I am trying to understand how to send SPI data back to the master. I used the SPI examples from Circuit Digest. I am connecting 2 Arduino's together. The Master is sending SPI.tranfer16(). In the scope image below the Master sent 0x3E00. MOSI-Yellow MISO-Green
What I would like to do is detect a message from byte 1 and then send responses in bytes 3, 4, 5, 6,... depending on the value in byte 1.
When I read the first non-zero value it already responds with 0xFF.
The second byte always echos whatever is in the first?
And the rest are always 0?
My understanding was the SPDR buffer would send when the master is clocking data during the ISR. Is the ISR triggered by the CS so it only enters 1 time?
Thanks for reading
//SPI SLAVE (ARDUINO)
//SPI COMMUNICATION BETWEEN TWO ARDUINO
//CIRCUIT DIGEST
//Pramoth.T
#include<SPI.h>
volatile boolean received;
volatile byte Slavereceived;
volatile byte Slavetx;
void setup()
{
Serial.begin(115200);
pinMode(MISO,OUTPUT); //Sets MISO as OUTPUT (Have to Send data to Master IN
SPCR |= _BV(SPE); //Turn on SPI in Slave Mode
received = false;
SPI.attachInterrupt(); //Interuupt ON is set for SPI commnucation
}
ISR (SPI_STC_vect) //Inerrrput routine function
{
Slavereceived = SPDR; // Value received from master if store in variable slavereceived
received = true; //Sets received as True
}
void loop()
{ if(received)
{
if (Slavereceived != 0)
{
Serial.println("not zero");
Slavetx = (0xAA);
}
else
{
Slavetx = (0xFF);
}
SPDR = Slavetx;
}
}