Details
BUY DS12885 https://www.utsource.net/itm/p/12541445.html
Below is the parameter table and instructions for the DS12885 Real-Time Clock (RTC) IC.
DS12885 Parameter Table
Parameter | Symbol | Min | Typ | Max | Unit |
---|---|---|---|---|---|
Supply Voltage | Vcc | 2.0 | 3.6 | 5.5 | V |
Operating Temperature | Ta | -40 | +85 | °C | |
Standby Current | Icc | 0.2 | 0.5 | 1.0 | μA |
Active Current | Icc | 1.0 | 2.0 | 3.0 | μA |
Output Frequency | fOUT | 32.768 | 32.768 | kHz | |
Timekeeping Accuracy | ±2 | ±2 | ppm/°C | ||
Data Retention Time | 10 | Years | |||
Write Cycle Time | tWC | 5 | 10 | 15 | ms |
Read Cycle Time | tRC | 1 | 2 | 3 | μs |
Reset Pulse Width | tRST | 100 | 200 | 300 | ns |
Clock Output Drive Current | IOUT | 1.0 | 2.0 | 3.0 | mA |
DS12885 Instructions
1. Powering the Device
- Vcc: Connect the supply voltage to the Vcc pin. The DS12885 operates from 2.0V to 5.5V.
- GND: Connect the ground to the GND pin.
2. Clock Input
- X1 and X2: Connect a 32.768 kHz crystal between the X1 and X2 pins for accurate timekeeping.
3. Reset Pin (RST)
- RST: A low pulse on this pin resets the device. The reset pulse width should be at least 100 ns.
4. Data Communication
- SCL and SDA: Use these pins for I2C communication. The DS12885 has a fixed I2C address.
- CS: Chip select pin for SPI communication. Pull low to enable SPI mode.
- MOSI, MISO, SCK: Used for SPI communication when CS is low.
5. Clock Output (CLKO)
- CLKO: This pin outputs a 32.768 kHz signal. It can be used for external clock synchronization.
6. Battery Backup (VBAT)
- VBAT: Connect a backup battery to this pin to maintain the RTC during power loss. The battery voltage should be between 2.0V and 3.6V.
7. Programming the RTC
- Time and Date Registers: Write the current time and date to the appropriate registers using I2C or SPI.
- Alarm Registers: Set up alarms by writing the desired time to the alarm registers.
- Control Registers: Configure the device settings such as interrupt enable, square wave output, and power-down modes.
8. Reading the RTC
- Time and Date Registers: Read the current time and date from the appropriate registers.
- Status Registers: Check the status of the device, including any pending interrupts or errors.
9. Interrupt Handling
- INT/SQW: This pin can be configured to generate interrupts or square wave outputs. Configure the control registers to enable the desired functionality.
10. Data Retention
- Backup Battery: Ensure the backup battery is connected to maintain data retention during power loss.
Example Code (I2C)
#include <Wire.h>
#define DS12885_I2C_ADDRESS 0x68
void setup() {
Wire.begin();
set_time(2023, 10, 1, 12, 0, 0); // Set time to October 1, 2023, 12:00:00
}
void loop() {
print_time(); // Print the current time
delay(1000); // Wait for 1 second
}
void set_time(int year, int month, int day, int hour, int minute, int second) {
Wire.beginTransmission(DS12885_I2C_ADDRESS);
Wire.write(0); // Start at the seconds register
Wire.write(dec_to_bcd(second));
Wire.write(dec_to_bcd(minute));
Wire.write(dec_to_bcd(hour));
Wire.write(dec_to_bcd(day));
Wire.write(dec_to_bcd(month));
Wire.write(dec_to_bcd(year % 100));
Wire.endTransmission();
}
void print_time() {
Wire.beginTransmission(DS12885_I2C_ADDRESS);
Wire.write(0); // Start at the seconds register
Wire.endTransmission();
Wire.requestFrom(DS12885_I2C_ADDRESS, 7);
if (Wire.available() == 7) {
int second = bcd_to_dec(Wire.read());
int minute = bcd_to_dec(Wire.read());
int hour = bcd_to_dec(Wire.read());
int day = bcd_to_dec(Wire.read());
int month = bcd_to_dec(Wire.read());
int year = bcd_to_dec(Wire.read()) + 2000; // Assuming 2000-2099
Serial.print("Time: ");
Serial.print(hour);
Serial.print(":");
Serial.print(minute);
Serial.print(":");
Serial.println(second);
Serial.print("Date: ");
Serial.print(month);
Serial.print("/");
Serial.print(day);
Serial.print("/");
Serial.println(year);
}
}
int dec_to_bcd(int val) {
return ((val / 10 * 16) + (val % 10));
}
int bcd_to_dec(int val) {
return ((val / 16 * 10) + (val % 16));
}
This example code sets the time and continuously prints the current time using I2C communication with the DS12885.
(For reference only)View more about DS12885 on main site