Skip to content

Instantly share code, notes, and snippets.

@ssnover
Created November 29, 2017 02:09
Show Gist options
  • Save ssnover/1a9982095c43bf7f4a52e6a380ae120c to your computer and use it in GitHub Desktop.
Save ssnover/1a9982095c43bf7f4a52e6a380ae120c to your computer and use it in GitHub Desktop.
Arduino SPI-to-Serial Slave
/*
* A short Arduino sketch which waits for a SPI character to be sent from a
* master device and then prints the received character over Serial.
*/
#include "Arduino.h"
#include <avr/io.h>
void setup()
{
Serial.begin(115200);
SPCR |= (1 << SPE); // enable the SPI peripheral
}
void loop()
{
if (SPSR & (1 << SPIF))
{
// if a SPI message has been received, print it
Serial.println(SPDR, HEX);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment