DS3231 AT24C32 IIC Clock Module (DS3231SN) [S174]
https://www.youtube.com/watch?v=hYUx6N5KAhI
*GitHub : https://github.com/rdiot/rdiot-s174.git
* Specs
Overview
DS3231 is a low cost and extremely accurate I2C real-time clock, with an integrated crystal and temperature-compensated crystal oscillator (TCXO). DS3231 can be operated using supply voltages ranging from 2.3 V to 5.5 V and it also features battery backup capabilities.
The DS3231 features an integrated crystal, 2 programmable time-of-day alarms, a temperature sensor, and 32.768 kHz signal output pin.
The AT24C32 EEPROM is a 32K EEPROM that can be used to add non-volatile data storage to your electronic projects and prototypes.
The module also features a battery holder, allowing you to add a backup battery to ensure continuous operation.
Features
Can be connected directly to the microcontroller IO ports
Standard 2.54 mm pins for input and output connections
Two calendars and alarm clock
Two programmable square-wave outputs
Real time clock generator for seconds, minutes, hours, day, date, month, and year timing
Valid until 2100 with leap year compensation
Can be cascaded with other I2C devices
The address can be set using the pins A0/A1/A2 (the default address is 0x57)
Battery socket compatible with LIR2032 batteries
I2C interface
Specifications
Operating voltage: 3.3 V to 5.5 V
Real-time clock chip: DS3231
Clock accuracy: 2 ppm
Memory chip: AT24C32 (32 Kb storage capacity)
On-chip temperature sensor with an accuracy of ±3 ℃
I2C bus interface maximum speed: 400 kHz
Size: 38 x 22 x 14 mm
* Contents
- DataSheet : http://datasheets.maximintegrated.com/en/ds/DS3231.pdf
- Library : https://github.com/kriswiner/DS3231RTC
- Connect
DS3231 Breakout --------- Arduino
3.3V --------------------- 3.3V
SDA ----------------------- A4
SCL ----------------------- A5
GND ---------------------- GND
- Key Code
// If device is not busy, read time, date, and temperature
byte c = readByte(DS3231_ADDRESS, STATUS) & 0x04;
if(!c) { // if device not busy
// These interrupts require constant polling of the STATUS register which takes a lot of time,
// which the microcontroller might not be able to spare. If the micrcontroller has a lot of other things to do
// or we want to save power by only waking up the microcontroller when something requires its attention, use the
// hardware interrupt routine alarmChange().
c = readByte(DS3231_ADDRESS, STATUS); // Read STATUS register of DS3231 RTC
if(c & 0x01) { // If Alarm1 flag set, take some action
digitalWrite(outPin1, HIGH); // Turn on extenal LED
// play song1
for (uint8_t entry = 0; entry < 32; entry++) {
uint8_t data = readEEPROM(AT24C32_ADDRESS, 1, entry);
tone(outPin2, data, 50); delay(50);
}
noTone(outPin2); // End song1
digitalWrite(outPin1, LOW); // Turn off external LED
writeByte(DS3231_ADDRESS, STATUS, c & ~0x01); // clear Alarm 1 flag if already set
}
if(c & 0x02) { // If Alarm 2 flag set, take some action
digitalWrite(outPin1, HIGH); // Turn on extenal LED
// play song1
for (uint8_t entry = 0; entry < 32; entry++) {
uint8_t data = readEEPROM(AT24C32_ADDRESS, 1, entry);
tone(outPin2, data, 50); delay(50);
}
noTone(outPin2); // End song1
digitalWrite(outPin1, LOW); // Turn off extenal LED
writeByte(DS3231_ADDRESS, STATUS, c & ~0x02); // clear Alarm 2 flag if already set
}
// get time
seconds = readSeconds();
minutes = readMinutes();
hours = readHours();
PM = readPM();
day = readDay();
date = readDate();
month = readMonth();
year = readYear();
century = readCentury();
// get temperature
temperature = readTempData(); // Read the temperature
}
// Serial print and/or display at 0.5 s rate independent of data rates
delt_t = millis() - count;
if (delt_t > 300) { // update LCD once per half-second independent of read rate
digitalWrite(blinkPin, blinkOn);
display.clearDisplay();
display.setCursor(0, 0); display.print("DS3231 RTC");
display.setCursor(0, 10);
if(hours < 10) {display.print("0"); display.print(hours);} else display.print(hours);
display.print(":");
if(minutes < 10) {display.print("0"); display.print(minutes);} else display.print(minutes);
display.print(":");
if(seconds < 10) {display.print("0"); display.print(seconds);} else display.print(seconds);
if(PM) display.print(" PM"); else display.print(" AM");
display.setCursor(0, 20); display.print(month); display.print("/"); display.print(date); display.print("/20"); display.print(year);
display.setCursor(0, 30);
if(day == 1) display.print("Monday");
if(day == 2) display.print("Tuesday");
if(day == 3) display.print("Wednesday");
if(day == 4) display.print("Thursday");
if(day == 5) display.print("Friday");
if(day == 6) display.print("Saturday");
if(day == 7) display.print("Sunday");
display.setCursor(0, 40); display.print("T = "); display.print(temperature, 2); display.print(" C");
display.display();
blinkOn = ~blinkOn;
count = millis();
}
'2) Sensor > RTC' 카테고리의 다른 글
RTC DS1302 Module (DS1302) [S030] (0) | 2016.09.11 |
---|---|
Tiny RTC DS1307 I2C Module (DS1307) [S029] (0) | 2016.09.11 |