ranjeetray:
Hi...!!I am reading Gammon Forum : Electronics : Microprocessors : SPI - Serial Peripheral Interface - for Arduino again and again and trying to grasp SPI, but not getting expected results.
Can we write the codes like this, are these correct codes for mater and slave
...
Slave receiving data from master then sending the data back to master, is it right....
// SPI interrupt routine
ISR (SPI_STC_vect)
{
c = SPDR;
if(c == 0x04)
{
digitalWrite(SS, LOW);
SPI.transfer(dat[0]);
SPI.transfer(dat[1]);
digitalWrite(SS, HIGH);
digitalWrite(SS, LOW);
SPI.transfer(dat[2]);
SPI.transfer(dat[3]);
digitalWrite(SS, HIGH);
digitalWrite(SS, LOW);
SPI.transfer(dat[4]);
SPI.transfer(dat[5]);
digitalWrite(SS, HIGH);
}
else if(c == 0x06)
{
digitalWrite(SS, LOW);
SPI.transfer(dat[6]);
SPI.transfer(dat[7]);
digitalWrite(SS, HIGH);
digitalWrite(SS, LOW);
SPI.transfer(dat[8]);
SPI.transfer(dat[9]);
digitalWrite(SS, HIGH);
digitalWrite(SS, LOW);
SPI.transfer(dat[10]);
SPI.transfer(dat[11]);
digitalWrite(SS, HIGH);
}
else
SPDR = 0x00; // what to return to the master
} // end of interrupt service routine (ISR) SPI_STC_vect
...
Look, ranjeetray, you are just ignoring everything I am saying. I said this:
You do not use SPI.transfer in the ISR. Do you have trouble understanding that?
You are ignoring me, you are just making stuff up, and then taking screen shots of the scope output. It won't work.
Graynomad has offered to write an example but that won't help if you don't make an attempt to understand things. Don't just copy and paste and hope for the best.