I’m having a bit of difficulty reading the number that the master board is sending to the slave board through SPI.
for the master board, i’m using the transfer method to transfer the number, i.e. an integer = 7.
the goal for the slave board is simply to read that integer and print it on the serial monitor.
I see there’s a tutorial for sending the data but not a tutorial for reading the data. can someone help?
Hi Hui
What language are you programming the Feather with?
Check out this example of SPI transactions:
https://www.arduino.cc/en/Tutorial/SPITransaction
I hope that helps!
Hi Stephen,
thanks for the help there. still have a bit of difficulty since this is my first project with arduino. i have modified the code a bit to suit my needs but still not getting the right integer counter.
this is the code for my master module that sends the data, integer counter = 7.
#include <SPI.h>
void setup()
{
digitalWrite(SS, HIGH);//set SS high, no data
SPI.begin();//initialize the SPI for master mode
}
void loop()
{
int counter;
digitalWrite(SS,LOW); //enable Slave select
counter = 7;
SPI.transfer(counter);
Serial.print(counter);
digitalWrite(SS,HIGH);
delay(1000);
}
this is the code for the slave, that should be reading from the master:
#include <SPI.h>
// using two incompatible SPI devices, A and B. Incompatible means that they need different SPI_MODE
const int slaveAPin = 20;
//const int slaveBPin = 21;
// set up the speed, data order and data mode
SPISettings settingsA(9600, MSBFIRST, SPI_MODE1);
//SPISettings settingsB(16000000, LSBFIRST, SPI_MODE3);
void setup() {
// set the Slave Select Pins as outputs:
pinMode (slaveAPin, OUTPUT);
// pinMode (slaveBPin, OUTPUT);
// initialize SPI:
SPI.begin();
}
uint8_t counter;
void loop() {
// read three bytes from device A
SPI.beginTransaction(settingsA);
digitalWrite (slaveAPin, LOW);
// reading only, so data sent does not matter
counter = SPI.transfer(0);
Serial.println(counter);
digitalWrite (slaveAPin, HIGH);
SPI.endTransaction();
}
I’m not sure. Have you checked to make sure that you Baudrates are correct for your device?
Here is another example sketch that is a little closer to what you are trying to accomplish:
https://www.arduino.cc/en/Tutorial/BarometricPressureSensor
Try following this examples format and see if it works for you.