Description
The DS1302 RTC Module provides basic Real Time Clock/Calendar capability over a 3-wire interface.
PACKAGE INCLUDES:
- DS1302 RTC Module
KEY FEATURES OF DS1302 RTC MODULE:
- Provides seconds / minutes / hours / date / day of week and year with leap-year compensation
- Uses CR1220 battery for battery back-up
- 3.3 and 5V compatible
The DS1302 RTC Module is based on one of the original Real Time Clock/Calendar chips that has been around for a very long time and there are many projects based on it.
The module uses a 32 kHz crystal, communicates via a 3-wire interface and works with either 3.3 or 5V uCs.
The module provides seconds, minutes, hours, date, day of week and year with leap-year compensation. You can use 24-hour or 12-hour mode with AM/PM indication.
There is also 31 bytes of RAM that is battery backed. The module uses a CR1220 back-up battery when power is removed. (Note: The module does not ship with a battery.)
Module Connections
The board has a 6-pin right-angle male header.
1 x 6 Header
- RST = Chip Enable. This is labeled EN on some modules
- I/O = Bidirectional data I/O
- SCLK = Shift Clock
- GND = Ground
- VCC2 = Connects to uC power (3.3 or 5V)
- VCC1 = N/C if on-board battery is used. Can be used for off-board battery
OUR EVALUATION RESULTS:
The DS1302 is an older device and the accuracy of time-keeping is not that great over long periods of time.
We offer these modules as they are used in a lot of projects and for experimenting with RTCs they work fine and we sell these cheap for use in projects that utilize them. If you are looking for a solid device to embed into a permanent project, you will be better off with our DS3231 RTC with EEPROM module available down below. it has excellent timekeeping stability and also has the advantage of having a non-volatile EEPROM on the module which can be handy for some applications.
The program below sets the current time in the module and then updates the time in the Serial Monitor Window. The program uses pins 6 – 8 for the 3-wire communications, but any 3 digital pins can be used. You will need to install the DS1302.h library.
These two lines in the program set the current year, month, day, hour in 24-hour format, minute, second, day of week. Update these values before running the program.
Time t(2018, 7, 9, 16, 02, 00, Time::kMonday);
rtc.time(t);
You can then comment these two lines out if you want to run the program again without resetting the time.
DS1302 RTC Module Example Program
/* DS1302 RTC Test This program uses a DS1302 RTC module and outputs the time and date to the Serial Monitor Window. Connect RST(CE) to D8, I/O to D7, SCLK to D6, VCC2 to 5V, GND to ground Need to install 'DS1302.h' library. If running program for first time, uncomment these lines and enter the correct day/time info //Time t(2018, 7, 9, 16, 02, 00, Time::kMonday); //rtc.time(t); */ #include <DS1302.h> const int RST_PIN = 8; // Chip Enable const int IO_PIN = 7; // Input/Output const int SCLK_PIN = 6; // Serial Clock // Create a DS1302 object. DS1302 rtc(RST_PIN, IO_PIN, SCLK_PIN); //=============================================================================== // Initialization //=============================================================================== void setup() { Serial.begin(9600); // Initialize chip by turning off write protection and clearing the clock halt flag. rtc.writeProtect(false); rtc.halt(false); // Set the date and time. This only needs to be done once if there is a battery backup // Format (Year, Month, Day, Hour (24 Format), Minute, Second, Day of Week) // Update the following line to current date time the first time it is run then comment out Time t(2018, 7, 9, 16, 02, 00, Time::kMonday); rtc.time(t); } //=============================================================================== // Main //=============================================================================== void loop() { PrintTime(); // Printout the time to the Serial Monitor window every second. delay(1000); } //=============================================================================== // DayAsString Function: Returns the day of the week //=============================================================================== String DayAsString(const Time::Day day) { switch (day) { case Time::kSunday: return "Sunday"; case Time::kMonday: return "Monday"; case Time::kTuesday: return "Tuesday"; case Time::kWednesday: return "Wednesday"; case Time::kThursday: return "Thursday"; case Time::kFriday: return "Friday"; case Time::kSaturday: return "Saturday"; } return "(Incorrect Day)"; } //=============================================================================== // PrintTime Function: Prints the time and date to the Serial Monitor Window //=============================================================================== void PrintTime() { // Get the current time and date from the DS1302. Time t = rtc.time(); // Retrieve the day of the week. const String day = DayAsString(t.day); // Print everything out to the Serial Monitor window Serial.print(day); Serial.print(" "); Serial.print(t.yr); Serial.print("-"); Serial.print(t.mon); Serial.print("-"); Serial.print(t.date); Serial.print(" "); Serial.print(t.hr); Serial.print(":"); Serial.print(t.min); Serial.print(":"); Serial.println(t.sec); }
BEFORE THEY ARE SHIPPED, THESE MODULES ARE:
- Inspected
- Basic functionality is tested
- Repackaged in resealable ESD bag
Notes:
- None
Technical Specifications
Operating Rating | Vcc2 | 2.0 – 5.5V (3.3 or 5V typical) |
Vcc1 | 2.0 – 5.5V | |
Power draw | < 300nA @ 2.0V | |
Dimensions | L x W (PCB) | 26 x 17mm (1″ x 0.67″) |
Datasheet | DS1302 Chip |