Setting SERCOM pins for SPI as the-opposite-of-a-master on SAMD21 not working

319 views Asked by At

I'm trying to make my SAMD21 chip a SPI Slave.

I have the following pins:

  • PB10 as MOSI
  • PB11 as SCK
  • PA10 as SS
  • PA12 as MISO

Most of these pins belong to SERCOM4

However, the pins are not working properly when I set them as followed:

 PORT->Group[PORTB].PINCFG[10].bit.PMUXEN = 0x1; //Enable Peripheral Multiplexing for SERCOM4 SPI PA12 Arduino PIN22
 PORT->Group[PORTA].PMUX[6].bit.PMUXE = 0x3; //SERCOM 4 is selected for peripheral use of this pad (0x3 selects peripheral function D: SERCOM-ALT)
 PORT->Group[PORTB].PINCFG[11].bit.PMUXEN = 0x1; //Enable Peripheral Multiplexing for SERCOM4 SPI PB09 Arduino PIN16
 PORT->Group[PORTB].PMUX[4].bit.PMUXO = 0x3; //SERCOM 4 is selected for peripheral use of this pad (0x3 selects peripheral function D: SERCOM-ALT)
 PORT->Group[PORTA].PINCFG[10].bit.PMUXEN = 0x1; //Enable Peripheral Multiplexing for SERCOM4 SPI PB10 Arduino PIN23
 PORT->Group[PORTB].PMUX[5].bit.PMUXE = 0x3; //SERCOM 4 is selected for peripheral use of this pad (0x3 selects peripheral function D: SERCOM-ALT)
 PORT->Group[PORTA].PINCFG[12].bit.PMUXEN = 0x1; //Enable Peripheral Multiplexing for SERCOM4 SPI PB11 Arduino PIN24
 PORT->Group[PORTB].PMUX[5].bit.PMUXO = 0x3; //SERCOM 4 is selected for peripheral use of this pad (0x3 selects peripheral function D: SERCOM-ALT)

I use the library of https://github.com/lenvm/SercomSPISlave

I program the chip using the arduino IDE and SAMD: M0 or somethings M0 Pro (navtive) board layout.

The pins according to the documentation:

  • | 1 | 1 <- TX | PA10 | | EIC/EXTINT[10] ADC/AIN[18] PTC/X[2] *SERCOM0/PAD[2] TCC0/WO[2] TCC1/WO[0]
  • | 22 | 1 | PA12 | MISO | EIC/EXTINT[12] SERCOM2/PAD[0] *SERCOM4/PAD[0] TCC2/WO[0] TCC0/WO[6]
  • | 23 | 4 | PB10 | MOSI | EIC/EXTINT[10] *SERCOM4/PAD[2] TC5/WO[0] TCC0/WO[4]
  • | 24 | 3 | PB11 | SCK | EIC/EXTINT[11] *SERCOM4/PAD[3] TC5/WO[1] TCC0/WO[5]
1

There are 1 answers

0
lenvm On

Thanks for your question. I've just come across your post. I'm the author of the repository you were using. I'll reply here for future reference for other readers.

Your code contains some issues, e.g.

  • using PORTA and PORTB to define PB10. For PB, PORTB shall be used. Equally, for PA, PORTA shall be used.
  • using the incorrect PMUX. If you want use PB10, you shall use PMUX[5] instead of PMUX[6], as 10/2 = 5. For PB11 you would also use PMUX[5], as 11/2 = 5.5. The PMUXE and PMUXO define wether the even or odd pin will be selected.

To make it easier to use different pins, I've released version 0.2.0 of the library. This will allow you to use any SERCOM (SERCOM0 to SERCOM5), and select any pin available to be used for that SERCOM.

Please see the readme and the code comments in SercomSPISlave.h and SercomSPISlave.cpp on the repository https://github.com/lenvm/SercomSPISlave for further reference.