The task I need to accomplish is as follows:
I have an analog/digital converter that sends out a 10-bit signal. This signal needs to be transferred to an Arduino Uno using the SPI protocol. Because the SPI protocol works with a 16 bit pattern I need to expand the incoming signal. The slave Arduino then needs to put out the transferred number in decimal.
I imitated the ADC with another Arduino Uno, setting it as master, but unfortunately at the time I only had one Arduino so I couldn't test my code. Furthermore, I don't really have a clue how to "expand" a 10-bit signal to a 16-bit one. Can someone please explain it to me and have a look at my code?
Code for the master Arduino:
#include <SPI.h>
#define SS 10
#define MOSI 11
void setup() {
pinMode(SS, OUTPUT);
pinMode(MOSI, OUTPUT);
SPI.beginTransaction(SPISettings(62500, LSBFIRST, SPI_MODE0));
}
void loop() {
byte x=0000001101;
byte y=0011111111;
digitalWrite(SS,LOW);
SPI.transfer(x,y);
digitalWrite(SS,HIGH);
delay(1000);
}
Code for the slave Arduino:
#include <SPI.h>
#define SS 10
#define MOSI 11
void setup() {
pinMode(SS, INPUT);
pinMode(MOSI, INPUT);
}
void loop() {
byte x=SPDR;
byte y=SPDR;
printf(x,DEC);
printf(y,DEC);
delay(1000);
}