4
\$\begingroup\$

I am thinking about purchasing this RTC ( real time clock ) module.

Since this particular item comes supplied without a battery, I wonder how the time is being kept running in the chip since it's manufactured and until a battery is plugged in the socket ?

EDIT :

After checking the plenty of nice answers that this question has received, I believe I didn't form my question well.

Real time clock is supposed to give you information about year ( counting leap years ), month, day of the week, time ( hours, minutes, seconds ). So if the module arrives without battery installed, what time will it show ? And how can you set the correct time on the chip ?

\$\endgroup\$
  • \$\begingroup\$ Check out my updated answer. I think I'm addressing your updated question now. \$\endgroup\$ – Ricardo Jun 20 '14 at 13:33
  • \$\begingroup\$ Like just about any clock, you have to set it before the time it shows is correct. \$\endgroup\$ – Olin Lathrop Jun 20 '14 at 14:14
5
\$\begingroup\$

Page 8 of DS1307 datasheet states the following:

On first application of power to the device the time and date registers are typically reset to 01/01/00 01 00:00:00.

So, when you apply power to the RTC, it will typically come with its time reset to zeroes. However, as James Cameron pointed out in his answer, the only guaranteed response to power failure is the clock halt (CH) bit 7 of register 0. So, the data may be corrupt at start up. In any case, after you apply power to the device, you'll have to set the time yourself. Then it will start ticking by itself.

Communication with the DS1307 RTC is done via the I2C protocol. One would usually use an MCU to control it. I usually use an ATmega328P to do so without problems. You can use a PIC, Raspberry Pi or an Arduino, or any other popular MCUs out there.

Wiring it is simple enough. Just follow the DS1307 datasheet. The most usual setup is the following:

  • Wire 5V and GROUND terminals to your board main power supply.
  • Place a 3V coin cell on its holder. That will let the RTC to keep time while main power is disconnected.
  • Wire the SDA and SCL to the corresponding pins at your MCU board. On the ATmega328P, those are pins 27 and 28, respectively. On Arduino Uno, these are analog input pins A4 and A5 respectively.
  • The SQ terminal is likely to be wired to the DS1307 SQW/OUT output pin (Square Wave/Output Driver). When enabled, the pin outputs one of four square-wave frequencies (1Hz, 4kHz, 8kHz, 32kHz). It is useful for triggering interrupts in your code, to let the program know when the time (seconds) has changed, for example.
  • There is another terminal, DS, that I'm not familiar with. Make your you find and read the module manual and understand what it is for while designing the board that will use the RTC.

In your program, you need make your MCU talk to the RTC using the I2C protocol. You can do it by yourself, but the easiest is to just find a library that makes the communication simpler to you. For Arduinos, there's a few libraries out there that were developed specifically to control the DS1307. These libraries will provide functions that you can call from your program to set the initial (current) time and then to read the time whenever needed.

I hope this update addresses your question.

\$\endgroup\$
5
\$\begingroup\$

It needs a battery. It is shipped without a battery so as to avoid triggering regulations on shipping batteries, and to avoid having to stock batteries that will eventually lose shelf life.

\$\endgroup\$
4
\$\begingroup\$

The module doesn't come with a battery. But from the picture, it does come with the battery holder. Meaning you just have to buy your own battery.

As for the default date/time, it will be set to either epoch (arbitrary start date chosen by the designers), or more likely reset to all Zeros, at powerup, and immediately should start counting up. It will keep time until VCC goes bellow its minimum (if VBat is also bellow its minimum or no battery installed). This can be confirmed in the datasheet for which ever specific IC your module has, or a similar IC with the same eeprom format like the Maxim/Dallas DS1037.

To set/read the time, apply power, and use i2c messages as specified by the datasheet.

\$\endgroup\$
4
\$\begingroup\$

I disagree with Ricardo a little bit, where he says

it will come with the time reset

The reset data pattern is only typical, it isn't guaranteed. In the datasheet, the only guaranteed response to power failure is the clock halt (CH) bit 7 of register 0. If you care about the data, your software must check the CH bit, and if it is set clear the date and time, even if it is clear already most of the time you see it.

I've spent days characterising the response to partial and total power failure of RTC chips on the OLPC XO laptop, and captured plenty of evidence of corruption of the data registers when VBAT was marginal. CH was reliable.

\$\endgroup\$
  • \$\begingroup\$ Thanks for pointing it out, James. I've corrected my answer accordingly. \$\endgroup\$ – Ricardo Jul 2 '14 at 15:27
1
\$\begingroup\$

The time isn't kept running: you have to set it every time the RTC loses power (this is why it will often have a separate battery). It is only running when it has power.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.