@@ -118,6 +118,24 @@ bool ws_sdcard::InitDS3231() {
118118 _rtc_ds3231->adjust (DateTime (F (__DATE__), F (__TIME__)));
119119 return true ;
120120}
121+ /*
122+ void scanI2C() {
123+ byte error, address;
124+ int devices = 0;
125+ Wire.begin();
126+ Serial.println("Scanning I2C bus...");
127+ for(address = 1; address < 127; address++) {
128+ Wire.beginTransmission(address);
129+ error = Wire.endTransmission();
130+ if (error == 0) {
131+ Serial.print("Device found at address 0x");
132+ if (address < 16) Serial.print("0");
133+ Serial.println(address, HEX);
134+ devices++;
135+ }
136+ }
137+ if (devices == 0) Serial.println("No I2C devices found");
138+ } */
121139
122140/* *************************************************************************/
123141/* !
@@ -127,9 +145,17 @@ bool ws_sdcard::InitDS3231() {
127145*/
128146/* *************************************************************************/
129147bool ws_sdcard::InitPCF8523 () {
148+ // pinMode(PIN_I2C_POWER, INPUT);
149+ // delay(1);
150+ // bool polarity = digitalRead(PIN_I2C_POWER);
151+ // pinMode(PIN_I2C_POWER, OUTPUT);
152+ // digitalWrite(PIN_I2C_POWER, !polarity);
153+
154+ // scanI2C();
155+
130156 _rtc_pcf8523 = new RTC_PCF8523 ();
131157 Serial.println (" Begin PCF init" );
132- if (!_rtc_pcf8523->begin ()) {
158+ if (!_rtc_pcf8523->begin (&Wire )) {
133159 WS_DEBUG_PRINTLN (
134160 " [SD] Runtime Error: Failed to initialize PCF8523 RTC on WIRE" );
135161 if (!_rtc_pcf8523->begin (&Wire1)) {
@@ -140,8 +166,10 @@ bool ws_sdcard::InitPCF8523() {
140166 }
141167 }
142168 Serial.println (" End PCF init" );
143- if (_rtc_pcf8523->lostPower ())
169+ if (! _rtc_pcf8523->initialized () || _rtc_pcf8523-> lostPower ()) {
144170 _rtc_pcf8523->adjust (DateTime (F (__DATE__), F (__TIME__)));
171+ }
172+ _rtc_pcf8523->start ();
145173 return true ;
146174}
147175
@@ -170,16 +198,12 @@ bool ws_sdcard::ConfigureRTC(const char *rtc_type) {
170198 // Initialize the RTC based on the rtc_type
171199 if (strcmp (rtc_type, " DS1307" ) == 0 ) {
172200 did_init = InitDS1307 ();
173- WS_DEBUG_PRINTLN (" [SD] Enabled DS1307 RTC" );
174201 } else if (strcmp (rtc_type, " DS3231" ) == 0 ) {
175202 did_init = InitDS3231 ();
176- WS_DEBUG_PRINTLN (" [SD] Enabled DS3231 RTC" );
177203 } else if (strcmp (rtc_type, " PCF8523" ) == 0 ) {
178204 did_init = InitPCF8523 ();
179- WS_DEBUG_PRINTLN (" [SD] Enabled PCF8523 RTC" );
180205 } else if (strcmp (rtc_type, " SOFT_RTC" ) == 0 ) {
181206 did_init = InitSoftRTC ();
182- WS_DEBUG_PRINTLN (" [SD] Enabled software RTC" );
183207 } else {
184208 WS_DEBUG_PRINTLN (
185209 " [SD] Runtime Error: Unknown RTC type found in JSON string!" );
0 commit comments