DS3234 Real-Time Clock Module
Introduction
This is a breakout board for MAXIM DS3234 real-time clock.The DS3234 is a low-cost, extremely accurate SPI™ bus real-time clock (RTC) with an integrated temperature-com- pensated crystal oscillator (TCXO) and crystal. The DS3234 incorporates a precision, temperature-compen- sated voltage reference and comparator circuit to monitor VCC. When VCC drops below the power-fail voltage (VPF), the device asserts the RST output and also disables read and write access to the part when VCC drops below both VPF and VBAT. The RST pin is monitored as a pushbutton input for generating a µP reset. The device switches to the backup supply input and maintains accurate timekeeping when main power to the device is interrupted. The integra- tion of the crystal resonator enhances the long-term accu- racy of the device as well as reduces the piece-part count in a manufacturing line. The DS3234 is available in com- mercial and industrial temperature ranges, and is offered in an industry-standard 300-mil, 20-pin SO package.
The DS3234 also integrates 256 bytes of battery-backed SRAM. In the event of main power loss, the contents of the memory are maintained by the power source con- nected to the VBAT pin. The RTC maintains seconds, minutes, hours, day, date, month, and year information. The date at the end of the month is automatically adjust- ed for months with fewer than 31 days, including correc- tions for leap year. The clock operates in either the 24-hour or 12-hour format with AM/PM indicator. Two programmable time-of-day alarms and a programmable square-wave output are provided. Address and data are transferred serially by an SPI bidirectional bus.
Features
- Accuracy ±2ppm from 0°C to +40°C
- Accuracy ±3.5ppm from -40°C to +85°C
- Battery Backup Input for Continuous Timekeeping
- Operating Temperature Ranges
- Commercial: 0°C to +70°C
- Industrial: -40°C to +85°C
- Low-Power Consumption
- Real-Time Clock Counts Seconds, Minutes,
- Hours, Day, Date, Month, and Year with Leap Year
- Compensation Valid Up to 2099
- Two Time-of-Day Alarms
- Programmable Square-Wave Output
- 4MHz SPI Bus Supports Modes 1 and 3
- Digital Temp Sensor Output: ±3°C Accuracy
- Register for Aging Trim
- RST Input/Output
- 300-Mil, 20-Pin SO Package
- Underwriters Laboratories Recognized
Pin definition
Usage
Here is the guide illustrates how to connect an Arduino to the DS3234 Real-Time Clock Module. The following is a table describing which pins on the Arduino should be connected to the pins on the DS3234 module:
Example code
#include <SPI.h> const int cs=8; //chip select void setup() { Serial.begin(9600); RTC_init(); //day(1-31), month(1-12), year(0-99), hour(0-23), minute(0-59), second(0-59) SetTimeDate(11,12,13,14,15,16); } void loop() { Serial.println(ReadTimeDate()); delay(1000); } //===================================== int RTC_init(){ pinMode(cs,OUTPUT); // chip select
// start the SPI library: SPI.begin(); SPI.setBitOrder(MSBFIRST); SPI.setDataMode(SPI_MODE3); // both mode 1 & 3 should work //set control register digitalWrite(cs, LOW); SPI.transfer(0x8E); SPI.transfer(0x60); //60= disable Osciallator and Battery SQ wave @1hz, temp compensation, Alarms disabled digitalWrite(cs, HIGH); delay(10);
} //===================================== int SetTimeDate(int d, int mo, int y, int h, int mi, int s){
int TimeDate [7]={s,mi,h,0,d,mo,y}; for(int i=0; i<=6;i++){ if(i==3) i++; int b= TimeDate[i]/10; int a= TimeDate[i]-b*10; if(i==2){ if (b==2) b=B00000010; else if (b==1) b=B00000001; } TimeDate[i]= a+(b<<4);
digitalWrite(cs, LOW); SPI.transfer(i+0x80); SPI.transfer(TimeDate[i]); digitalWrite(cs, HIGH);
} } //===================================== String ReadTimeDate(){
String temp; int TimeDate [7]; //second,minute,hour,null,day,month,year for(int i=0; i<=6;i++){ if(i==3) i++; digitalWrite(cs, LOW); SPI.transfer(i+0x00); unsigned int n = SPI.transfer(0x00); digitalWrite(cs, HIGH); int a=n & B00001111; if(i==2){ int b=(n & B00110000)>>4; //24 hour mode if(b==B00000010) b=20; else if(b==B00000001) b=10; TimeDate[i]=a+b; } else if(i==4){ int b=(n & B00110000)>>4; TimeDate[i]=a+b*10; } else if(i==5){ int b=(n & B00010000)>>4; TimeDate[i]=a+b*10; } else if(i==6){ int b=(n & B11110000)>>4; TimeDate[i]=a+b*10; } else{ int b=(n & B01110000)>>4; TimeDate[i]=a+b*10; } } temp.concat(TimeDate[4]); temp.concat("/") ; temp.concat(TimeDate[5]); temp.concat("/") ; temp.concat(TimeDate[6]); temp.concat(" ") ; temp.concat(TimeDate[2]); temp.concat(":") ; temp.concat(TimeDate[1]); temp.concat(":") ; temp.concat(TimeDate[0]);
return(temp); }