RTC DS3231 - High Precision Real Time Clock


RTC DS3231 - High Precision Real Time ClockThe DS3231 is a high-precision real-time clock (RTC) with built-in I2C interface, temperature compensated crystal oscillator (TCXO) and crystal resonator. The device has an input for connecting a backup autonomous power supply, which allows timing and temperature measurement even when the main supply voltage is disconnected. The built-in quartz resonator increases the life of the instrument and reduces the number of external elements required. The DS3231 is available in both commercial and industrial temperature ranges and is packaged in a 300 mil 16 pin SO package.

The RTC provides a countdown of seconds, minutes, hours, days of the week, days of the month and of the year. The end of the month is determined automatically based on the leap year. The real time clock operates in 24 or 12 hour format with indication of the current half of the day (AM / PM). The device has two daily alarms and a square wave output with programmable frequency. Data exchange with the device is carried out through the built-in serial I2C compatible interface.

A precision temperature-compensated reference voltage source and a comparison circuit monitor the main supply voltage VCC and, when it drops below a predetermined threshold, generate a reset signal and transfer the circuit to work from a backup power source. An additional RST pin can be used for external reset.

ZS-042 module based on RTC DS3231N

They are a complete ZS-042 module that can be connected to various devices, not only to the Arduino platform.

The module is built on the DS3231SN microcircuit, which, in fact, is a real time clock. Unlike the old model of watches, for example, on the DS1307 microcircuit, this watch contains an internal quartz resonator, due to which the watch has an accurate movement.

Schematic diagram

ZS-042 Module Based on RTC DS3231N - Schematic Diagram

Location and assignment of pins on the ZS-042 module

32KOutput, frequency 32 kHz
SQWProgrammable Square-Wave Signal Output
SCLSerial CLock
SDASerial Data Line
VCCModule power supply

Description ATMEL AT24C32N

AT24C32N is a 32k EEPROM from Atmel, assembled in a SOIC8 package, running on a two-wire I2C bus. The address of the microcircuit is 0x57, if necessary, it can be easily changed using jumpers A0, A1 and A2 (this allows you to increase the number of connected AT24C32 / 64 microcircuits). Since the AT24C32N chip has three address inputs (A0, A1 and A2), which can be in two states, either log "1" or log "0", eight addresses are available to the microcircuit. from 0x50 to 0x57.

Distinctive features of DS3231

  • Accuracy ± 2 ppm over a temperature range of 0 ° C to + 40 ° C
  • Accuracy ± 3.5 ppm over a temperature range of -40 ° C to + 85 ° C
  • Input for connecting an autonomous power supply to ensure continuous operation
  • Operating temperature range commercial: 0 ° C to + 70 ° C
  • industrial: -40 ° C to + 85 ° C
  • Low consumption
  • Real-time clock that measures seconds, minutes, hours, days of the week, days of the month, month and year with leap year correction up to 2100
  • Two daily alarms
  • Frequency programmable square wave output
  • Fast (400 kHz) I2C interface
  • 3.3V power supply
  • Digital temperature sensor with a measurement accuracy of ± 3 ° C
  • Register containing information about the required tuning
  • Reset input / output nonRST

Power modes

The supply voltage of the microcircuit can be in the range of 2.3 ... 5.5V, there are two power lines, for an external source (Vcc line), and also for a battery (Vbat). The voltage of the external source is constantly monitored, when it falls below the threshold Vpf = 2.5V, it switches to the battery line. The following table shows the conditions for switching between supply lines:

Combinations of voltage levelsActive power line
Vcc <Vpf, Vcc <VbatVbat
Vcc <Vpf, Vcc> VbatVcc
Vcc> Vpf, Vcc <VbatVcc
Vcc> Vpf, Vcc> VbatVcc

The accuracy of the watch is maintained by monitoring the ambient temperature. An internal procedure for adjusting the clock generator frequency is launched in the microcircuit, the amount of adjustment is determined according to a special graph of the frequency versus temperature. The procedure starts after power-up and then runs every 64 seconds.

In order to save charge, when the battery is connected (voltage is applied to the Vbat line), the clock generator does not start until the voltage on the Vcc line exceeds the threshold value Vpf, or the correct address of the microcircuit is transmitted via the I2C interface. The clock generator start-up time is less than one second. Approximately 2 seconds after the power supply (Vcc) is applied, or the address is received via the I2C interface, the frequency correction procedure is started. Once the clock has started, it continues to function as long as Vcc or Vbat is present. On first power-up, the date and time registers are cleared and have the following values ​​01/01/00 - 01 - 00/00/00 (day / month / year / - day of the week - hour / minute / second).

The current consumption when powered by a 3.63V battery is 3 μA, in the absence of data transfer via the I2C interface. The maximum current consumption can reach 300 μA, in the case of using an external power supply with a voltage of 5.5 V and a high data transfer rate I2C.

External reset function

The RST line can be used for external reset and also has a low voltage alarm function. The line is pulled high through an internal resistor, no external pull-up is required. To use the external reset function, a button can be connected between the RST line and the common wire; the microcircuit implements contact bounce protection. The alarm function is activated when the supply voltage Vcc drops below the threshold value Vpf, and the RST line is set to logic low.

DS3231 Register Description

The table below shows a list of real-time clock registers:

The addressD7D6D5D4D3D2D1D0FunctionThe limits
0x00010 SecondsSecondsSeconds00-59
0x01010 minutesMinutesMinutes00-59
0x02012/24AM / PM10 hoursHourClock1-12 + AM / PM or 00-23
10 hours
0x0300000DayDay of week1-7
0x040010 numberNumberdate01-31
0x05Century0010 monthMonthMonths / century01-12 + Century
0x0610 yearsYearYears00-99
0x07A1M110 SecondsSecondsSeconds, 1st alarm00-59
0x08A1M210 minutesMinutesMinutes, 1st alarm00-59
0x09A1M312/24AM / PM10 hoursHourClock, 1st alarm1-12 + AM / PM or 00-23
10 hours
0x0AA1M4DY / DT10 numberDayDay of the week, 1st alarm1-7
NumberDate, 1st alarm01-31
0x0BA2M210 minutesMinutesMinutes, 2nd alarm00-59
0x0CA2M312/24AM / PM10 hoursHourClock, 2nd alarm1-12 + AM / PM or 00-23
10 hours
0x0DA2M4DY / DT10 numberDayDay of the week, 2nd alarm1-7
NumberDate, 2nd alarm01-31
0x0EEOSCBBSQWCONVRS2RS1INTCNA2IEA1IESettings register (Control)
0x0FOSF000EN32kHzBSYA2FA1FStatus register
0x11SIGNDATADATADATADATADATADATADATATemperature register, high byte
0x12DATADATA000000Temperature register, low byte

Time information is stored in binary-decimal format, that is, each digit of a decimal number (from 0 to 9) is represented by a group of 4 bits. In the case of one byte, the low nibble counts ones, high tens, etc. The time is counted in registers with addresses 0x00-0x06, for clock counting, you can select the 12 or 24 hour mode. Setting the 6th bit of the clock register (address 0x02) sets the 12-hour mode, in which the 5th bit indicates the time of day, value 1 corresponds to the time after noon (PM), value 0 corresponds to noon (AM). The zero value of the 6th bit corresponds to the 24-hour mode, here the 5th bit is involved in the counting of hours (values ​​20-23).

The day of the week register increases at midnight, the count goes from 1 to 7, the month register (address 0x05) contains the Century bit (7th bit), which switches when the years count register (address 0x06) overflows, from 99 to 00.

The DS3231 microcircuit implements two alarm clocks, the 1st alarm clock is configured using registers with addresses 0x07-0x0A, the 2nd alarm clock with registers 0x0B-0x0D. Bits A1Mx and A2Mx can be used to configure different modes for alarms, setting the bit excludes the corresponding register from the comparison operation.

Typical wiring diagram for DS3231

Typical wiring diagram for DS3231

DS3231 Pin Layout

DS3231 Pin Layout

one32kHzOutput frequency 32768 Hz. This is an open drain output that requires an external upper pullup resistor. The output operates on any available power source. If not used, it may remain unconnected.
2CCMain power supply. This pin must have a 0.1..1.0 µF decoupling capacitor connected. If not used, it is connected to ground (GND).
3~ INT / SQWActive-low interrupt signal, or square-wave frequency output. This is an open drain output and requires an external upper pullup resistor connected to 5.5V or less. The operating mode of this pin is determined by the INTCN bit of the Control Register (Address 0Eh), and the output frequency depends on the RS2 and RS1 bits. If the ~ INT / SQW pin is not used, it may not be connected.
4~ RSTReset with an active level log. 0. This pin has an open drain, and works as an input and an output. The level indicates the correspondence of the supply voltage V CC to the permissible limit V PF . As soon as V CC  falls below V PF , a log will appear on the ~ RST pin. 0. When V CC exceeds V PF , then after the interval t RST, the ~ RST pin with the pullup resistor will appear log. 1. With an active level log. 0 open drain output combined with an input function that suppresses the bounce of the button contacts. This pin can be activated by a reset request issued by an external pushbutton. The ~ RST pin has an internal 50K pullup resistor connected to V CC... An external pull-up resistor must not be connected. If the generator is disabled, then the t REC time interval is skipped and the ~ RST level will immediately go to log. one.
5..12NCNo connection. These pins must be connected to ground (GND).
thirteenGNDGround, common for supply voltages and all signals.
14BATInput for connecting a backup power supply (usually a 3V lithium battery). If the V BAT pin is used as the main power supply, it must have a 0.1..1.0 µF decoupling capacitor connected with a low leakage current. When used as a backup power supply in V BAT , this capacitor is not needed. If V BAT is not used then connect it to ground (GND).
15SDAI2C interface data. The pin output has an open drain, so an external top pullup resistor is required. The pull-up voltage can be up to 5.5V regardless of the supply voltage V CC .
sixteenSCLI2C interface clock. The voltage at the SCL input can be up to 5.5V, regardless of the supply voltage level V CC .

DS3231 block diagram

DS3231 block diagram

Materials (edit)

DS3231_high precision RTC chip
DS3231_ real time clock connection

Previous Post Next Post

Contact Form