Can anyone help? We need an “Arduino Due SPI Slave mode” example? I have been trying to crack this problem with the intent of publishing the example here and using it myself but no luck so far. What I can share are all the good clues and good help that I have received / found, but alas no working example for the Due yet. I guess I need an enlightened soul to get us to the point of a working “Arduino DUE SPI slave mode” example. Please see below all the clues and help that I have received or found thus far:-
A most excellent source for SPI UNO-UNO / MEGA-MEGA is available herehttp://gammon.com.au/spi
Many thanks to Nick Gammon for such a detailed write up.
Also a nice example of Arduino UNO/MEGA SPI slave mode to Raspberry PI as master.http://mitchtech.net/raspberry-pi-arduino-spi/
Many thanks to Michael Mitchell for his detailed write up.
The UNO/MEGA examples above give us a good idea of how to implement the Arduino Due SPI slave solution but you cannot use these examples “as-is” on the Due. The Due uses different registers.
The following is Help from dlloyd (Many thanks)
This is the slave setup that I use...
REG_SPI0_CR |= 0x1; // SPI enable (write only)
REG_SPI0_WPMR = 0x53504900; // Write Protection disable
REG_SPI0_MR = 0x2; // DLYBCS=0, PCS=0, PS=1, MSTR=0
REG_SPI0_CSR = 0xA; // DLYBCT=0, DLYBS=0, SCBR=0, 8 bit transfer, Clock Phase = 1 for SPI mode 0
The most important reference material I used is page 695 of the SAM3X datasheet http://www.atmel.com/Images/doc11057.pdf
In slave mode, the SCLK frequency is set by the external SPI master, and can be anything up to 42 MHz. It’s good to start at a much lower frequency and use a scope on the SPI signals to troubleshoot. On the Due, your just reading and writing to a shift register that can be set anywhere from 8 to 16 bits in length. Just before each read or write, check the status register REG_SPI0_SR. and it will give you all the status flags shown on page 695.
I read from REG_SPI0_RDR when bit RDRF is 1, I write to REG_SPI0_TDR when bit TXEMPTY is 1.
Once again, many thanks to dlloyd for assistance provided.
OK by now I should have enough clues to get this all working on the Due but still no luck getting an SPI slave mode example working on the Due.
If anyone can help produce a working “Arduino Due SPI Slave mode” example it will be very much appreciated.