Good morning,
im new to the topic of I2C, was reading a lot in the past and try to understand how it works. Maybe I made something wrong or misunderstood anything. I was starting step by step. My Master µC is an Espressif ESP32-S2 and I made different setups (short distances on breadboard):
-
I2C Connection between ESP32-S2 and external real time clock (RTC): The SDA and SCA pins of the ESP32-S2 (Master device) are directly connected with the RTC DSB3231 (Slave). The RTC is power by 3.3V, GND is connected as well. At the clock board are already pullup resistors for SDA and SCL available (4.7kOhm each) so i had nothing to do here. I tested the connection and it works like charme.
-
How cool would it be to communicate with an other ESP8266 instead of the RTC? It should be possible since core 2.5.0: Release 2.5.0 · esp8266/Arduino · GitHub. I was using this example code at the ESP8266 (Slave): Arduino/slave_receiver.ino at master · esp8266/Arduino · GitHub. At the master device, I was sending just random stuff and was checking the serial monitor of the slave device. Everything perfect. Everything is transmitted and received perfectly. Since the RTC was removed, I added one pullup resistor (2.4kOhm) for SDA and an other one for SCL.
-
The last step was to connect all together. I removed the previous added 2.4 kOhm resistors because of the RTC board (which already have pullups) and was connecting all SDA and SCL lines together. My sketch for the master device is as simple as possible, the slave is still the same as before (just reading if there is income).
Short summary of the master device sketch: if the RTC (slave) is available, reading time, date and day of week of the RTC and store values to char array. This values are printed to the serial monitor of the master device. After that, just send random stuff to the ESP8266 (slave). I can check the received data with a second serial monitor at the slave device. This code is in a loop without delay and will be executed every second. And here is the code of the master device:
#include <Wire.h>
#include "DS3231_RTC.h"
#define SDA_PIN 8
#define SCL_PIN 9
#define RTC_ADDRESS 0x68
#define ESP8266_ADDRESS 0x08
DS3231_RTC rtc(RTC_ADDRESS);
unsigned long previousMillis = 0;
const long interval = 1000;
char rtc_time[6];
char rtc_date[9];
char rtc_dow[11];
int counter = 0;
void setup(){
//Wire.setClock(100000L);
Wire.begin(SDA_PIN, SCL_PIN);
Serial.begin(115200);
}
void loop(){
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval) {
previousMillis = currentMillis;
if(rtc.available()){
rtc.getTime(CLOCK, rtc_time);
rtc.getDate(rtc_date);
rtc.getDow(rtc_dow);
Serial.print("Counter: "); Serial.println(counter);
Serial.print("Time: "); Serial.println(rtc_time);
Serial.print("Date: "); Serial.println(rtc_date);
Serial.print("Day of week: "); Serial.println(rtc_dow);
Serial.println();
}
Wire.beginTransmission(ESP8266_ADDRESS);
Wire.write(0x11); // Send random stuff
Wire.write(0x89);
Wire.write(0x38);
Wire.write(0x12);
Wire.endTransmission();
counter++;
}
}
The connection between Master and RTC seems to be okay. I can read and print the values of the RTC. Sometimes there is a wrong value or nothing (RTC not available) but for the most of the time, it looks good. The connection between Master and ESP8266 is almost okay as well. Its the same as with the RTC, some values are sometimes not received.
But here is the point: The Master device ist crashing randomly. Sometimes after 1 minute, sometimes after 30 minutes, sometimes twice in a row.. I get this message:
Guru Meditation Error: Core 0 panic'ed (Interrupt wdt timeout on CPU0).
Core 0 register dump:
PC : 0x4002a360 PS : 0x00060034 A0 : 0x8002aa6d A1 : 0x3ffbfa70
A2 : 0x3ffcd96c A3 : 0x00000001 A4 : 0x00060021 A5 : 0x3ffcd920
A6 : 0x00000001 A7 : 0x00000000 A8 : 0x8002a360 A9 : 0x3ffbfa60
A10 : 0x00060023 A11 : 0x00000003 A12 : 0x00060023 A13 : 0x3ffcd978
A14 : 0x00000000 A15 : 0x00000000 SAR : 0x0000001f EXCCAUSE: 0x00000005
EXCVADDR: 0x00000000 LBEG : 0x00060023 LEND : 0x3ffcd978 LCOUNT : 0x40025ee0
Core 0 was running in ISR context:
EPC1 : 0x4002a780 EPC2 : 0x00000000 EPC3 : 0x00000000 EPC4 : 0x4002a360
Backtrace:0x4002a35d:0x3ffbfa70 0x4002aa6a:0x3ffbfa90 0x40026619:0x3ffbfac0 0x40026df6:0x3ffbfaf0 0x4002a77d:0x3ffc7fb0 0x400815e0:0x3ffc8000 0x4008136d:0x3ffc8020 0x40081469:0x3ffc8040 0x40081213:0x3ffc8060 0x40081ee5:0x3ffc8080
As I already said, Im not an expert with I2C. My plan is to connect two more slave devices to the bus in the future. But it already doesnt work properly with two slave devices.. What did I wrong? What can cause a reboot of the master device? If im testing the connection to each device separately (point 1 and point 2), everything works as expected. I was playing around with the I2C clock frequency, but without success. A lower frequency will cause a reboot of the master device more often, a higher frequency causes more errors with reading the RTC.
Any Ideas?
Best regards