Hi folks.
I need to decode a stream of data over a SPI bus. I need my Arduino to act as a SPI slave.
Fortunately i found Nick Gammon's tut here: Gammon Forum : Electronics : Microprocessors : SPI - Serial Peripheral Interface - for Arduino
I tested the example and it works just fine. So long so good.
I have a device which transmits 14 hex values over SPI which i need to put into some byte values that my program then decides what to do with.
14 bytes are transmitted in a row, then comes a delay of about 21 ms, then the data repeats with any changes from the transmitter circuit.
As i do not have the SS line to trigger from, what is the smartest way to do this - capture one byte at a time, and when i've counted 14 received bytes, it's back to start, or maybe starting a timer and using that to figure out what is start and stop...
I have DATA and CLOCK available. The Arduino won't me doing much else that receiving this string of data and toggling some outputs according to the bytes sent to it.
This snippet of code replicated accurately what my circuit is sending out:
// Written by Nick Gammon
// February 2011
#include <SPI.h>
void setup (void)
{
digitalWrite(SS, HIGH); // ensure SS stays high for now
// Put SCK, MOSI, SS pins into output mode
// also put SCK, MOSI into LOW state, and SS into HIGH state.
// Then put SPI hardware into Master mode and turn SPI on
SPI.begin ();
// Slow down the master a bit
SPI.setClockDivider(SPI_CLOCK_DIV8);
} // end of setup
void loop (void)
{
char c;
// enable Slave Select
digitalWrite(SS, LOW); // SS is pin 10
SPI.transfer(0x00);
SPI.transfer(0xB7);
SPI.transfer(0x05);
SPI.transfer(0xFC);
SPI.transfer(0x09);
SPI.transfer(0xFC);
SPI.transfer(0x0D);
SPI.transfer(0xFE);
SPI.transfer(0x10);
SPI.transfer(0xA4);
SPI.transfer(0x17);
SPI.transfer(0x53);
SPI.transfer(0x00);
SPI.transfer(0x39);
// disable Slave Select
digitalWrite(SS, HIGH);
delay (21); // 1 seconds delay
} // end of loop
I would like to capture the data and then in the 21 ms delay toggle ports depending on what the bytes were.
for example, if the second byte is 0xAD instead of 0xB7, turn output 0 high.
Any advice for a n00b how to handle this in a nice manner ?
Regards, Per.