Overview of the DS3231 clock chip

In one testing stand, it was necessary to add a source of autonomous accurate time for logs. In a box with unsorted gadgets somehow turned out to be only a chip DS3231.

This is a real time clock chip. And an unusual RTC. Inside it has its own quartz resonator, as well as a temperature sensor and configuration registers. The spec says that the error will not exceed 2 minutes in a year. There are only 33k transistors inside the DS3231. Let’s try to figure out what kind of ASIC it is and how to work with it.

DS3231 case pinout

https://docs.google.com/spreadsheets/d/1HU7AiqZ2NBZyWqT0Ura-tjRy0CjZiKvkRfyBWxorrsQ/edit#gid=0

Chip wiring diagram

Software part

The chip is programmed via a 2-wire synchronous I2C interface. On the I2C bus, the chip has the address 0x68=0b1101000=104. This is how the I2C address map is displayed when a DS3231 and some other eeprom are connected to the bus.

Any I2C device has 2 addresses. For reading and writing. For DS3231 it is

Address

Meaning

type

bin

hex

main

0110_1000

0x68

read

1101_0001

0xD1

write

1101_0000

0xD0

Bytes are transmitted MSB first. It has 19 configuration registers of 8 bits each. Only 152 bits of configs. Here is the complete register map.

Note that only 8 bits are allocated per year. That is, you can count only 256 years, and if you take into account that there are only 4 bits for tens, it turns out that 159 years. How to encode 2023? It is possible to store only tens and units of the year value in the year (0x06) register. Add or subtract centuries as a constant.

The RTC DS3231 clock is not as good as it says in the spec. Out of the box when working on the street in the summer for two weeks of work, they went 20 minutes ahead of the exact time from the Internet. If you look with an oscilloscope, which produces a 32kHz pin at the quartz output, then there is a rectangular signal not 32768 Hz but 32776Hz.

To finally make sure of this, you can bring the frequency of quartz divided by four to the street. Here it becomes quite clear that the desired frequency of 8192 Hz has never even appeared.

This means that the clock must be adjusted by varying the Aging Offset register with address 10h

According to the spec positive Aging Offset values slow down quartz resonator. This is just what I need. Let’s try to set the maximum slowdown to +127. The frequency of the quartz divided by 4 took a value from the range 8193….8194. This is better than 8194…8197, but 4…8 Hz more than the desired value.

The watch also has thermal compensation. And thermal compensation does not happen by itself. Without thermal compensation, the clock will work very poorly and show 2 minutes more every day. Therefore, it is necessary to periodically take the Control register (0Eh) and set the fifth bit of CONV to 1 bit.

Project Ideas at RTC

–Clocks, alarm clocks, calendars

–A device that reminds you to do something.

— Telematic units, source of TimeStamp(s)

–Navigation systems

Despite the fact that the real-time clock driver itself is a relatively simple microcircuit, however, to work with a real-time clock, you need a whole bunch of various service functions for working with date and time. This is a date comparison. Calculating the ordinal number of a day in a year, converting a date to strings of different national formats, parsing time-date from strings, checking the time data structure for validity, calculating the difference between two dates in seconds, and so on and so forth. That being said, all of this requires unit tests.

How to initialize real time clock?

It is clear that the time must be set via some interface, for example, via UART-CLI. However, the firmware can also parse the time directly from the __TIME__ __DATE__ preprocessor directives. Thus, the time will differ only by the duration of the compilation.

Conclusion

The DS3231 didn’t live up to expectations. It rushes to 4 … 8 Hz, or I just got a defective copy of the microcircuit. We must look for something else. One of two things: the DS3231 chip is really in a hurry, or the Saleae Pro logic analyzer is defective.

If you know other variants of proven RTC modules with a built-in battery compartment, then write in the comments.

Dictionary

Acronym

Decryption

RTC

Real Time Clock

ASIC

application-specific integrated circuit

RST

reset

MSB

most significant bit

SQW

square wave output

AM

After Morning

BCD

binary coded decimal

PM

post meridiem

INT

Interrupt

I2C

Inter-Integrated Circuit

GPS

Global Positioning System

TCXO

temperature compensated crystal oscillator

VCC

Voltage Collector Collector

D.S.

Dallas

Links
http://microsin.net/adminstuff/hardware/ds3231-extremely-accurate-rtc.html
https://cxem.net/mc/mc316.php

https://radiolaba.ru/microcotrollers/ds3231-podklyuchenie-chasov-realnogo-vremeni.html

Control questions:

–Why are clock quartzes made with a frequency of exactly 32768 Hz?

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *