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.
/**********************************************
MASTER
**********************************************/
#include <SPI.h>
#define SS 52
void setup()
{
SPI.begin();
pinMode(SS,OUTPUT);
digitalWrite(SS,HIGH);
}
void loop()
{
SPI.transfer(SS,(byte)'E', SPI_CONTINUE);
//SPI.transfer(SS,(byte)'M', SPI_CONTINUE);
delay(10);
}
/**********************************************
SLAVE
**********************************************/
#include <SPI.h>
#define SS 52
void setup()
{
SPI.begin();
pinMode(SS,INPUT);
Serial.begin(115200);
}
void loop()
{
char c = SPI.transfer(SS,0x45,SPI_CONTINUE);
Serial.println(c);
delay(1000);
}
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.