Permalink
Browse files

a sample Arduino sketch

1 parent eea100f commit efe10972557df6411aca83c4f78d26fe10109b63 lthiery committed Jan 5, 2013
Showing with 43 additions and 0 deletions.
  1. +43 −0 SPIGames/SPIGames.ino
View
@@ -0,0 +1,43 @@
+
+// inslude the SPI library:
+#include <SPI.h>
+
+char buf[100];
+volatile byte pos;
+volatile boolean process_it;
+
+void setup(){
+ Serial.begin(57600);
+ //enable slave mode
+ pinMode(MISO,OUTPUT);
+ SPCR |= _BV(SPE);
+
+ //initialize buffer
+ pos = 0;
+
+ SPI.attachInterrupt();
+ Serial.println("SPI Testing");
+}
+
+ISR(SPI_STC_vect)
+{
+ byte c = SPDR;
+ if(pos<sizeof buf)
+ {
+ buf[pos++]=c;
+ }
+ //echo incoming byte back out
+ SPDR = c;
+}
+
+void loop(){
+ SPDR=0;
+ if(pos==8){
+ for(int i=0;i<8;i++){
+ Serial.print(buf[i],HEX);
+ Serial.print(" ");
+ }
+ Serial.println();
+ pos=0;
+ }
+}

0 comments on commit efe1097

Please sign in to comment.