#include <SPI.h>
char buff [50];
volatile byte indx;
volatile boolean process_it;
int i = 0;
void setup (void) {
Serial.begin (115200);
pinMode(MISO, OUTPUT); // have to send on master in so it set as output
SPCR |= _BV(SPE); // turn on SPI in slave mode
indx = 0; // buffer empty
process_it = false;
Serial.println("The Program is Executing");
Serial.println(true);
SPI.attachInterrupt(); // turn on interrupt _BV(SPE)
}
ISR (SPI_STC_vect) // SPI interrupt routine SPI_STC_vect transfer complete handler.
{
byte c = SPDR; // read byte from SPI Data Register
if (indx < sizeof buff) {
buff [indx++] = c; // save data in the next index in the array buff
if (c == '\n') //check for the end of the word
Serial.println("Inside \r If condition");
process_it = true;
}
}
void loop (void) {
//Serial.println(process);
if (process_it == true) {
process_it = false; //reset the process
Serial.println("Bow");
Serial.println (buff); //print the array on serial monitor
indx= 0; //reset button to zero
}
}
I have attached the screenshot of the output. Actually I am send Hello World throught SPI. The if loop should get executed only when process is true. and the correct output should be HELLO WORLD.