0

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]
Rick Vink
  • 321
  • 1
  • 3
  • 11
  • Mixing PORTA and PORTB in configuration looks wrong to me, but maybe it's just odd ordering? Could you clarify which lines set up which pins? "not working properly" will also need some more detail. – domen Oct 02 '20 at 15:06
  • @domen Thank you for you response. The Sercom4 is indeed a bit mixy matchy it seems (see the documentation I added). I only added a slave select from somewhere else but I think that this won't be an issue. Not working properly means: I don't receive the messages from the master and the slave select interrupt is not triggered. – Rick Vink Oct 05 '20 at 08:37
  • Are you *sure* `PORT->Group[PORTB].PINCFG[10].bit.PMUXEN` stands for `PA12` and so on for the rest of pins. Without going into datasheets, it looks very wrong and should at least be commented why it looks so wrong if it's indeed correct. On the other hand, PORTB/10 matches the PB10 from question, same for other pins, so maybe it's just comments that are out of sync. Then the next weird bit is the PMUXE/O which again appear to be mixed up. – domen Oct 05 '20 at 09:29

1 Answers1

1

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.

lenvm
  • 11
  • 2