Hello!
I have spent a lot of time reading many posts, but I have not found an answer to my question...
I'd like to transfer data between two arduino nano 33 iot using SPI; many topics talk about this, but not specifically for these boards ![]()
I used default MOSI, MISO and SCK pins (11, 12, 13) as in pinout for both sides.
SS pin is 8 master side, 9 slave side (to be able to use attachInterrupt).
Here are basic tests I've been running:
Master:
#include<SPI.h>
#define SS_PIN 8
void setup() {
Serial.begin(115200);
while (!Serial) {
delay(10);
}
Serial.println("OK master");
SPI.begin();
pinMode(SS_PIN, OUTPUT);
pinMode(MOSI, OUTPUT);
pinMode(MISO, INPUT);
digitalWrite(SS_PIN, HIGH);
}
void loop() {
String test = "";
while(test == ""){
test = Serial.readString();
}
if(test == "test"){
SPI.beginTransaction(SPISettings(200000, MSBFIRST, SPI_MODE0));
digitalWrite(SS_PIN, LOW);
char c;
for (const char * p = "Hello, world\r"; c =*p ; p++) {
byte toto = SPI.transfer(c);
}
digitalWrite(SS_PIN, HIGH);
SPI.endTransaction();
}
}
Slave:
#include <SPI.h>
#include <Arduino.h>
volatile byte indx;
volatile boolean process;
#define SS_PIN 9
void interruptCb() {
Serial.println("receiving");
process = true;
}
void setup() {
Serial.begin(115200);
SPI.begin();
pinMode(MOSI, INPUT);
pinMode(MISO, OUTPUT);
pinMode(SS_PIN, INPUT);
attachInterrupt(digitalPinToInterrupt(SS_PIN), interruptCb, FALLING);
}
void loop() {
indx = 0;
if (process == true) {
while(indx < 50) { //In case where data would be delayed. Probably should not exist
byte test = SPI.transfer(0);
Serial.println(test);
indx++;
}
process = false;
}
}
I know that slave implementation is not usual, as I should use SPDR to catch current value and put this one in a buffer, but arduino nano 33 iot does not have this value as in this post. You can find linked article in web archive , but it implies to play with SERCOM directly.
Usually I find answers on this forum, and after some tries I find a solution, but I've been stuck on this one for four days (I'm on holidays so it's really four days
).
I hope someone will have the knowledge to help me!
Thank you!