Closed rakhmaevao closed 5 years ago
I have an ESP32 project and I cant seem to get my DS3231 to work....I've remapped the SDA and SCL pins as you suggest here but to no avail
Remaping can only help configuration I2C in ESP32. Problem can be in DC3231, in wire or another. Can you view the SDA and SLC line with an oscilloscope or logic analyzer?
I have just tested a RTClib, DC3231, with a LoadLin32 Lite clone which does not have pin 21. To make it work for DS3231, I made the following changes in the RTClib.cpp:
//////////////////////////////////////////////////////////////////////////////// // RTC_DS3231 implementation
boolean RTC_DS3231::begin(int sda, int scl) { Wire.begin(sda,scl); return true; }
boolean RTC_DS3231::begin(void) { Wire.begin(); return true; }
And in the RTClib.h:
EDIT:
After further investigation, -1 is used as standard value for pin number
in Wire.
In that case, the pin numbers defined for the architecture are used.
So
boolean begin(int sda = 21, int scl = 22);
should be replaced by
boolean begin(int sda = -1, int scl = -1);
NOTE: -1 is not tested.
class RTC_DS3231 { public:
boolean begin(int sda = -1, int scl = -1); //EDITED
boolean begin(void);
static void adjust(const DateTime& dt);:
And the DS3231 works with RTClib.
For remaping pins SDA and SCL correct file RTClib.cpp:
https://github.com/adafruit/RTClib/blob/82d00a1a15bcf738b001e42bf26a3d1f1a15be32/RTClib.cpp#L240
Use: Wire.begin(RTC_SDA, RTC_SCL);