Description
The DS3231M RTC with EEPROM Module is a high accuracy real-time clock with battery backup, 4k x 8-bit EEPROM and I2C interface.
PACKAGE INCLUDES:
- DS3231M RTC with EEPROM Module
- CR2032 battery installed
KEY FEATURES OF DS3231M RTC with EEPROM MODULE:
- Accurate timekeeping with temperature compensation
- Provides seconds / minutes / hours / date / day of week and year with leap-year compensation
- 12 / 24 hour formats
- Two programmable time-of-day alarms
- Programmable square wave output
- Digital temperature sensor
- AT24C32 4K x 8-bit EEPROM non-volatile memory
- CR2032 battery backup (included)
- I2C interface
- Power LED
- 3.3 and 5V compatible
DS3231M Real-Time Clock Chip:
The DS3231M RTC with EEPROM Module is based on the capable DS3231M Real Time Clock/Calendar chips which has been around for awhile and has excellent library support. The chip includes a built-in 32kHz resonator.
The temperature reading from the RTC is made available via the I2C bus. This reading is not terribly accurate and is spec’d at ± 3C, though it has been within ± 2C or better in our testing.
The module brings out the 32kHz square wave timing signal that the RTC clock runs on. The output of the chip is open-collector and the module includes a 4.7K pull-up resistor on this line. This clock output may be useful in some applications to either measure the accuracy of the clock timing or to clock other circuits.
The pin marked SQW which stands for Square Wave is a dual purpose output. It can carry either a 1Hz square wave or it can be used as an interrupt output for the built-in time-of-day alarms. This pin is also an open-collector output and the module includes a 4.7K pull-up resistor on this line as well.
Communications with the DS3231M chip is via I2C and it has a fixed address of 0x68.
The DS3231M vs DS3231S(N)
The DS3231S is the standard high accuracy RTC device from Maxim with integrated temperature compensated crystal and has nominal +/- 2ppm frequency accuracy with the ability to further trim the frequency accuracy to as low as 0.1ppm to help compensate for aging. Basic accuracy is stated as +/- 2 minutes per year
The DS3231M is a lower cost version of their chip which uses a resonator instead of a crystal with a +/- 5ppm frequency accuracy and no ability to further trim it. Accuracy is stated as +/- 0.432 seconds-per-day. The ‘M’ variant is fine for many basic time keeping requirements, but the ‘S’ (or ‘SN’) version is optimal where best accuracy is needed.
AT24C32 EEPROM Chip:
The module also includes a separate AT24C32 EEPROM which provides 4K x 8-bits of non-volatile memory. This chip hasn’t nothing to do with the RTC directly, but it can be handy for applications such as data logging which is based on time or can be used for storage of any other data that you want to be non-volatile. This memory is non-volatile by its design and is independent of the battery that is on the module.
When writing/reading the EEPROM, keep in mind that different data types occupy different amounts of memory. For instance Char is 1 byte, Integers are 2 byes and Floats are 4 bytes each.
If you are storing unsigned char data, each memory location (byte) can contain a value of 0-255 and data can be written to each memory location (0,1,2,3,4,5…..)
On the other hand, if you are storing unsigned integer data as might be the case when using the Arduino built-in 10-bit DAC, you need to reserve 2 memory locations for each value that can range from 0-65535 and so you will want to store data in every other memory location such as (0,2,4,6…..)
The EEPROM is rated for a minimum of 1,000,000 write cycles, so there is little concern about wearing out the EEPROM during normal data logging type applications as long as you are not doing something like writing data every second.
The EEPROM also communicates via I2C at the address of 0x57. The module includes jumpers on the 3 address lines (A0-A2) to the EEPROM which potentially allows for having multiple EEPROMs with different addresses in the same system or the address can be changed in case of a conflict with another device. These lines are pulled up to VCC via 4.7K pull-up resistors on the module and a solder short across these pads will ground them and change the address. The possible range of addresses is 0x50 – 0x57.
I2C Interface
The module has an easy to use I2C interface which occupies two addresses. The DS3231M RTC chip is at address 0x68 and the EEPROM is at 0x57.
The I2C lines have 4.7K pull-up resistors which are part of the small resistor packs.
The I2C SDA and SCL signals are also brought out to solder pads along with power and ground on the top of the module to allow for looping these signals out to another module if desired.
Module Connections
The board has a 6-pin right-angle male header.
1 x 6 Header
- 32K = 32K clock output of the DS3231
- SQW = Dual purpose square wave output / Alarm Output
- SCL = I2C SCL – Connects to uC SCL
- SDA = I2C SDA – Connects to uC SDA
- VCC = Connects to uC power (3.3 or 5V). If disconnected, the module operates off the backup battery
- GND = Ground
The module also brings the VCC, GND, SCL and SDA lines out to solder pads on top of the module which can be used to loop these signals through to another module if desired.
OUR EVALUATION RESULTS:
These are nice modules with good timing accuracy. The EEPROM is also quite handy, especially for non-volatile data collection that allows you to upload the data to a computer at some point in the future.
The battery that comes with the module are already installed and running, so remaining lifespan is unknown. Since these are fairly inexpensive batteries to begin with, if you are putting this module into full-time operation in an application, you may want to swap this battery out for one with a known pedigree.
********************************
Important Note: These modules normally come with a 200 ohm resistor installed in the location next to the glass diode which can be seen in some of the pictures. The resistor and diode form a simple charging circuit that is intended for use with LIR2032 rechargeable batteries. Since the module ships with a non-rechargable CR2032 battery, this resistor is removed since recharging it could cause failure of the battery.
The resistor is taped to the back of the battery in case you want to reinstall it for use with a rechargeable LIR2032 battery or you can toss it.
If you do decide to use a rechargeable battery and add this resistor back in, please note that this circuit does not guarantee that the specified 4.2V charging voltage will be applied to the LIR2032 battery, so there is some chance of overcharging and destroying that battery as well. We recommend either staying with the CR2032 type non-rechargeable battery or do some research and possibly make some circuit modifications if necessary to ensure that the charging voltage is correct for the LIR2032 that you use.
The schematic shows the resistor that is removed and the circuitry should you decide to modify it.
*********************************
The program below illustrates the main functions of the module including setting the date/time and reading it back out, writing and reading the EEPROM memory and reading the built in temperature sensor of the DS3231. We are using the uRTCLIB and uEEPROMLib libraries downloadable from the Arduino IDE because it i is nice and small, but there are many libraries to choose from if another one suits your purposes better. These libraries do not support the time-of-day alarms or programming the SQW output.
If you need to set the date/time, uncomment the rtc.set(0, 41, 8, 3, 20, 8, 19); and enter the current values as shown below.
The format is (Seconds 0-59, Minutes 0-59, Hours 0-23, Day of Week 1-7, Day of Month 1-31, Month 1-12, Year 00-99)
Download the program and then comment this line back out so that you don’t accidentally overwrite the time again. Setting the exact time down to the second can be difficult since it depends on the compile and download time but you can usually get within a couple of seconds.
The rest of the program does a few different things to illustrate the use of the RTC and EEPROM memory and sends the output to the Serial Monitor Window.
The program first does a couple of write and reads to the EEPROM of several different data types which take different amounts of memory.
It then writes the entire EEPROM with values ranging from 0-255.
It then goes back and reads out the data from the first 11 memory locations, one per second, while also reporting the current time and temperature. Notice that in bytes 0 – 6, there will be the Char, Int and Float data that we wrote at first so you can see what it looks like when read back out as bytes. Bytes 7 – 10 should contain the numbers that match their addresses 7 – 10.
Once it goes through the first 11 EEPROM addresses, it writes 0’s to the entire EEPROM to erase it and then suspends execution.
To connect, simply connect the SDA pin to I2C SDA and SCL pin to I2C SCL on MCU. Also connect Vcc to 3.3V or 5V to match MCU and ground to groun.
DS3231 RTC with EEPROM Module Example Program
/* DS3231 RTC and EEPROM Test This program exercises the DS3231 RTC module with built-in EEPROM It tests the EEPROM first 7 bytes and then writes the value 0-255 to the entire EEPROM It then outputs the date, time, temperature and EEPROM values by address to the Serial Monitor Window. Connect SDA to SDA and SCL to SCL. VCC connects to 3.3 or 5V, GND to ground Need to install 'uRTCLib.h' and uEEPROMLib libraries. If running program for first time, uncomment these line and enter the correct day/time info // rtc.set(0, 39, 13, 6, 19, 10, 18); Once correct date/time info has been entered, comment this line back out. */ #include "Arduino.h" #include "Wire.h" #include "uRTCLib.h" #include "uEEPROMLib.h" uRTCLib rtc(0x68); // Create objects and assign module I2c Addresses uEEPROMLib eeprom(0x57); unsigned int addr_EEPROM; // Variable to store current EEPROM memory address //=============================================================================== // Initialization //=============================================================================== void setup() { Serial.begin(9600); Wire.begin(); // Use following command once to set current day/time, then disable by commenting it out. // rtc.set(0, 41, 8, 3, 20, 8, 19); // Format: Seconds(0-59), Minute(0-59), Hour(0-23), Day of Week - Sun thru Sat (1-7), // Day of Month(1-31), Month(1-12), Year(00-99) // Below are dummy values to test the EEPROM write/read with char char_temp = 'A'; int int_temp = 32123; float float_temp = 3.1416; // Test EEPROM Write/Read Functionality Serial.print("Writing CHAR: "); // Test Char value (1 byte) Serial.println(char_temp); if (!eeprom.eeprom_write(0, char_temp)) { Serial.println("Failed to store CHAR"); } else { Serial.println("CHAR correctly stored"); } Serial.println(); Serial.print("Writing INT: "); // Test Integer value (2 bytes) Serial.print(int_temp); if (!eeprom.eeprom_write(1, int_temp)) { Serial.println("Failed to store INT"); } else { Serial.println("INT correctly stored"); } Serial.println(); Serial.print("Writing FLOAT: "); // Test Floating Point (4 bytes) Serial.print(float_temp, 4); if (!eeprom.eeprom_write(3, float_temp)) { Serial.println("Failed to store FLOAT"); } else { Serial.println("FLOAT correctly stored"); } Serial.println(); char_temp = 0; // Clear the variables and reinitialize with values read from EEPROM int_temp = 0; float_temp = 0; Serial.println ("Reading Values Back Out of EEPROM"); Serial.print("CHAR: "); eeprom.eeprom_read(0, &char_temp); Serial.println(char_temp); Serial.print("INT: "); eeprom.eeprom_read(1, &int_temp); Serial.println(int_temp); Serial.print("FLOAT: "); eeprom.eeprom_read(3, &float_temp); Serial.println((float) float_temp, 4); Serial.println(); Serial.println("Writing the values ranging from 0-255 into the entire EEPROM"); Serial.println("starting at location 7. This will take a few moments"); for (addr_EEPROM = 7; addr_EEPROM < 4096; addr_EEPROM++) { eeprom.eeprom_write(addr_EEPROM, (unsigned char) (addr_EEPROM % 256)); if (int i = addr_EEPROM % 100 == 0) Serial.print("."); // Prints a '.' every 100 writes to EEPROM } Serial.println(); addr_EEPROM = 0; } //=============================================================================== // Main //=============================================================================== void loop() { rtc.refresh(); Serial.print("Date: "); Serial.print(rtc.month()); Serial.print('/'); Serial.print(rtc.day()); Serial.print('/'); Serial.print(rtc.year()); Serial.print(" Time: "); Serial.print(rtc.hour()); Serial.print(':'); Serial.print(rtc.minute()); Serial.print(':'); Serial.print(rtc.second()); Serial.print(" "); Serial.print(DayAsString(rtc.dayOfWeek())); Serial.print(" Current Temp: "); Serial.print(rtc.temp()/100); Serial.print(" EEPROM Addr/Data "); Serial.print(addr_EEPROM); Serial.print(": "); Serial.print(eeprom.eeprom_read(addr_EEPROM)); Serial.println(); addr_EEPROM++; // Increment memory location delay(1000); // Pause between updates // We are just going to check the first 10 addresses, then clear the memory // Address 0-6 will contain the Char, Int and Float data. 7 thru 10 should // contain the numbers 7-10 if (addr_EEPROM >= 11) { Serial.println("Clearing the entire EEPROM. This will take a few moments"); for (addr_EEPROM = 0; addr_EEPROM < 4096; addr_EEPROM++) { eeprom.eeprom_write(addr_EEPROM, (unsigned char) (0)); if (int i = addr_EEPROM % 100 == 0) Serial.print("."); // Prints a '.' every 100 writes to EEPROM } Serial.println(); Serial.println("Memory Erase Complete"); while (1); //Stops further execution of the program } } //=============================================================================== // DayAsString Function: Accepts 1-7, Returns the day of the week as string //=============================================================================== String DayAsString(int day) { switch (day) { case 1: return "Sunday"; case 2: return "Monday"; case 3: return "Tuesday"; case 4: return "Wednesday"; case 5: return "Thursday"; case 6: return "Friday"; case 7: return "Saturday"; } return "(Incorrect Day)"; }
BEFORE THEY ARE SHIPPED, THESE MODULES ARE:
- Inspected
- Basic functionality is tested
- Repackaged in resealable ESD bag
Notes:
- None
Technical Specifications
Operating Rating | Vcc | 2.3 – 5.5V (3.3 or 5V typical) |
Battery | CR2032 (3V Coin) | |
Power draw | < 300uA (typ) | |
Accuracy (0-40°C) | ± 2ppm | |
Dimensions | L x W (PCB) | 38 x 22mm (1.5″ x 0.87″) |
Datasheet | Maxim | DS3231M Chip |
Country of Origin | China | |
Atmel | AT24C32 |