DS1307 RTC and the RTC.chipPresent command

Hello all,

I've been playing around with my Arduino UNO and an DS1307 RTC circuit. It know it is correctly wired because I've double checked it, and I'm also able to run these three examples: SetTime, TimeRTC and ReadTest (all from the 'DS1307' and 'Time' libraries)

I have set as one of my first setup check questions

if (RTC.chipPresent)
{
    ...
}
else
{
    Print out error
}

The thing is I'm alway getting the printout error and, furthermore, I'm also having trouble when opening my results file on my SD card.

According to the DS1307 documentation, the RTC.chipPresent function should be used after the four functions, but I've seen in the examples this is not the case.

Could anyone please clarify how to use this function, please?

This is my startup I mentioned:

//Clock

        Serial.print("Initializing RTC... ");

        if (RTC.chipPresent())
        {
            Serial.println("ChipPresent");
            if (getDate(__DATE__) && getTime(__TIME__))
            {
                RTCparse = true;
                if (RTC.write(tm))
                {
                    RTCconfig = true;
                }
            }
        }
        else
        {
            Serial.println("DS1307 RTC not present!  Please check the circuitry.");
        }

        if (RTCparse && RTCconfig) 
        {
            Serial.print("RTC configured on:");
            Serial.print(__DATE__);
            Serial.print("at ");
            Serial.println(__TIME__);

        } 
        else
        {
            if (RTCparse) 
                {
                    Serial.println("RTC Communication Error.  I couldn't write the current time in it");
                } 
                else 
                {
                Serial.print("Could not parse info from the compiler.  Last Sync on: ");
                Serial.print("Date=");
                Serial.print(__DATE__);
                Serial.print(", at ");
                Serial.println(__TIME__);
                }
        }

        setSyncProvider(RTC.get);
        if(timeStatus()!= timeSet)
        {
            Serial.println("Unable to sync with the RTC");
        }
        else
        {
            Serial.println("RTC has set the system time");
        }

You forgot to mention the library you're using! There are about half a dozen of them, so this information is relevant.

If you use this one: https://www.pjrc.com/teensy/td_libs_DS1307RTC.html, you have to call either read() or write() before you can use the chipPresent() method.

Get the RTC code working correctly first, then delve into the SD card problem.

It seems it has to do with the fact you need to call the read() or write() function before asking if the chip is present…