Author Topic: Additional SPI config  (Read 959 times)

Jim

  • NewMember
  • *
  • Posts: 16
Additional SPI config
« on: February 01, 2021, 04:19:28 PM »
Hi,

can somebody help me to add a second SPI to the Meteino M0 core? I would like to edit the variant.h/cpp to add SPI1
I would need sercom0 as I figured out as I would like to use PA06, PA07 as additional hardware SPI pins.

I found this instruction but they're writing the new definition to the sketch instead of the variant-files
https://learn.adafruit.com/using-atsamd21-sercom-to-add-more-spi-i2c-serial-ports/creating-a-new-spi

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 6866
  • Country: us
    • LowPowerLab
Re: Additional SPI config
« Reply #1 on: February 02, 2021, 09:36:50 AM »
Is there any issue with including this in your sketch rather than do it in the board variant? I believe that would be more portable, but perhaps slightly less convenient. This is something that could achieve that:

Code: [Select]
#if defined (MOTEINO_M0)
  #include "wiring_private.h" // pinPeripheral() function
  SPIClass mySPI(&sercom1, 12, 13, 11, SPI_PAD_0_SCK_1, SERCOM_RX_PAD_3);
  SPIClass& mySPI=SPI;
#endif

//then in setup():
  mySPI.begin();
  pinPeripheral(11, PIO_SERCOM);pinPeripheral(12, PIO_SERCOM);pinPeripheral(13, PIO_SERCOM);

Anyway the pattern is the same as seen in the variants.h/cpp files. You need 3 free pins not 2. And it cannot be just any pins, they have to be sercom pins tied to the peripheral they are defined on.

Here are the pins for the main SPI, notice they are SERCOM_ALT, this depends on which peripheral is defined for sercom in the pin mux section of the datasheet (i/o multiplexing and considerations section, or see this samd21-pmux google sheet).
Code: [Select]
  // 22..24 - SPI pins (ICSP:MISO,SCK,MOSI)
  // ----------------------
  { PORTA, 12, PIO_SERCOM_ALT, PIN_ATTR_DIGITAL, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_12 }, // MISO: SERCOM4/PAD[0]
  { PORTB, 10, PIO_SERCOM_ALT, PIN_ATTR_DIGITAL, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_10 }, // MOSI: SERCOM4/PAD[2]
  { PORTB, 11, PIO_SERCOM_ALT, PIN_ATTR_DIGITAL, No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_11 }, // SCK: SERCOM4/PAD[3]

BTW I will have to release a new version of the SAMD package, that will include the ability to use the builtin FLASHMEM as a disk drive through the MoteinoM0's USB.
« Last Edit: February 02, 2021, 09:41:46 AM by Felix »