Library for DS3231 RTC

Dependents:   ard2pmod DS3231demo DS3231demo_COM_Port_Output MAXREFDES99_RTC_Display ... more

DS3231 Component Page

Revision:
3:312589d8185c
Parent:
2:4e6e761c60f2
Child:
4:0beb5e9ac927
--- a/ds3231.h	Thu Nov 20 00:03:27 2014 +0000
+++ b/ds3231.h	Thu Nov 20 21:06:57 2014 +0000
@@ -53,7 +53,8 @@
 #include "mbed.h"
 
 
-#define DS3231_I2C_ADRS 0x68 //7bit, shift left 1 and 'OR' with R/W bit
+//7 bit I2C slave address and R/W bits
+#define DS3231_I2C_ADRS 0x68 
 #define I2C_WRITE 0
 #define I2C_READ  1
 
@@ -80,6 +81,7 @@
 #define OSF     (1 << 7)
 
 
+//enumerated registers 
 typedef enum
 {
     SECONDS,
@@ -104,33 +106,37 @@
 }ds3231_regs_t;
 
 
+//Time data
 typedef struct
 {
-    uint8_t seconds;
-    uint8_t minutes;
-    uint8_t hours;
+    uint8_t seconds; //Use decimal value. Member fx's convert to BCD
+    uint8_t minutes; //Use decimal value. Member fx's convert to BCD
+    uint8_t hours; //Use decimal value. Member fx's convert to BCD
     bool am_pm; //TRUE for PM, same logic as datasheet
     bool mode; //TRUE for 12 hour, same logic as datasheet
 }ds3231_time_t;
 
 
+//Calendar data
 typedef struct
 {
-    uint8_t day;
-    uint8_t date;
-    uint8_t month;
-    uint8_t year;
+    uint8_t day; //Use decimal value. Member fx's convert to BCD
+    uint8_t date; //Use decimal value. Member fx's convert to BCD
+    uint8_t month; //Use decimal value. Member fx's convert to BCD
+    uint8_t year; //Use decimal value. Member fx's convert to BCD
 }ds3231_calendar_t;
 
 
+//Alarm data
 typedef struct
 {
-    uint8_t seconds; //not used for alarm2
-    uint8_t minutes;
-    uint8_t hours;
-    uint8_t day;
-    uint8_t date;
-    bool am1; //not used for alarm 2
+    //Seconds and am1 not used for alarm2
+    uint8_t seconds; //Use decimal value. Member fx's convert to BCD 
+    uint8_t minutes; //Use decimal value. Member fx's convert to BCD
+    uint8_t hours; //Use decimal value. Member fx's convert to BCD
+    uint8_t day; //Use decimal value. Member fx's convert to BCD
+    uint8_t date; //Use decimal value. Member fx's convert to BCD
+    bool am1; 
     bool am2;
     bool am3;
     bool am4;
@@ -142,8 +148,8 @@
 
 typedef struct
 {
-    uint8_t control;
-    uint8_t status;
+    uint8_t control; //binary data
+    uint8_t status; //binary data
 }ds3231_cntl_stat_t;
 
     
@@ -231,12 +237,9 @@
         
         /**********************************************************//**
         * Sets the calendar on DS3231
-        * Struct data is in integrer format, not BCD.  Fx will convert
-        * to BCD for you.
         *
         * On Entry:
-        *     @param[in] calendar - struct cotaining calendar data; 
-        *                           day, date, month, year
+        *     @param[in] calendar - struct cotaining calendar data 
         *
         * On Exit:
         *     @return return value = 0 on success, non-0 on failure
@@ -260,13 +263,10 @@
         
         /**********************************************************//**
         * Set either Alarm1 or Alarm2 of DS3231
-        * Struct data is in integrer format, not BCD.  Fx will convert
-        * to BCD for you.
         *
         * On Entry:
         *     @param[in] alarm - struct cotaining alarm data 
-        *                        seconds, minutes, hours, day, date
-        *                        seconds used on Alarm1 only
+        *                        
         *     @param[in] one_r_two - TRUE for Alarm1 and FALSE for 
         *                            Alarm2
         *
@@ -337,7 +337,7 @@
         * ds3231_time_t time = {0, 0, 0} // time = 0:0:0 24hr format
         * uint16_t rtn_val;
         *
-        * rtn_val = rtc.get_time(time);
+        * rtn_val = rtc.get_time(&time);
         *
         * @endcode
         **************************************************************/
@@ -367,7 +367,7 @@
         * ds3231_calendar_t calendar = {1, 1, 1, 0}; 
         * uint16_t rtn_val;
         *
-        * rtn_val = rtc.get_calendar(calendar);
+        * rtn_val = rtc.get_calendar(&calendar);
         *
         * @endcode
         **************************************************************/
@@ -400,7 +400,7 @@
         * ds3231_alrm_t alarm = {0, 0, 0, 0, 0}; 
         * uint16_t rtn_val;
         *
-        * rtn_val = rtc.get_alarm(alarm, FALSE);
+        * rtn_val = rtc.get_alarm(&alarm, FALSE);
         *
         * @endcode
         **************************************************************/
@@ -428,7 +428,7 @@
         * //do not use 0xAA, see datasheet for appropriate data 
         * ds3231_cntl_stat_t data = {0xAA, 0xAA}; 
         *
-        * rtn_val = rtc.get_cntl_stat_reg(data);
+        * rtn_val = rtc.get_cntl_stat_reg(&data);
         *
         * @endcode
         **************************************************************/