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

Files at this revision

API Documentation at this revision

Comitter:
j3
Date:
Wed Nov 19 04:16:33 2014 +0000
Parent:
0:b00c4699ae6f
Child:
2:4e6e761c60f2
Commit message:
inherited I2C

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	Tue Nov 18 22:28:04 2014 +0000
+++ b/ds3231.cpp	Wed Nov 19 04:16:33 2014 +0000
@@ -53,7 +53,8 @@
 * Constructor for Ds3231 Class
 *
 * On Entry:
-*     @param[in] p_i2c - pointer to I2C object for bus
+*     @param[in] sda - sda pin of I2C bus
+*     @param[in] scl - scl pin of I2C bus
 *
 * On Exit:
 *    @return none
@@ -61,17 +62,13 @@
 * Example:
 * @code
 * 
-* I2C i2c_bus(D14, D15); //instantiate I2C bus
-* I2C * p_i2c_bus = &i2c_bus; //create pointer to bus
-* 
 * //instantiate rtc object
-* Ds3231 rtc(p_i2c_bus); 
+* Ds3231 rtc(D14, D15); 
 *
 * @endcode
 **************************************************************/
-Ds3231::Ds3231(I2C* ptr_i2c_bus)
+Ds3231::Ds3231(PinName sda, PinName scl) : I2C(sda, scl)
 {
-    p_i2c = ptr_i2c_bus;
     w_adrs = ((DS3231_I2C_ADRS << 1) | I2C_WRITE);
     r_adrs = ((DS3231_I2C_ADRS << 1) | I2C_READ);
 }
@@ -90,11 +87,8 @@
 * Example:
 * @code
 * 
-* I2C i2c_bus(D14, D15); //instantiate I2C bus
-* I2C * p_i2c_bus = &i2c_bus; //create pointer to bus
-* 
 * //instantiate rtc object
-* Ds3231 rtc(p_i2c_bus); 
+* Ds3231 rtc(D14, D15); 
 * 
 * ds3231_time_t time = {0, 0, 0} // time = 0:0:0 24hr format
 * uint16_t rtn_val;
@@ -123,11 +117,8 @@
 * Example:
 * @code
 * 
-* I2C i2c_bus(D14, D15); //instantiate I2C bus
-* I2C * p_i2c_bus = &i2c_bus; //create pointer to bus
-* 
 * //instantiate rtc object
-* Ds3231 rtc(p_i2c_bus); 
+* Ds3231 rtc(D14, D15); 
 * 
 * //see datasheet for calendar format
 * ds3231_calendar_t calendar = {1, 1, 1, 0}; 
@@ -160,11 +151,8 @@
 * Example:
 * @code
 * 
-* I2C i2c_bus(D14, D15); //instantiate I2C bus
-* I2C * p_i2c_bus = &i2c_bus; //create pointer to bus
-* 
 * //instantiate rtc object
-* Ds3231 rtc(p_i2c_bus); 
+* Ds3231 rtc(D14, D15); 
 * 
 * //see datasheet for alarm format
 * ds3231_alrm_t alarm = {0, 0, 0, 0, 0}; 
@@ -194,11 +182,8 @@
 * Example:
 * @code
 * 
-* I2C i2c_bus(D14, D15); //instantiate I2C bus
-* I2C * p_i2c_bus = &i2c_bus; //create pointer to bus
-* 
 * //instantiate rtc object
-* Ds3231 rtc(p_i2c_bus); 
+* Ds3231 rtc(D14, D15);  
 * 
 * //do not use 0xAA, see datasheet for appropriate data 
 * ds3231_cntl_stat_t data = {0xAA, 0xAA}; 
@@ -228,11 +213,8 @@
 * Example:
 * @code
 * 
-* I2C i2c_bus(D14, D15); //instantiate I2C bus
-* I2C * p_i2c_bus = &i2c_bus; //create pointer to bus
-* 
 * //instantiate rtc object
-* Ds3231 rtc(p_i2c_bus); 
+* Ds3231 rtc(D14, D15); 
 * 
 * ds3231_time_t time = {0, 0, 0} // time = 0:0:0 24hr format
 * uint16_t rtn_val;
@@ -262,11 +244,8 @@
 * Example:
 * @code
 * 
-* I2C i2c_bus(D14, D15); //instantiate I2C bus
-* I2C * p_i2c_bus = &i2c_bus; //create pointer to bus
-* 
 * //instantiate rtc object
-* Ds3231 rtc(p_i2c_bus); 
+* Ds3231 rtc(D14, D15); 
 * 
 * //see datasheet for calendar format
 * ds3231_calendar_t calendar = {1, 1, 1, 0}; 
@@ -300,11 +279,8 @@
 * Example:
 * @code
 * 
-* I2C i2c_bus(D14, D15); //instantiate I2C bus
-* I2C * p_i2c_bus = &i2c_bus; //create pointer to bus
-* 
 * //instantiate rtc object
-* Ds3231 rtc(p_i2c_bus); 
+* Ds3231 rtc(D14, D15); 
 * 
 * //see datasheet for alarm format
 * ds3231_alrm_t alarm = {0, 0, 0, 0, 0}; 
@@ -336,11 +312,8 @@
 * Example:
 * @code
 * 
-* I2C i2c_bus(D14, D15); //instantiate I2C bus
-* I2C * p_i2c_bus = &i2c_bus; //create pointer to bus
-* 
 * //instantiate rtc object
-* Ds3231 rtc(p_i2c_bus); 
+* Ds3231 rtc(D14, D15);  
 * 
 * //do not use 0xAA, see datasheet for appropriate data 
 * ds3231_cntl_stat_t data = {0xAA, 0xAA}; 
@@ -369,16 +342,13 @@
 * Example:
 * @code
 * 
-* I2C i2c_bus(D14, D15); //instantiate I2C bus
-* I2C * p_i2c_bus = &i2c_bus; //create pointer to bus
-* 
 * //instantiate rtc object
-* Ds3231 rtc(p_i2c_bus); 
+* Ds3231 rtc(D14, D15); 
 * 
 * //do not use 0xAA, see datasheet for appropriate data 
 * uint16_t temp; 
 *
-* rtn_val = rtc.get_temperature(data);
+* rtn_val = rtc.get_temperature(temp);
 *
 * @endcode
 **************************************************************/
--- a/ds3231.h	Tue Nov 18 22:28:04 2014 +0000
+++ b/ds3231.h	Wed Nov 19 04:16:33 2014 +0000
@@ -140,10 +140,8 @@
 /******************************************************************//**
 * Ds3231 Class
 **********************************************************************/
-class Ds3231
+class Ds3231 : public I2C
 {
-    //private members
-    I2C* p_i2c;
     uint8_t w_adrs, r_adrs;
     
     public:
@@ -151,7 +149,8 @@
         * Constructor for Ds3231 Class
         *
         * On Entry:
-        *     @param[in] p_i2c - pointer to I2C object for bus
+        *     @param[in] sda - sda pin of I2C bus
+        *     @param[in] scl - scl pin of I2C bus
         *
         * On Exit:
         *    @return none
@@ -159,15 +158,12 @@
         * Example:
         * @code
         * 
-        * I2C i2c_bus(D14, D15); //instantiate I2C bus
-        * I2C * p_i2c_bus = &i2c_bus; //create pointer to bus
-        * 
         * //instantiate rtc object
-        * Ds3231 rtc(p_i2c_bus); 
+        * Ds3231 rtc(D14, D15); 
         *
         * @endcode
         **************************************************************/
-        Ds3231(I2C* ptr_i2c_bus);
+        Ds3231(PinName sda, PinName scl);
         
         
         /**********************************************************//**
@@ -183,11 +179,8 @@
         * Example:
         * @code
         * 
-        * I2C i2c_bus(D14, D15); //instantiate I2C bus
-        * I2C * p_i2c_bus = &i2c_bus; //create pointer to bus
-        * 
         * //instantiate rtc object
-        * Ds3231 rtc(p_i2c_bus); 
+        * Ds3231 rtc(D14, D15); 
         * 
         * ds3231_time_t time = {0, 0, 0} // time = 0:0:0 24hr format
         * uint16_t rtn_val;
@@ -212,11 +205,8 @@
         * Example:
         * @code
         * 
-        * I2C i2c_bus(D14, D15); //instantiate I2C bus
-        * I2C * p_i2c_bus = &i2c_bus; //create pointer to bus
-        * 
         * //instantiate rtc object
-        * Ds3231 rtc(p_i2c_bus); 
+        * Ds3231 rtc(D14, D15); 
         * 
         * //see datasheet for calendar format
         * ds3231_calendar_t calendar = {1, 1, 1, 0}; 
@@ -245,11 +235,8 @@
         * Example:
         * @code
         * 
-        * I2C i2c_bus(D14, D15); //instantiate I2C bus
-        * I2C * p_i2c_bus = &i2c_bus; //create pointer to bus
-        * 
         * //instantiate rtc object
-        * Ds3231 rtc(p_i2c_bus); 
+        * Ds3231 rtc(D14, D15); 
         * 
         * //see datasheet for alarm format
         * ds3231_alrm_t alarm = {0, 0, 0, 0, 0}; 
@@ -275,11 +262,8 @@
         * Example:
         * @code
         * 
-        * I2C i2c_bus(D14, D15); //instantiate I2C bus
-        * I2C * p_i2c_bus = &i2c_bus; //create pointer to bus
-        * 
         * //instantiate rtc object
-        * Ds3231 rtc(p_i2c_bus); 
+        * Ds3231 rtc(D14, D15);  
         * 
         * //do not use 0xAA, see datasheet for appropriate data 
         * ds3231_cntl_stat_t data = {0xAA, 0xAA}; 
@@ -305,11 +289,8 @@
         * Example:
         * @code
         * 
-        * I2C i2c_bus(D14, D15); //instantiate I2C bus
-        * I2C * p_i2c_bus = &i2c_bus; //create pointer to bus
-        * 
         * //instantiate rtc object
-        * Ds3231 rtc(p_i2c_bus); 
+        * Ds3231 rtc(D14, D15); 
         * 
         * ds3231_time_t time = {0, 0, 0} // time = 0:0:0 24hr format
         * uint16_t rtn_val;
@@ -335,11 +316,8 @@
         * Example:
         * @code
         * 
-        * I2C i2c_bus(D14, D15); //instantiate I2C bus
-        * I2C * p_i2c_bus = &i2c_bus; //create pointer to bus
-        * 
         * //instantiate rtc object
-        * Ds3231 rtc(p_i2c_bus); 
+        * Ds3231 rtc(D14, D15); 
         * 
         * //see datasheet for calendar format
         * ds3231_calendar_t calendar = {1, 1, 1, 0}; 
@@ -369,11 +347,8 @@
         * Example:
         * @code
         * 
-        * I2C i2c_bus(D14, D15); //instantiate I2C bus
-        * I2C * p_i2c_bus = &i2c_bus; //create pointer to bus
-        * 
         * //instantiate rtc object
-        * Ds3231 rtc(p_i2c_bus); 
+        * Ds3231 rtc(D14, D15); 
         * 
         * //see datasheet for alarm format
         * ds3231_alrm_t alarm = {0, 0, 0, 0, 0}; 
@@ -401,11 +376,8 @@
         * Example:
         * @code
         * 
-        * I2C i2c_bus(D14, D15); //instantiate I2C bus
-        * I2C * p_i2c_bus = &i2c_bus; //create pointer to bus
-        * 
         * //instantiate rtc object
-        * Ds3231 rtc(p_i2c_bus); 
+        * Ds3231 rtc(D14, D15);  
         * 
         * //do not use 0xAA, see datasheet for appropriate data 
         * ds3231_cntl_stat_t data = {0xAA, 0xAA}; 
@@ -430,16 +402,13 @@
         * Example:
         * @code
         * 
-        * I2C i2c_bus(D14, D15); //instantiate I2C bus
-        * I2C * p_i2c_bus = &i2c_bus; //create pointer to bus
-        * 
         * //instantiate rtc object
-        * Ds3231 rtc(p_i2c_bus); 
+        * Ds3231 rtc(D14, D15); 
         * 
         * //do not use 0xAA, see datasheet for appropriate data 
         * uint16_t temp; 
         *
-        * rtn_val = rtc.get_temperature(data);
+        * rtn_val = rtc.get_temperature(temp);
         *
         * @endcode
         **************************************************************/