Electronic – arduino – How is time of supplied real time clock module maintained without battery

arduinobatteriesrtcstm32time

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 ?

Best Answer

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.