un programa que prueba que el DS3231 funciona bien en una FRDMKL25Z

Files at this revision

API Documentation at this revision

Comitter:
j3
Date:
Thu Nov 20 22:16:15 2014 +0000
Parent:
3:312589d8185c
Child:
5:61dfe2690360
Commit message:
added support for bool data types in get_time and get_alarm.; fixed some comments too.

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	Thu Nov 20 21:06:57 2014 +0000
+++ b/ds3231.cpp	Thu Nov 20 22:16:15 2014 +0000
@@ -91,7 +91,8 @@
 * //instantiate rtc object
 * Ds3231 rtc(D14, D15); 
 * 
-* ds3231_time_t time = {0, 0, 0} // time = 0:0:0 24hr format
+* //time = 12:00:00 AM 12hr mode
+* ds3231_time_t time = {12, 0, 0, 0, 1}
 * uint16_t rtn_val;
 *
 * rtn_val = rtc.set_time(time);
@@ -196,8 +197,8 @@
 * //instantiate rtc object
 * Ds3231 rtc(D14, D15); 
 * 
-* //see datasheet for alarm format
-* ds3231_alrm_t alarm = {0, 0, 0, 0, 0}; 
+* //see ds3231.h for .members and datasheet for alarm format
+* ds3231_alrm_t alarm; 
 * uint16_t rtn_val;
 *
 * rtn_val = rtc.set_alarm(alarm, FALSE);
@@ -372,8 +373,7 @@
 * Gets the time on DS3231
 *
 * On Entry:
-*     @param[in] time - pointer to struct for storing time 
-*                       data; seconds, minutes and hours
+*     @param[in] time - pointer to struct for storing time data
 *
 * On Exit:
 *     @param[out] time - contains current integrer rtc time 
@@ -386,7 +386,8 @@
 * //instantiate rtc object
 * Ds3231 rtc(D14, D15); 
 * 
-* ds3231_time_t time = {0, 0, 0} // time = 0:0:0 24hr format
+* //time = 12:00:00 AM 12hr mode
+* ds3231_time_t time = {12, 0, 0, 0, 1} 
 * uint16_t rtn_val;
 *
 * rtn_val = rtc.get_time(&time);
@@ -408,6 +409,8 @@
         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);
     } 
   
     return(rtn_val);
@@ -419,8 +422,7 @@
 *
 * On Entry:
 *     @param[in] calendar - pointer to struct for storing 
-*                           calendar data; 
-*                           day, date, month, year
+*                           calendar data
 *
 * On Exit:
 *     @param[out] calendar - contains current integer rtc 
@@ -469,8 +471,6 @@
 * On Entry:
 *     @param[in] alarm - pointer to struct for storing alarm 
 *                        data; 
-*                        seconds, minutes, hours, day, date
-*                        seconds used on Alarm1 only
 *
 *     @param[in] one_r_two - TRUE for Alarm1 and FALSE for 
 *                            Alarm2
@@ -485,8 +485,8 @@
 * //instantiate rtc object
 * Ds3231 rtc(D14, D15); 
 * 
-* //see datasheet for alarm format
-* ds3231_alrm_t alarm = {0, 0, 0, 0, 0}; 
+* //see ds3231.h for .members and datasheet for alarm format
+* ds3231_alrm_t alarm; 
 * uint16_t rtn_val;
 *
 * rtn_val = rtc.get_alarm(&alarm, FALSE);
@@ -508,17 +508,24 @@
             rtn_val = read(r_adrs,(char *) data, 4);
             
             alarm->seconds = bcd_2_uchar(data[0]&0x7F);
+            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(data[3] & DY_DT)
             {
+                alarm->dy_dt = 1;
                 alarm->day = bcd_2_uchar(data[3]&0x0F);
             }
             else
             {
                 alarm->date = bcd_2_uchar(data[3]&0x3F);
             }
+            alarm->am4 = (data[3]&ALRM_MASK);
         } 
     }
     else
@@ -531,16 +538,22 @@
             rtn_val = read(r_adrs,(char *) data, 4);
             
             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(data[3] & DY_DT)
+            if(data[2] & DY_DT)
             {
+                alarm->dy_dt = 1;
                 alarm->day = bcd_2_uchar(data[2]&0x0F);
             }
             else
             {
                 alarm->date = bcd_2_uchar(data[2]&0x3F);
             }
+            alarm->am4 = (data[2]&ALRM_MASK);
         } 
     }
     
@@ -553,7 +566,7 @@
 *
 * On Entry:
 *     @param[in] data - pointer to struct for storing control 
-*                       nd status register data
+*                       and status register data
 *
 * On Exit:
 *     @param[out] data - contains control and status registers
--- a/ds3231.h	Thu Nov 20 21:06:57 2014 +0000
+++ b/ds3231.h	Thu Nov 20 22:16:15 2014 +0000
@@ -214,7 +214,6 @@
         *
         * On Entry:
         *     @param[in] time - struct cotaining time data; 
-        *                       seconds, minutes and hours
         *
         * On Exit:
         *     @return return value = 0 on success, non-0 on failure
@@ -225,7 +224,8 @@
         * //instantiate rtc object
         * Ds3231 rtc(D14, D15); 
         * 
-        * ds3231_time_t time = {0, 0, 0} // time = 0:0:0 24hr format
+        * //time = 12:00:00 AM 12hr mode
+        * ds3231_time_t time = {12, 0, 0, 0, 1}
         * uint16_t rtn_val;
         *
         * rtn_val = rtc.set_time(time);
@@ -279,8 +279,8 @@
         * //instantiate rtc object
         * Ds3231 rtc(D14, D15); 
         * 
-        * //see datasheet for alarm format
-        * ds3231_alrm_t alarm = {0, 0, 0, 0, 0}; 
+        * //see ds3231.h for .members and datasheet for alarm format
+        * ds3231_alrm_t alarm; 
         * uint16_t rtn_val;
         *
         * rtn_val = rtc.set_alarm(alarm, FALSE);
@@ -320,8 +320,7 @@
         * Gets the time on DS3231
         *
         * On Entry:
-        *     @param[in] time - pointer to struct for storing time 
-        *                       data; seconds, minutes and hours
+        *     @param[in] time - pointer to struct for storing time data
         *
         * On Exit:
         *     @param[out] time - contains current integrer rtc time 
@@ -334,7 +333,8 @@
         * //instantiate rtc object
         * Ds3231 rtc(D14, D15); 
         * 
-        * ds3231_time_t time = {0, 0, 0} // time = 0:0:0 24hr format
+        * //time = 12:00:00 AM 12hr mode
+        * ds3231_time_t time = {12, 0, 0, 0, 1} 
         * uint16_t rtn_val;
         *
         * rtn_val = rtc.get_time(&time);
@@ -349,8 +349,7 @@
         *
         * On Entry:
         *     @param[in] calendar - pointer to struct for storing 
-        *                           calendar data; 
-        *                           day, date, month, year
+        *                           calendar data
         *
         * On Exit:
         *     @param[out] calendar - contains current integer rtc 
@@ -380,8 +379,6 @@
         * On Entry:
         *     @param[in] alarm - pointer to struct for storing alarm 
         *                        data; 
-        *                        seconds, minutes, hours, day, date
-        *                        seconds used on Alarm1 only
         *
         *     @param[in] one_r_two - TRUE for Alarm1 and FALSE for 
         *                            Alarm2
@@ -396,8 +393,8 @@
         * //instantiate rtc object
         * Ds3231 rtc(D14, D15); 
         * 
-        * //see datasheet for alarm format
-        * ds3231_alrm_t alarm = {0, 0, 0, 0, 0}; 
+        * //see ds3231.h for .members and datasheet for alarm format
+        * ds3231_alrm_t alarm; 
         * uint16_t rtn_val;
         *
         * rtn_val = rtc.get_alarm(&alarm, FALSE);
@@ -412,7 +409,7 @@
         *
         * On Entry:
         *     @param[in] data - pointer to struct for storing control 
-        *                       nd status register data
+        *                       and status register data
         *
         * On Exit:
         *     @param[out] data - contains control and status registers