[code][quote author=Nick Gammon link=topic=120454.msg999023#msg999023 date=1353098493]
[quote author=ranjeetray link=topic=120454.msg998331#msg998331 date=1353063009]
Can we do like this, after receiving data can we check(if condition) data and then send back data to master like this.
[/quote]
I really don't know what you are trying to do. You are doing an SPI.transfer in the middle of the ISR?
You send back data to the master [b]by assigning to SPDR in the interrupt service routine[/b]. No other way. What are you thinking?
[/quote]
Hi...!!
This way(SPDR = dat[0]) also it is not able to send back data to Master, and I am not able to give delay properly and synchronize with master. Slave is not getting chance to send back data, I think so.
[code]
#include "pins_arduino.h"
#include <SPI.h>
#define SS 10
int dat[24] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14};
byte c;
void ss_falling()
{
c = 0;
}
void setup (void)
{
// 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);
// disable timer interrupts
TIMSK0 = 0;
// interrupt for SS falling edge
attachInterrupt (0, ss_falling, FALLING);
// disable timer interrupts
TIMSK0 = 0;
} // end of setup
// SPI interrupt routine
ISR (SPI_STC_vect)
{
c = SPDR;
if(c == 0x04)
{
SPDR = dat[0];
}
else if(c == 0x06)
{
SPDR = dat[1];
}
else
SPDR = 0x00; // what to return to the master
} // end of interrupt service routine (ISR) SPI_STC_vect
void loop (void)
{
} // end of loop
[/code][/code]