How to use the MH-Real-Time Clock Modules-2 with Arduino.

The MH-Real-Time Clock Module - 2 is based on 'integrated DS1302 inside which there is a real-time clock / calendar and 31 bytes of static RAM.
The integrated model is similar to the DS1307 from which it differs from the DS1302 for some peculiarities:

  • The DS1302 has an SPI interface and the DS1307 has an I2C interface
  • The DS1302 can charge the battery, while the DS1307 not ago
  • The DS1307 is equipped with a programmable square-wave output
  • DS1302 Trickle-Charge Timekeeping Chip

The chip communicates with the microprocessor via a serial interface. The RTC provides: seconds, minutes, hours, day, date, information Month, and Year.
For the interface, in addition to power, only three wires are required: CE (RST), I / O (line Data), and SCLK (serial clock).
Data can be transferred to and from the clock / RAM 1 byte at a time or in a Inico send up to 31 bytes.
The DS1302 is designed to work with a very low power and to store data and clock information with less of 1μW.
The DS1302 has dual power supply pins, a primary (Pin # 1 # 4) and another for the backup battery (Pin # 8 # 4), current 260mAh, non-rechargeable battery. retention time of theoretical data is more than 10 years.
In this application, for example, the primary power supply is provided by Arduino, and the secondary one by battery type CR2032.
The circuit diagram of the DS1302 Real Time Clock Module, VCC is set to accept the primary power supply, this is typically 3.3V, but can use 5V. It is recommended to not apply more than 7V, as this may damage the unit. VBAT is is used for backup power, supplied from 3.3V CR2032 battery.
The quartz crystal is placed between pins # 2 and # 3 pin. the Pin # 5-6-7 are used for data communication between the module and the microcontroller, it is also connected to the CE pin referred to as RST.
Before you load the program you must install the appropriate library which can be downloaded from the website Henning Karlsen, DS1302.
The Arduino sketch verifies the operation of the DS1302 form, showing the serial monitor or display connected 16x2 with I2C interface to date and the current time.
At the first run you will have to indicate the date and the current time to form, this is done you can comment out the line and re-run the compilation, because the value will be stored within the memory of the module power from the backup battery.