Go Down

Topic: SPI across two Arduino DUE's (Read 4623 times) previous topic - next topic


I have been searching for examples of how to set the Arduino DUE as a slave in SPI communication with no luck. I think this should be an easy task, but seem to be missing something important for everything to work. Here is what I am try to accomplish and it should be easy for this community.

Master Arduino DUE send a character 'E' to the slave and the slave just receive and prints 'E' over and over again.

The second task is to have the Master Arduino DUE send 2 characters 'E' and 'M' and the slave prints both out and respond with 1 character 'Y'

If I can get these two task and understand SPI, I will be able to implement similar functionality to a project I am working on.
Here are some code I testes and incorrect results.

Code: [Select]

#include <SPI.h>

#define SS 52

void setup()

void loop()
   SPI.transfer(SS,(byte)'E', SPI_CONTINUE);
   //SPI.transfer(SS,(byte)'M', SPI_CONTINUE);

Code: [Select]

#include <SPI.h>

#define SS 52

void setup()

void loop()
   char c = SPI.transfer(SS,0x45,SPI_CONTINUE);

All I get on the output for every println is 255 as a character. I commented out the second transfer because I was not sure how SPI do the transfer.


Hi, the SPI library only supports master mode:
[...]Since this library supports only master mode[...]
(quote from the library page)
So the Slave due is acting as a master too. Unfortunately I don't know how the spi is implemented in the due, so I can't help more.


Bump. Can anyone help with this topic?


any luck on slave mode ?

i'm looking to connect a DUE (slave)to a RaspberryPi(master) .. 
and spi has only been implemented on the Pi as master so i figured the Due would be a easier modification ....
sigh .. time to dig into some data sheets & libs ...


I'm trying to operate a Due as slave too. But with no success.
I'm wondering if anyone has made any progress on that matter.
Is it possible to have a Mega as spi Master and an adafruit data logging shield as slave1 and a Due as slave2 ? I want the due acting as a sensor node.

I would  appreciate any help!


Sep 27, 2013, 04:57 pm Last Edit: Sep 27, 2013, 08:56 pm by Stephan_Duino Reason: 1
I also need to make the “Arduino due” run in SPI slave mode as opposed to SPI master mode, (The defaults is SPI Master mode). To set the other Arduinos (Uno / Mega) to run in SPI Slave mode you do the following:-
// turn on SPI in slave mode
Alas SPCR is not available on the “Arduino Due” which means I do not know how to set the DUE to run in SPI slave mode.
This is a popular need so any help will be very much appreciated.

Additional information
IDE used: Arduino V1.5.4 (Windows)
Board used: Arduino Due (Programming port)
Source code: Full version of the Arduino code that I am trying to run can be found on this link:-
Error received: "error: 'SPCR' was not declared in this scope"


Sep 28, 2013, 10:30 am Last Edit: Sep 28, 2013, 03:52 pm by dlloyd Reason: 1
This is the slave setup that I use...

Code: [Select]

//SPI setup
SPI.setDataMode(10, SPI_MODE0);
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


Oct 11, 2013, 12:24 pm Last Edit: Oct 11, 2013, 03:52 pm by Stephan_Duino Reason: 1
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 here
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.
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...
//SPI setup
SPI.setDataMode(10, SPI_MODE0);
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.


Hi everybody

As the topic is a few months old I am hoping somebody managed it to put the Arduino due in Slave mode. If so I would appreciate an example code.
In detail I would like to communicate with a RaspberryPi over SPI.



It's a pity that the Arduino DUE will not suppport SPI  as slave mode.

From what I read it can be done, but there is no example code. I have read and understood the clues above, but I dont know how to do it.

I think the key part is:

"I read from REG_SPI0_RDR when bit RDRF is 1, I write to REG_SPI0_TDR when bit TXEMPTY is 1."

If anyone comes up with working source code, it will be a great contribution to arduino community if it is published.

Best Regards,


Bump again.  Any one of the previous posters manage to get a DUE working in slave mode?


From the datasheet:

The Serial Peripheral Interface (SPI) circuit is a synchronous serial data link that provides communication
with external devices in Master or Slave Mode.

Rather than complain about this, have a go at implementing it?  Most stuff developed
for Arduino is done gratis by enthusiasts, and demand driven...

Start at datasheet section 33.7.1
[ I won't respond to messages, use the forum please ]


Here is a simple DUE spislave.ino sketch, proof of concept,
I've tested it with a maple (3.3v) master at various data rates, sending various number of bytes between SS LOW/HIGH.
sketch utilizes SPI library (SPI.begin(SS)) to get pins and such set up, then resets the SPI and enables it in slave mode.

Go Up