Greetings everyone!
I have a project that uses the DS3231 RTC and I know that if I disconnect the module, my program won't even get past the RTC's constructor and will stay there until I connect it, which is logical. However, I would like to skip that "hanging" if the RTC has an error or something, so my program can continue without it.
Something like error catching. So I used the Wire library to do this job, but with no success so far. I also use the wonderful DS3231 library from Mr. Karlsen.
In the small part of the code I wrote below, I have the module connected, but I still want to check if everything's fine, like pinging the device.
void Graphics::InitializeRTC() const
{
Wire.beginTransmission(104);
byte connection = Wire.endTransmission();
myGLCD.setColor(255, 255, 255);
myGLCD.setBackColor(0, 0, 0);
myGLCD.setFont(SmallFont);
if (connection1 == 0)
{
myGLCD.print("CLOCK IS THERE", CENTER, 150);
}
else
{
myGLCD.print("NO CLOCK", CENTER, 150);
return;
}
rtc.begin();
currentTemperature = rtc.getTemp();
currentDate = rtc.getDateStr();
currentClock = rtc.getTimeStr();
timeString = rtc.getTimeStr();
currentHours = timeString.substring(0, 2);
currentMinutes = timeString.substring(3, 5);
currentSeconds = timeString.substring(6, 8);
}
So I transmit at address 104 which is 0x68 of the RTC module. But the answer I receive is always != 0 and therefore I always get the message "NO CLOCK", even though the clock is up and running. Is there any other way to ping the device so I can catch any errors and prevent my program from getting stuck? Thank you for your time.