// Interrupt-driven SPI SLAVE example // Recieves bytes over SPI and stuffs them in // a sort-of-circular-buffer that is printed to Serial. // Uses a mix of Arduino and plain AVR code, // but does not use the Arduino SPI library. #include volatile uint8_t buffer[16]; volatile uint8_t bptr; void setup() { Serial.begin(115200); Serial.println("Hello from SLAVE") // A nice little debug/status pin, set as OUTPUT using the Arduino-way ;) pinMode(7, OUTPUT); // Make sure our buffer-pointer starts at the first buffer byte (pos 0) bptr = 0; // Set MISO as OUTPUT using the AVR-way ;) DDRB=(1< 15) bptr = 0; } uint8_t spi_read( ){ // Getting the transferred byte is as imple as reading the Data Register // each time a byte has completed transfer. This and the ISR, needs to be // quick, so that the next byte does not overwrite the current one. // Sending is done by setting the data register before reading ... SPDR = 0; uint8_t d = SPDR; // Let's add some fun "things happen because of transfers"... if ( d == 45 ) digitalWrite(7, ( !digitalRead(7) ) ); return d; }