Local Library for DS3231 RTC

Fork of ds3231 by Maxim Integrated

Files at this revision

API Documentation at this revision

Comitter:
j3
Date:
Fri Feb 06 05:13:22 2015 +0000
Parent:
9:e57201ee8921
Child:
11:1654fcc0a5ea
Commit message:
Changed date time members to uint32_t to prevent roll over (unless user enters something bigger than 4x10^9++); ; fixed 24 hr mode reporting, & w/0x3F instead of 0x1F (12hr mode)

Changed in this revision

ds3231.cpp Show annotated file Show diff for this revision Revisions of this file
ds3231.h Show annotated file Show diff for this revision Revisions of this file
--- a/ds3231.cpp	Fri Dec 05 22:31:35 2014 +0000
+++ b/ds3231.cpp	Fri Feb 06 05:13:22 2015 +0000
@@ -420,9 +420,17 @@
         
         time->seconds = bcd_2_uchar(data[0]);
         time->minutes = bcd_2_uchar(data[1]);
-        time->hours = bcd_2_uchar((data[2]&0x1F));
         time->am_pm = (data[2]&AM_PM);
         time->mode = (data[2]&MODE);
+        
+        if(time->mode)
+        {
+            time->hours = bcd_2_uchar((data[2]&0x1F));
+        }
+        else
+        {
+            time->hours = bcd_2_uchar((data[2]&0x3F));
+        }  
     } 
   
     return(rtn_val);
@@ -523,11 +531,19 @@
             alarm->am1 = (data[0]&ALRM_MASK);
             alarm->minutes = bcd_2_uchar(data[1]&0x7F);
             alarm->am2 = (data[1]&ALRM_MASK);
-            alarm->hours = bcd_2_uchar(data[2]&0x1F);
             alarm->am3 = (data[2]&ALRM_MASK);
             alarm->am_pm = (data[2]&AM_PM);
             alarm->mode = (data[2]&MODE);
             
+            if(alarm->mode)
+            {
+                alarm->hours = bcd_2_uchar((data[2]&0x1F));
+            }
+            else
+            {
+                alarm->hours = bcd_2_uchar((data[2]&0x3F));
+            }  
+            
             if(data[3] & DY_DT)
             {
                 alarm->dy_dt = 1;
@@ -551,11 +567,19 @@
             
             alarm->minutes = bcd_2_uchar(data[0]&0x7F);
             alarm->am2 = (data[0]&ALRM_MASK);
-            alarm->hours = bcd_2_uchar(data[1]&0x1F);
             alarm->am3 = (data[1]&ALRM_MASK);
             alarm->am_pm = (data[1]&AM_PM);
             alarm->mode = (data[1]&MODE);
             
+            if(alarm->mode)
+            {
+                alarm->hours = bcd_2_uchar((data[2]&0x1F));
+            }
+            else
+            {
+                alarm->hours = bcd_2_uchar((data[2]&0x3F));
+            }  
+            
             if(data[2] & DY_DT)
             {
                 alarm->dy_dt = 1;
--- a/ds3231.h	Fri Dec 05 22:31:35 2014 +0000
+++ b/ds3231.h	Fri Feb 06 05:13:22 2015 +0000
@@ -111,11 +111,11 @@
 * 
 * Members:
 *
-* - uint8_t seconds - Use decimal value. Member fx's convert to BCD
+* - uint32_t seconds - Use decimal value. Member fx's convert to BCD
 *
-* - uint8_t minutes - Use decimal value. Member fx's convert to BCD
+* - uint32_t minutes - Use decimal value. Member fx's convert to BCD
 *
-* - uint8_t hours   - Use decimal value. Member fx's convert to BCD
+* - uint32_t hours   - Use decimal value. Member fx's convert to BCD
 *
 * - bool am_pm      - TRUE for PM, same logic as datasheet
 *
@@ -123,9 +123,9 @@
 */
 typedef struct
 {
-    uint8_t seconds; 
-    uint8_t minutes; 
-    uint8_t hours; 
+    uint32_t seconds; 
+    uint32_t minutes; 
+    uint32_t hours; 
     bool am_pm; 
     bool mode; 
 }ds3231_time_t;
@@ -136,20 +136,20 @@
 * 
 * Members:
 *
-* - uint8_t day   - Use decimal value. Member fx's convert to BCD
+* - uint32_t day   - Use decimal value. Member fx's convert to BCD
 *
-* - uint8_t date  - Use decimal value. Member fx's convert to BCD
+* - uint32_t date  - Use decimal value. Member fx's convert to BCD
 *
-* - uint8_t month - Use decimal value. Member fx's convert to BCD
+* - uint32_t month - Use decimal value. Member fx's convert to BCD
 *
-* - uint8_t year  - Use decimal value. Member fx's convert to BCD
+* - uint32_t year  - Use decimal value. Member fx's convert to BCD
 */
 typedef struct
 {
-    uint8_t day; 
-    uint8_t date; 
-    uint8_t month; 
-    uint8_t year;
+    uint32_t day; 
+    uint32_t date; 
+    uint32_t month; 
+    uint32_t year;
 }ds3231_calendar_t;
 
 
@@ -158,15 +158,15 @@
 * 
 * Members:
 *
-* - uint8_t seconds - Use decimal value. Member fx's convert to BCD 
+* - uint32_t seconds - Use decimal value. Member fx's convert to BCD 
 *
-* - uint8_t minutes - Use decimal value. Member fx's convert to BCD 
+* - uint32_t minutes - Use decimal value. Member fx's convert to BCD 
 *
-* - uint8_t hours   - Use decimal value. Member fx's convert to BCD 
+* - uint32_t hours   - Use decimal value. Member fx's convert to BCD 
 *
-* - uint8_t day     - Use decimal value. Member fx's convert to BCD 
+* - uint32_t day     - Use decimal value. Member fx's convert to BCD 
 *
-* - uint8_t date    - Use decimal value. Member fx's convert to BCD 
+* - uint32_t date    - Use decimal value. Member fx's convert to BCD 
 *
 * - bool am1        - Flag for setting alarm rate
 *
@@ -185,11 +185,11 @@
 typedef struct
 {
     //Seconds and am1 not used for alarm2
-    uint8_t seconds; 
-    uint8_t minutes; 
-    uint8_t hours; 
-    uint8_t day; 
-    uint8_t date; 
+    uint32_t seconds; 
+    uint32_t minutes; 
+    uint32_t hours; 
+    uint32_t day; 
+    uint32_t date; 
     bool am1; 
     bool am2;
     bool am3;