Hi,
I'm sending bytes one by one from one ESP32 to another ESP32. ESP32 receiving bytes is "Controller" and ESP32 sending bytes is "Peripheral". For some reason "Controller" always receives previously sent byte. Why is that? How to fix?
For example with codes below: Sending Peripheral says "Sending: 173" and receiving Controller says "Received: 172".
"Controller" code:
#include <Wire.h>
void setup() {
Wire.begin(); // join i2c bus as master
Serial.begin(115200);
}
void loop() {
Wire.requestFrom(8, 1); // request 1 byte from peripheral device #8
byte c = Wire.read(); // receive a byte
Serial.print("Received: ");
Serial.println(c);
delay(5000);
}
"Peripheral" code:
#include <Wire.h>
int x = 0;
void setup() {
Serial.begin(115200);
Wire.begin(8); // join i2c bus as slave with address #8
Wire.onRequest(requestEvent); // register event
}
void loop() {
delay(100);
}
// function that executes whenever data is requested by master
// this function is registered as an event, see setup()
void requestEvent() {
Serial.print("Sending: ");
Serial.println(x);
Wire.write(x);
x++;
}
Thanks,
Tipo