I have two Esp32S3-WROOM-1 DevKits and I'm trying to communicate both with SPI, one slave and other master. I'm using Arduino IDE to do it.
I am connecting the wires like this:
| Master | Slave |
|---|---|
| PIN9/GPIO10 - CS | PIN9/GPIO10 - CS |
| PIN10/GPIO11 - MOSI | PIN10/GPIO11 - MOSI |
| PIN11/GPIO12 - SCK | PIN11/GPIO12 - SCK |
| PIN12/GPIO13 - MISO | PIN12/GPIO13 - MISO |
The codes I'm using:
#include <SPI.h>
volatile bool receivedFlag = false;
volatile byte receivedData = 0;
static const int spiClk = 1000000;
void IRAM_ATTR ssInterrupt() {
if (digitalRead(SS) == LOW) {
SPI.beginTransaction(SPISettings(spiClk, MSBFIRST, SPI_MODE0));
receivedData = SPI.transfer(0x00);
receivedFlag = true;
SPI.endTransaction();
}
}
void setup() {
Serial.begin(115200);
pinMode(SS, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(SS), ssInterrupt, FALLING);
SPI.begin(SCK, MISO, MOSI, SS); // Inicia o SPI como slave
}
void loop() {
if (receivedFlag) {
Serial.print("Received: ");
Serial.println(receivedData);
receivedFlag = false;
}
}
#include <SPI.h>
#define SS_PIN 10
static const int spiClk = 1000000;
void setup() {
Serial.begin(115200);
pinMode(SS_PIN, OUTPUT);
SPI.begin(SCK, MISO, MOSI, SS);
}
void loop() {
SPI.beginTransaction(SPISettings(spiClk, MSBFIRST, SPI_MODE0));
digitalWrite(SS_PIN, LOW);
SPI.transfer(0x45);
digitalWrite(SS_PIN, HIGH);
SPI.endTransaction();
delay(1000);
}
With Serial Monitor on Slave it just show Received: 0.
Can somebody help me what I'm doing wrong?
Thanks.