Sending and receiving data as SPI slave (ATSAMD21) [SOLVED]

Hello,

I have problems with my SERCOM4 code. I got this from SercomSPISlave/Sercom4SPISlave.ino at master · lenvm/SercomSPISlave · GitHub.
Recently I was trying to establish the SPI communication between the ATSAMD21 chip (slave) and the Raspberry Pi (master). However, I am used to the ATMEGA328 chip (Uno). I have established the SPI communication before, but I've never done this on the ATSAMD21 chip. I came across a few examples, but these were meant for masters and the Pi cannot work as a slave. Do you know how to send and receive data from/to the ATSAMD21?

The pins that I'm using on my chip:

  • MISO | PA12 | D22 | SERCOM4/PAD[0]
  • MOSI | PB10 | D23 | SERCOM4/PAD[2]
  • SCK | PB11 | D24 | SERCOM4/PAD[3]
  • SS | PA13 | D38 | SERCOM4/PAD[1]

I've edited the library in order to use my pins:

 PORT->Group[PORTB].PINCFG[10].bit.PMUXEN = 0x1; //Enable Peripheral Multiplexing for SERCOM4 SPI PA12 Arduino PIN22
  PORT->Group[PORTB].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[13].bit.PMUXEN = 0x1; //Enable Peripheral Multiplexing for SERCOM4 SPI PB10 Arduino PIN23
  PORT->Group[PORTA].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[PORTA].PMUX[5].bit.PMUXO = 0x3; //SERCOM 4 is selected for peripheral use of this pad (0x3 selects peripheral function D: SERCOM-ALT)

The example code stayed the same, but I don't know how to send or receive any data like the Arduino Uno (ATMEGA328). I'm completely stuck.

Any help?

When you changed the pins did you check if the pins you chose were SPI compatible? SPI is typically a hardware module and can only connect a few pins via internal selection. If you are using software spi then it should be OK. also check to be sure the clock phase and polarities are correct.

Hello gilshultz,

Thank you for your reply. The pins I'm using are specifically for SPI, except the SS pin. So MOSI, MISO and SCK are in all probability SPI compatible. According to

(see code lines 133-145) in the SPI library, the pins are D22, D23 and D24 with SERCOM4. I don't use software SPI.

My bad, I was looking at the Arduino Zero's variant.h file, while I'm using Arduino M0 Pro. The pins are 18 (MISO), 21 (MOSI) and 20 (SCK), but it still doesn't work.
If I use the preinstalled SPI library, the Arduino Uno has variables like SPDR, SPCR, SPSR what the M0 Pro doesn't have.

What does the M0 Pro have?

Problem solved. See topic for solution: