How to control SDA and SCL to reset DS3231

SpitfireMk
Posts: 1
Joined: Tue Aug 31, 2021 8:16 pm

How to control SDA and SCL to reset DS3231

Postby SpitfireMk » Tue Aug 31, 2021 8:30 pm

I'm having some issues with a ESP32 development board (SparkFun ESP32 Thing Plus) and a DS3231 RTC module. Sometimes it starts giving absurd readings (minute 165 for example) and it seems to be triggered after a crash rebooting the board.

I came across this stackoverflow response which points out to this paragraph of the DS3231 datasheet:
The I2C interface is accessible whenever either VCC or VBAT is at a valid level. If a microcontroller connected to the DS3231 resets because of a loss of VCC or other event, it is possible that the microcontroller and DS3231 I2C communications could become unsynchronized, e.g., the microcontroller resets while reading data from the DS3231. When the microcontroller resets, the DS3231 I2C interface may be placed into a known state by toggling SCL until SDA is observed to be at a high level. At that point the microcontroller should pull SDA low while SCL is high, generating a START condition.
Then he gives an example of such function for the ESP8266, but his code doesn't seem to be compatible with the ESP32. I would assume that just using digitalRead and digitalWrite on those pins is not an option based on the example but I honestly don't know how else could I implement it.

Thank you.

Who is online

Users browsing this forum: No registered users and 96 guests