Hi. I am working on communicating between 2 esp32 boards using i2c and pins 18 as SDA and Pin 19 as SCL.
However, everything works well with Master ESP but slave ESP resets.
Here are the codes:
Master ESP:
#include <Wire.h>
#define I2C_SLAVE_ADDR 0x08 // Slave I2C address
void setup() {
Wire.begin(18, 19); // Initialize I2C with SDA on pin 18 and SCL on pin 19
Serial.begin(115200);
}
void loop() {
Wire.beginTransmission(I2C_SLAVE_ADDR); // Start I2C transmission to the slave
Wire.write("Hello from master"); // Send a message to the slave
Wire.endTransmission(); // End the transmission
Serial.println("Data sent to slave");
delay(1000); // Wait 1 second before sending data again
}
Slave Code:
#include <Wire.h>
#define I2C_SLAVE_ADDR 0x08 // Slave I2C address
void receiveEvent(int bytes) {
while (Wire.available()) {
char c = Wire.read(); // Read each byte sent by the master
Serial.print(c); // Print the received character
}
Serial.println(); // Print a new line after the message
delay(1000);
}
void setup() {
Wire.begin(I2C_SLAVE_ADDR, 18, 19); // Initialize I2C as a slave with SDA on pin 18 and SCL on pin 19
Wire.onReceive(receiveEvent); // Register event to handle incoming data
Serial.begin(115200);
Serial.println("I2C Slave Ready");
}
void loop() {
// Nothing to do in the main loop, data is received in the receiveEvent callback
}
I have connected SCL-SCL, SDA- SDA and common ground between two esps.
Error I am getting:
"
rst:0x8 (TG1WDT_SYS_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0030,len:1184
load:0x40078000,len:13260
"
Requesting you to help as this is crucial for my current project