un programa que prueba que el DS3231 funciona bien en una FRDMKL25Z
Diff: ds3231.h
- Revision:
- 2:4e6e761c60f2
- Parent:
- 1:c814af60fdbf
- Child:
- 3:312589d8185c
--- a/ds3231.h Wed Nov 19 04:16:33 2014 +0000 +++ b/ds3231.h Thu Nov 20 00:03:27 2014 +0000 @@ -57,9 +57,10 @@ #define I2C_WRITE 0 #define I2C_READ 1 -#define AM_PM (1 << 5) -#define TIME_FORMAT (1 << 6) -#define DY_DT (1 << 6) +#define AM_PM (1 << 5) +#define MODE (1 << 6) +#define DY_DT (1 << 6) +#define ALRM_MASK (1 << 7) //control register bit masks #define A1IE (1 << 0) @@ -69,7 +70,7 @@ #define RS2 (1 << 4) #define CONV (1 << 5) #define BBSQW (1 << 6) -#define EOSC (1 << 7) +#define EOSC (1 << 7) //status register bit masks #define A1F (1 << 0) @@ -108,6 +109,8 @@ uint8_t seconds; uint8_t minutes; uint8_t hours; + bool am_pm; //TRUE for PM, same logic as datasheet + bool mode; //TRUE for 12 hour, same logic as datasheet }ds3231_time_t; @@ -127,6 +130,13 @@ uint8_t hours; uint8_t day; uint8_t date; + bool am1; //not used for alarm 2 + bool am2; + bool am3; + bool am4; + bool am_pm; //TRUE for PM, same logic as datasheet + bool mode; //TRUE for 12 hour, same logic as datasheet + bool dy_dt; //TRUE for Day, same logic as datasheet }ds3231_alrm_t; @@ -144,6 +154,31 @@ { uint8_t w_adrs, r_adrs; + /**********************************************************//** + * Private mmber fx, converts unsigned char to BCD + * + * On Entry: + * @param[in] data - 0-255 + * + * On Exit: + * @return bcd_result = BCD representation of data + * + **************************************************************/ + uint16_t uchar_2_bcd(uint8_t data); + + + /**********************************************************//** + * Private mmber fx, converts BCD to a uint8_t + * + * On Entry: + * @param[in] bcd - 0-99 + * + * On Exit: + * @return rtn_val = integer rep. of BCD + * + **************************************************************/ + uint8_t bcd_2_uchar(uint8_t bcd); + public: /**********************************************************//** * Constructor for Ds3231 Class @@ -168,6 +203,8 @@ /**********************************************************//** * Sets the time on DS3231 + * Struct data is in integrer format, not BCD. Fx will convert + * to BCD for you. * * On Entry: * @param[in] time - struct cotaining time data; @@ -194,6 +231,8 @@ /**********************************************************//** * 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; @@ -221,6 +260,8 @@ /**********************************************************//** * 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 @@ -279,11 +320,12 @@ * Gets the time on DS3231 * * On Entry: - * @param[in] time - struct for storing time data; - * seconds, minutes and hours + * @param[in] time - pointer to struct for storing time + * data; seconds, minutes and hours * * On Exit: - * @param[out] time - contains current rtc time data + * @param[out] time - contains current integrer rtc time + * data * @return return value = 0 on success, non-0 on failure * * Example: @@ -299,18 +341,20 @@ * * @endcode **************************************************************/ - uint16_t get_time(ds3231_time_t time); + uint16_t get_time(ds3231_time_t* time); /**********************************************************//** * Gets the calendar on DS3231 * * On Entry: - * @param[in] calendar - struct for storing calendar data; + * @param[in] calendar - pointer to struct for storing + * calendar data; * day, date, month, year * * On Exit: - * @param[out] calendar - contains current rtc calendar + * @param[out] calendar - contains current integer rtc + * calendar data * @return return value = 0 on success, non-0 on failure * * Example: @@ -327,21 +371,23 @@ * * @endcode **************************************************************/ - uint16_t get_calendar(ds3231_calendar_t calendar); + uint16_t get_calendar(ds3231_calendar_t* calendar); /**********************************************************//** * Get either Alarm1 or Alarm2 of DS3231 * * On Entry: - * @param[in] alarm - struct for storing alarm data + * @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 * * On Exit: - * @param[out] alarm - contains alarm register data + * @param[out] alarm - contains integer alarm data * @return return value = 0 on success, non-0 on failure * * Example: @@ -358,15 +404,15 @@ * * @endcode **************************************************************/ - uint16_t get_alarm(ds3231_alrm_t alarm, bool one_r_two); + uint16_t get_alarm(ds3231_alrm_t* alarm, bool one_r_two); /**********************************************************//** * Get control and status registers of DS3231 * * On Entry: - * @param[in] data - Struct for storing control and status - * register data + * @param[in] data - pointer to struct for storing control + * nd status register data * * On Exit: * @param[out] data - contains control and status registers @@ -386,18 +432,16 @@ * * @endcode **************************************************************/ - uint16_t get_cntl_stat_reg(ds3231_cntl_stat_t data); + uint16_t get_cntl_stat_reg(ds3231_cntl_stat_t* data); /**********************************************************//** * Get temperature data of DS3231 * * On Entry: - * @param[in] temp - Integer for storing temperature data * * On Exit: - * @param[out] temp - contains temperature data - * @return return value = 0 on success, non-0 on failure + * @return return value = raw temperature data * * Example: * @code @@ -405,14 +449,13 @@ * //instantiate rtc object * Ds3231 rtc(D14, D15); * - * //do not use 0xAA, see datasheet for appropriate data * uint16_t temp; * - * rtn_val = rtc.get_temperature(temp); + * temp = rtc.get_temperature(); * * @endcode **************************************************************/ - uint16_t get_temperature(uint16_t temp); + uint16_t get_temperature(void); }; #endif /* DS3231_H*/