Adafruit Feather M4 Express (ATSAMD51J19A) - Extra SPI port

Hello,

I'm trying to create a second SPI port to use with a Ethernet controller (W5500).
I'm following the tutorial on the Adafruit website:

For the multiplexing and pins selection I used the following diagram:
Feather M4 Pinout

It looks that SERCOM4 with A2(4:0), A3 (4:1) and D4(4:2) is available for use.
That will give the following test code:

#include <SPI.h>
#include "wiring_private.h" // pinPeripheral() function
 

//              sercom    miso sck  mosi  tx               rx 
SPIClass mySPI (&sercom4, 4,   A3,  A2,   SPI_PAD_0_SCK_1, SERCOM_RX_PAD_2); 

void setup() {
  Serial.begin(9600);
 
  // do this first, for Reasons
  mySPI.begin();
 
  // Assign pins 4, A2, A3 to SERCOM functionality
  pinPeripheral(4, PIO_SERCOM);
  pinPeripheral(A3, PIO_SERCOM);
  pinPeripheral(A2, PIO_SERCOM);
}
 
uint8_t i=0;
void loop() {
  Serial.println(i);
  mySPI.beginTransaction(SPISettings(8000000, MSBFIRST, SPI_MODE0));
  mySPI.transfer(i++);
  mySPI.endTransaction();
}

But nothing happens on all the pins if you measure it with a scope (10Mhz max). They all stay near GND level.

Is there something I'm doing wrong? I tried the same on SERCOM3 with pins 5,6 and 9. But also no result.

Thank you

Hi qniens,

The pinPeripheral() functions' arguments needs to be changed to: PIO_SERCOM_ALT:

// Assign pins 4, A2, A3 to SERCOM functionality
pinPeripheral(4, PIO_SERCOM_ALT);
pinPeripheral(A3, PIO_SERCOM_ALT);
pinPeripheral(A2, PIO_SERCOM_ALT);

This is because the port pins PB08 (A2), PB09 (A3) and PA14 (D4) use SERCOM4 on the second (or alternate) SERCOM multiplexer switch, (column "D" in the SAMD51 datasheet's port mapping table).

Dear MartinL,

Thank you for your comment. That did the trick.