mirror of
https://github.com/adafruit/RTClib.git
synced 2026-09-15 11:02:35 +00:00
Verify RTC communication in PCF8523 and DS1307 begin()
This change extends the logic already used for verifying comms with the DS3231 (ff898af) to the other two RTCs supported by this library: the PCF8523 and DS1307.
Fixes #64
This commit is contained in:
+12
-6
@@ -755,13 +755,16 @@ static uint8_t bin2bcd(uint8_t val) { return val + 6 * (val / 10); }
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Startup for the DS1307
|
||||
@return Always true
|
||||
@brief Start I2C for the DS1307 and test succesful connection
|
||||
@return True if Wire can find DS1307 or false otherwise.
|
||||
*/
|
||||
/**************************************************************************/
|
||||
boolean RTC_DS1307::begin(void) {
|
||||
Wire.begin();
|
||||
return true;
|
||||
Wire.beginTransmission(DS1307_ADDRESS);
|
||||
if (Wire.endTransmission() == 0)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
@@ -995,13 +998,16 @@ DateTime RTC_Micros::now() {
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Start using the PCF8523
|
||||
@return True
|
||||
@brief Start I2C for the PCF8523 and test succesful connection
|
||||
@return True if Wire can find PCF8523 or false otherwise.
|
||||
*/
|
||||
/**************************************************************************/
|
||||
boolean RTC_PCF8523::begin(void) {
|
||||
Wire.begin();
|
||||
return true;
|
||||
Wire.beginTransmission(PCF8523_ADDRESS);
|
||||
if (Wire.endTransmission() == 0)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
|
||||
@@ -14,6 +14,7 @@ void setup () {
|
||||
|
||||
if (! rtc.begin()) {
|
||||
Serial.println("Couldn't find RTC");
|
||||
Serial.flush(); // ensure above text prints with nRF52 native USB Serial
|
||||
while (1);
|
||||
}
|
||||
|
||||
|
||||
@@ -41,6 +41,7 @@ void setup () {
|
||||
|
||||
if (! rtc.begin()) {
|
||||
Serial.println("Couldn't find RTC");
|
||||
Serial.flush(); // ensure above text prints with nRF52 native USB Serial
|
||||
while (1);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user