Hello,
I have a Seeed Studio XIAO nrf52840 and an Arduino Nano. I have been trying to establish communication between both of them using SPI protocol. I have been facing certain issues while doing so. Please find the details.
Master: Arduino Nano
Slave: Seeed Studio XIAO nrf52840
Platform Used: Arduino IDE
Master Code:
#include <SPI.h>
#define SS 2
byte Send_Data;
byte Receive_Data;
void setup()
{
pinMode(SS, OUTPUT);
digitalWrite(SS, HIGH);
Serial.begin(115200);
SPI.begin();
SPI.setClockDivider(SPI_CLOCK_DIV8);
SPI.setDataMode(SPI_MODE0);
SPI.setBitOrder(MSBFIRST);
}
void loop()
{
digitalWrite(SS, LOW);
Send_Data = 55;
SPI.transfer(Send_Data);
Receive_Data = SPI.transfer(Send_Data);
digitalWrite(SS, HIGH);
Serial.print("Sent: “);
Serial.println(Send_Data);
Serial.print(”, Received: ");
Serial.println(Receive_Data);
delay(1000);
}
Slave Code:
#include <SPI.h>
#include <Adafruit_TinyUSB.h>
#define Slave_Select 1
int data_receive = 0;
void setup()
{
pinMode(Slave_Select, INPUT);
pinMode(SCK, INPUT);
Serial.begin(115200);
SPI.begin();
SPI.setClockDivider(SPI_CLOCK_DIV8);
SPI.setDataMode(SPI_MODE0);
SPI.setBitOrder(MSBFIRST);
}
void loop()
{
if(digitalRead(Slave_Select)==LOW)
{
data_receive = SPI.transfer(0);
while(digitalRead(Slave_Select) == LOW);
Serial.print("Received: ");
Serial.println(data_receive);
data_receive = 0;
}
}
The slave is not receiving 55, instead it is giving random outputs such as, FF, 0, FE etc. Can anyone kindly help me sort this out?
PS: All the hardware connections are in the right place.