IWEUA.COM

Arduino SPI Modes
I have been using the Arduino SPI library with an Arduino Mega 2560 recently, it took me a little while to work out the SPI
modes, which are straightforward, but I though I would post some traces to backup the reference links which I will include. For
me looking at the scope trace, a picture, was a thousand words.

The
SPI wiki page gives an excellent definition of the format.

The code :

#include <SPI.h>
#define SPISpeed 100000

void setup()
{ Serial.begin(9600);  
SPI.begin();
}

void loop()
{  SPIWord();
delay(10);
}


void SPIWord()
{  SPI.beginTransaction (SPISettings ( SPISpeed, MSBFIRST,
SPI_MODE0 ) );    // MODE0 / MODE1 / MODE2 / MODE3
SPI.transfer( B01000010 );
SPI.endTransaction();
}
Mode0
Mode1
Mode2
Mode3
SPISpeed = 100000
SPISpeed = 1000000