DS3231 AT24C32 IIC Clock Module (DS3231SN) [S174] 




https://www.youtube.com/watch?v=hYUx6N5KAhI


*GitHubhttps://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
Posted by RDIoT
|

RTC DS1302 Module (DS1302) [S030]



https://www.youtube.com/watch?v=_TlS8qnRSx8


*GitHubhttps://github.com/rdiot/rdiot-s030.git


* Specs

Color: Green

Material: PCB

Voltage: 2v ~ 5.5v

Length: 43mm

Width: 23mm


* Contents

- Connect

VCC ----- 5V

GND ----- GND

CLK ----- D6

DAT ----- D7

RST ----- D8

 

- Setup Default Value

#define SET_DATE_TIME_JUST_ONCE

  seconds    = 0;

  minutes    = 44;

  hours      = 9;

  dayofweek  = 2;  // Day of week, any day can be first, counts 1...7

  dayofmonth = 2; // Day of month, 1...31

  month      = 2;  // month 1...12

  year       = 2016;



- Key Code

// Set your own pins with these defines !

#define DS1302_SCLK_PIN   6    // Arduino pin for the Serial Clock

#define DS1302_IO_PIN     7    // Arduino pin for the Data I/O

#define DS1302_CE_PIN     8    // Arduino pin for the Chip Enable


#define bcd2bin(h,l)    (((h)*10) + (l))

#define bin2bcd_h(x)   ((x)/10)

#define bin2bcd_l(x)    ((x)%10)


#define DS1302_SECONDS           0x80

#define DS1302_MINUTES           0x82

#define DS1302_HOURS             0x84

#define DS1302_DATE              0x86

#define DS1302_MONTH             0x88

#define DS1302_DAY               0x8A

#define DS1302_YEAR              0x8C

#define DS1302_ENABLE            0x8E

#define DS1302_TRICKLE           0x90

#define DS1302_CLOCK_BURST       0xBE

#define DS1302_CLOCK_BURST_WRITE 0xBE

#define DS1302_CLOCK_BURST_READ  0xBF

#define DS1302_RAMSTART          0xC0

#define DS1302_RAMEND            0xFC

#define DS1302_RAM_BURST         0xFE

#define DS1302_RAM_BURST_WRITE   0xFE

#define DS1302_RAM_BURST_READ    0xFF


#define DS1302_D0 0

#define DS1302_D1 1

#define DS1302_D2 2

#define DS1302_D3 3

#define DS1302_D4 4

#define DS1302_D5 5

#define DS1302_D6 6

#define DS1302_D7 7


// Bit for reading (bit in address)

#define DS1302_READBIT DS1302_D0 // READBIT=1: read instruction


// Bit for clock (0) or ram (1) area, 

// called R/C-bit (bit in address)

#define DS1302_RC DS1302_D6


// Seconds Register

#define DS1302_CH DS1302_D7   // 1 = Clock Halt, 0 = start


// Hour Register

#define DS1302_AM_PM DS1302_D5 // 0 = AM, 1 = PM

#define DS1302_12_24 DS1302_D7 // 0 = 24 hour, 1 = 12 hour


// Enable Register

#define DS1302_WP DS1302_D7   // 1 = Write Protect, 0 = enabled


// Trickle Register

#define DS1302_ROUT0 DS1302_D0

#define DS1302_ROUT1 DS1302_D1

#define DS1302_DS0   DS1302_D2

#define DS1302_DS1   DS1302_D2

#define DS1302_TCS0  DS1302_D4

#define DS1302_TCS1  DS1302_D5

#define DS1302_TCS2  DS1302_D6

#define DS1302_TCS3  DS1302_D7


  ds1302_struct rtc;

  char buffer[80];     // the code uses 70 characters.


  // Read all clock data at once (burst mode).

  DS1302_clock_burst_read( (uint8_t *) &rtc);


  sprintf(buffer, "Date=%d-%d-%d [%d]", \

    2000 + bcd2bin( rtc.Year10, rtc.Year), \

    bcd2bin( rtc.Month10, rtc.Month), \

    rtc.Day, \

    bcd2bin( rtc.Date10, rtc.Date));


  lcd.print(buffer);

'2) Sensor > RTC' 카테고리의 다른 글

DS3231 AT24C32 IIC Clock Module (DS3231SN) [S174]  (0) 2016.09.11
Tiny RTC DS1307 I2C Module (DS1307) [S029]  (0) 2016.09.11
Posted by RDIoT
|

Tiny RTC DS1307 I2C Module (DS1307) [S029]



https://www.youtube.com/watch?v=Ai9vbMClES8


*GitHubhttps://github.com/rdiot/rdiot-s029.git


* Specs

DS1307 I2C real-time clock chip (RTC)

24C32 32K I2C EEPROM memory

The using LIR2032 rechargeable lithium battery with charging circuit

Solve the problem DS1307 with backup battery can not read and write.

Fully charged, it can provide the DS1307 timing 1.

Compact design, 27mm * 28mm * 8.4mm

Leads to the a DS1307 clock pin, to provide the clock signal for the microcontroller.

Other I2C devices can be cascaded


* Contents

- Library : https://github.com/adafruit/RTClib


- Connect

GND - GND

VCC - 5V

SDA - SDA

SCL - SCL


- Key Code

#include <Wire.h> 

#include <LiquidCrystal_I2C.h>

#include "RTClib.h"

 

LiquidCrystal_I2C lcd(0x27,20,4);  // LCD2004

RTC_Millis rtc;

String dt;

String ut;

 

void setup()

{

  lcd.init();  // initialize the lcd 

  lcd.backlight();

  lcd.print("start LCD2004");

  

  rtc.begin(DateTime(F(__DATE__), F(__TIME__)));

 

  delay(1000);

  lcd.clear();

}

 

void loop()

{

 

  lcd.setCursor(0,0);

  lcd.print("S029:DS1307");

 

  DateTime now = rtc.now();

 

  dt = (String)now.year()+"/";

  dt += (String)now.month()+"/";

  dt += (String)now.day()+" ";

  dt += (String)now.hour()+":";

  dt += (String)now.minute()+":";

  dt += (String)now.second();

 

  lcd.setCursor(0,1);

  lcd.print(dt);

 

  ut = (String)now.unixtime();


  lcd.setCursor(0,2);

  lcd.print("unixtime="+ut);

}



'2) Sensor > RTC' 카테고리의 다른 글

DS3231 AT24C32 IIC Clock Module (DS3231SN) [S174]  (0) 2016.09.11
RTC DS1302 Module (DS1302) [S030]  (0) 2016.09.11
Posted by RDIoT
|