Hardware Reference
In-Depth Information
#include "SPI.h"
int val = 0 ;
void setup () {
SPI.begin();
Serial.begin( 9600 );
val = 0 ;
}
void loop () {
int ret = SPI.transfer(val);
Serial.print("send=");
Serial.print(val);
Serial.print(", recv=");
Serial.println(ret);
delay( 1000 );
val++;
if (val>= 100 )
val = 0 ;
}
This code send a counter number using SPI.Transfer() and return reading value from SPI.
Because we connect MOSI to MISO, we get the same data from sending and receiving.
Save this code as SPIDemo.ino .
Compile and deploy this program to the board. Open Serial Monitor to see SPI communic-
ation.
Search WWH ::




Custom Search