Hi...!!
This code works fine with making SPDR = 0x00; at ISR but I have observed on Oscilloscope that sometime few data goes back to MISO, Slave is not able to clear SPDR perfectly, what could be the reason.
//Slave receiving data
#include <SPI.h>
void setup (void)
{
Serial.begin(115200);
// have to send on master in, *slave out*
pinMode(MISO, OUTPUT);
SPI.setBitOrder(MSBFIRST);
SPI.setDataMode (SPI_MODE2);
SPI.setClockDivider(SPI_CLOCK_DIV64) ;
// turn on SPI in slave mode
SPCR |= _BV(SPE);
// turn on interrupts
SPCR |= _BV(SPIE);
} // end of setup
// SPI interrupt routine
ISR (SPI_STC_vect)
{
byte c = SPDR; // what we received from the master
SPDR = 0x00; // what to return to the master
} // end of ISR SPI_STC_vect
void loop (void)
{
} // end of loop
Just keeping bandwidth of site in mind I am attaching one oscilloscope photo for your reference.
TEK0000.BMP (76.1 KB)