Hi there!
Due to some component placements, I need to use two SPI buses on my Arduino Zero.
I checked out this guide to get a sense of Muxing the serial ports to be used for SPI.
I then changed SPI_INTERFACES_COUNT
(variant.h, line 133) to 2
#define SPI_INTERFACES_COUNT 2
Now, SPI.h will be defining my second SPI bus as SPI1:
extern SPIClass SPI1;
I am using the following pins:
/*
PA16 - MOSI - SER1 [0] - ARDUINO PIN 11
PA17 - SCK - SER1 [1] - ARDUINO PIN 13
PA18 - MISO - SER1 [2] - ARDUINO PIN 12
*/
I am changing the external SPIClass definition in SPI.cpp to:
#if SPI_INTERFACES_COUNT > 1
SPIClass SPI1(&sercom1, 12, 13, 11, SPI_PAD_0_SCK_1, SERCOM_RX_PAD_2)
#endif
So far so good...at this point, the code compiles and runs
I then open this second SPI port by calling
char buf[3] = {0};
SPI1.begin();
pinPeripheral(11, PIO_SERCOM);
pinPeripheral(12, PIO_SERCOM);
pinPeripheral(13, PIO_SERCOM);
pinMode(CSpin, OUTPUT);
digitalWrite(CSpin, HIGH); //CS is active low
SPI1.beginTransaction(SPISettings(20000000, MSBFIRST, SPI_MODE0);
digitalWrite(CSpin, LOW); //assert CS
SPI1.transfer(0x6E); //send a command to the unit
buf[0] = SPI1.transfer(0); //get a response
buf[1] = SPI1.transfer(0); //get a response
buf[2] = SPI1.transfer(0); //get a response
digitalWrite(CSpin, HIGH); //release CS
SPI1.endTransaction();
And I get nothing. Nothing goes into buf the way it does on the default SPI port, and it doesn't seem like any signal is being sent across. I checked the pins with my logic analyzer and I also see no change - the only thing that moves is CS.
Is there still something in the register that I am missing? CTRLA and CTRLB seem to be enabled, I don't see any kind of buffer overflow or register error - which would be surprising since I'm simply initializing the device.
Does anyone have any experience with this or any suggestions as to how I can properly configure these pins?
Thank you!