Quick Testing RTC DS3231

In the past, I was using a simple oscillator to measure the time. This is not the best way, ant even worst if the oscillator is 8MHz from the microcontroller (Losing seconds every day!)

Then, an oscillator with the frequency 32.768kHz improve the measure. 32.768 kHz it is precisely half of a 16-bit counter. Start counting at 0x8000 (or 32768). When the counter rolls over from 65535 to 0, then you know that exactly one second has passed.

After that, I tried a RTC with the oscillator 32.768. In this way, I am no worries about how to count the seconds with the microcontroller, a dedicated chip measure the time for me. I’ve tried the RTC MCP79410-I/SN SO-8.

It is not so bad, but is necessary an external oscillator.

In this test, I am going to use the DS3231

The DS3231 is a extremely accurate I2C real-time clock (RTC) with an integrated temperature-compensated crystal oscillator (TCXO) and crystal. The device incorporates a battery input, and maintains accurate timekeeping when main power to the device is interrupted. The integration of the crystal resonator enhances the long-term accuracy of the device as well as reduces the piece-part count in a manufacturing line.

rtc

Price

I’ve consider is quite expensive (~8e), compare with others RTC (Although, it is more precise, oscillator integrated and temperature sensor for compensation…) but, as always, you can buy in aliexpress for much less.

Schematic and layout

Adafruit has a breakout pcb for this component and they have also the component for eagle in their library if you decide to build your own system.

Pinout

You can find the pinout in the official datasheet,

Pinout1

Pinout2

And an example with the tyipical values for the component for using with a pic microcontroller

Software

There are several libraries using this RTC for arduino (or for the atmega328), but this library from Makuna seems to be very simple and updated.

Another library for complex (or complete) is this one JChristensen or the one from adafruit