Hello everyone!
I'm currently working on a project that involves using an Arduino Nano 33 BLE, but I'm facing some challenges with SPI communication. I've tried the code below to establish a simple SPI communication between an Arduino Nano (master) and Arduino Nano 33 BLE (slave), but it does not work.
Initially, I suspected that the issue might be due to different SPI frequencies. However, even after specifying the same frequency, I'm still encountering problems. Another consideration is that the Arduino Nano 33 BLE runs on a different board and utilizes mbed OS. Could this be affecting the SPI library?
I would appreciate any guidance or assistance you could provide or have suggestions on how to troubleshoot this? Thank you in advance for your help!
Master:
#include <SPI.h>
const int SS_PIN = 10;
void setup() {
Serial.begin(115200);
SPI.begin();
SPI.beginTransaction(SPISettings(8000000, MSBFIRST, SPI_MODE0));
pinMode(SS_PIN, OUTPUT);
digitalWrite(SS_PIN, HIGH);
}
void loop() {
// Select the slave
digitalWrite(SS_PIN, LOW);
// Send address byte
char add = 'h'; //
SPI.transfer(add);
// Send data
char data = 'A';
SPI.transfer(data);
Serial.print("Sent: ");
Serial.println(data);
Serial.println(add);
// Deselect the slave
digitalWrite(SS_PIN, HIGH);
delay(1000);
}
Slave code:
#include <SPI.h>
const int SS_PIN = 10;
void setup() {
Serial.begin(115200);
pinMode(SS_PIN, INPUT);
SPI.beginTransaction(SPISettings(8000000, MSBFIRST, SPI_MODE0));
}
void loop() {
if(SS_PIN == LOW){
// Receive address byte
char receivedAddress = SPI.transfer(' ');
Serial.print("Received Address: ");
Serial.println(receivedAddress);
// Receive data
char receivedData = SPI.transfer(' ');
Serial.print("Received Data: ");
Serial.println(receivedData);
digitalWrite(SS_PIN, HIGH);
delay(1000);
}
}