un programa que prueba que el DS3231 funciona bien en una FRDMKL25Z
ds3231.h@5:61dfe2690360, 2014-11-28 (annotated)
- Committer:
- j3
- Date:
- Fri Nov 28 02:36:26 2014 +0000
- Revision:
- 5:61dfe2690360
- Parent:
- 4:0beb5e9ac927
- Child:
- 8:c7484a65fcea
added get_epoch fx to support other libraries that use epoch time
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
j3 | 0:b00c4699ae6f | 1 | /******************************************************************//** |
j3 | 0:b00c4699ae6f | 2 | * @file ds3231.h |
j3 | 0:b00c4699ae6f | 3 | * |
j3 | 0:b00c4699ae6f | 4 | * @author Justin Jordan |
j3 | 0:b00c4699ae6f | 5 | * |
j3 | 0:b00c4699ae6f | 6 | * @version 0.0 |
j3 | 0:b00c4699ae6f | 7 | * |
j3 | 0:b00c4699ae6f | 8 | * Started: 11NOV14 |
j3 | 0:b00c4699ae6f | 9 | * |
j3 | 0:b00c4699ae6f | 10 | * Updated: |
j3 | 0:b00c4699ae6f | 11 | * |
j3 | 0:b00c4699ae6f | 12 | * @brief Header file for DS3231 class |
j3 | 0:b00c4699ae6f | 13 | * |
j3 | 0:b00c4699ae6f | 14 | *********************************************************************** |
j3 | 0:b00c4699ae6f | 15 | * |
j3 | 0:b00c4699ae6f | 16 | * @copyright |
j3 | 0:b00c4699ae6f | 17 | * Copyright (C) 2013 Maxim Integrated Products, Inc., All Rights Reserved. |
j3 | 0:b00c4699ae6f | 18 | * |
j3 | 0:b00c4699ae6f | 19 | * Permission is hereby granted, free of charge, to any person obtaining a |
j3 | 0:b00c4699ae6f | 20 | * copy of this software and associated documentation files (the "Software"), |
j3 | 0:b00c4699ae6f | 21 | * to deal in the Software without restriction, including without limitation |
j3 | 0:b00c4699ae6f | 22 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
j3 | 0:b00c4699ae6f | 23 | * and/or sell copies of the Software, and to permit persons to whom the |
j3 | 0:b00c4699ae6f | 24 | * Software is furnished to do so, subject to the following conditions: |
j3 | 0:b00c4699ae6f | 25 | * |
j3 | 0:b00c4699ae6f | 26 | * The above copyright notice and this permission notice shall be included |
j3 | 0:b00c4699ae6f | 27 | * in all copies or substantial portions of the Software. |
j3 | 0:b00c4699ae6f | 28 | * |
j3 | 0:b00c4699ae6f | 29 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
j3 | 0:b00c4699ae6f | 30 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
j3 | 0:b00c4699ae6f | 31 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
j3 | 0:b00c4699ae6f | 32 | * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES |
j3 | 0:b00c4699ae6f | 33 | * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
j3 | 0:b00c4699ae6f | 34 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
j3 | 0:b00c4699ae6f | 35 | * OTHER DEALINGS IN THE SOFTWARE. |
j3 | 0:b00c4699ae6f | 36 | * |
j3 | 0:b00c4699ae6f | 37 | * Except as contained in this notice, the name of Maxim Integrated |
j3 | 0:b00c4699ae6f | 38 | * Products, Inc. shall not be used except as stated in the Maxim Integrated |
j3 | 0:b00c4699ae6f | 39 | * Products, Inc. Branding Policy. |
j3 | 0:b00c4699ae6f | 40 | * |
j3 | 0:b00c4699ae6f | 41 | * The mere transfer of this software does not imply any licenses |
j3 | 0:b00c4699ae6f | 42 | * of trade secrets, proprietary technology, copyrights, patents, |
j3 | 0:b00c4699ae6f | 43 | * trademarks, maskwork rights, or any other form of intellectual |
j3 | 0:b00c4699ae6f | 44 | * property whatsoever. Maxim Integrated Products, Inc. retains all |
j3 | 0:b00c4699ae6f | 45 | * ownership rights. |
j3 | 0:b00c4699ae6f | 46 | **********************************************************************/ |
j3 | 0:b00c4699ae6f | 47 | |
j3 | 0:b00c4699ae6f | 48 | |
j3 | 0:b00c4699ae6f | 49 | #ifndef DS3231_H |
j3 | 0:b00c4699ae6f | 50 | #define DS3231_H |
j3 | 0:b00c4699ae6f | 51 | |
j3 | 0:b00c4699ae6f | 52 | |
j3 | 0:b00c4699ae6f | 53 | #include "mbed.h" |
j3 | 0:b00c4699ae6f | 54 | |
j3 | 0:b00c4699ae6f | 55 | |
j3 | 3:312589d8185c | 56 | //7 bit I2C slave address and R/W bits |
j3 | 3:312589d8185c | 57 | #define DS3231_I2C_ADRS 0x68 |
j3 | 0:b00c4699ae6f | 58 | #define I2C_WRITE 0 |
j3 | 0:b00c4699ae6f | 59 | #define I2C_READ 1 |
j3 | 0:b00c4699ae6f | 60 | |
j3 | 2:4e6e761c60f2 | 61 | #define AM_PM (1 << 5) |
j3 | 2:4e6e761c60f2 | 62 | #define MODE (1 << 6) |
j3 | 2:4e6e761c60f2 | 63 | #define DY_DT (1 << 6) |
j3 | 2:4e6e761c60f2 | 64 | #define ALRM_MASK (1 << 7) |
j3 | 0:b00c4699ae6f | 65 | |
j3 | 0:b00c4699ae6f | 66 | //control register bit masks |
j3 | 0:b00c4699ae6f | 67 | #define A1IE (1 << 0) |
j3 | 0:b00c4699ae6f | 68 | #define A2IE (1 << 1) |
j3 | 0:b00c4699ae6f | 69 | #define INTCN (1 << 2) |
j3 | 0:b00c4699ae6f | 70 | #define RS1 (1 << 3) |
j3 | 0:b00c4699ae6f | 71 | #define RS2 (1 << 4) |
j3 | 0:b00c4699ae6f | 72 | #define CONV (1 << 5) |
j3 | 0:b00c4699ae6f | 73 | #define BBSQW (1 << 6) |
j3 | 2:4e6e761c60f2 | 74 | #define EOSC (1 << 7) |
j3 | 0:b00c4699ae6f | 75 | |
j3 | 0:b00c4699ae6f | 76 | //status register bit masks |
j3 | 0:b00c4699ae6f | 77 | #define A1F (1 << 0) |
j3 | 0:b00c4699ae6f | 78 | #define A2F (1 << 1) |
j3 | 0:b00c4699ae6f | 79 | #define BSY (1 << 2) |
j3 | 0:b00c4699ae6f | 80 | #define EN32KHZ (1 << 3) |
j3 | 0:b00c4699ae6f | 81 | #define OSF (1 << 7) |
j3 | 0:b00c4699ae6f | 82 | |
j3 | 0:b00c4699ae6f | 83 | |
j3 | 3:312589d8185c | 84 | //enumerated registers |
j3 | 0:b00c4699ae6f | 85 | typedef enum |
j3 | 0:b00c4699ae6f | 86 | { |
j3 | 0:b00c4699ae6f | 87 | SECONDS, |
j3 | 0:b00c4699ae6f | 88 | MINUTES, |
j3 | 0:b00c4699ae6f | 89 | HOURS, |
j3 | 0:b00c4699ae6f | 90 | DAY, |
j3 | 0:b00c4699ae6f | 91 | DATE, |
j3 | 0:b00c4699ae6f | 92 | MONTH, |
j3 | 0:b00c4699ae6f | 93 | YEAR, |
j3 | 0:b00c4699ae6f | 94 | ALRM1_SECONDS, |
j3 | 0:b00c4699ae6f | 95 | ALRM1_MINUTES, |
j3 | 0:b00c4699ae6f | 96 | ALRM1_HOURS, |
j3 | 0:b00c4699ae6f | 97 | ALRM1_DAY_DATE, |
j3 | 0:b00c4699ae6f | 98 | ALRM2_MINUTES, |
j3 | 0:b00c4699ae6f | 99 | ALRM2_HOURS, |
j3 | 0:b00c4699ae6f | 100 | ALRM2_DAY_DATE, |
j3 | 0:b00c4699ae6f | 101 | CONTROL, |
j3 | 0:b00c4699ae6f | 102 | STATUS, |
j3 | 0:b00c4699ae6f | 103 | AGING_OFFSET, //don't touch this register |
j3 | 0:b00c4699ae6f | 104 | MSB_TEMP, |
j3 | 0:b00c4699ae6f | 105 | LSB_TEMP |
j3 | 0:b00c4699ae6f | 106 | }ds3231_regs_t; |
j3 | 0:b00c4699ae6f | 107 | |
j3 | 0:b00c4699ae6f | 108 | |
j3 | 3:312589d8185c | 109 | //Time data |
j3 | 0:b00c4699ae6f | 110 | typedef struct |
j3 | 0:b00c4699ae6f | 111 | { |
j3 | 3:312589d8185c | 112 | uint8_t seconds; //Use decimal value. Member fx's convert to BCD |
j3 | 3:312589d8185c | 113 | uint8_t minutes; //Use decimal value. Member fx's convert to BCD |
j3 | 3:312589d8185c | 114 | uint8_t hours; //Use decimal value. Member fx's convert to BCD |
j3 | 2:4e6e761c60f2 | 115 | bool am_pm; //TRUE for PM, same logic as datasheet |
j3 | 2:4e6e761c60f2 | 116 | bool mode; //TRUE for 12 hour, same logic as datasheet |
j3 | 0:b00c4699ae6f | 117 | }ds3231_time_t; |
j3 | 0:b00c4699ae6f | 118 | |
j3 | 0:b00c4699ae6f | 119 | |
j3 | 3:312589d8185c | 120 | //Calendar data |
j3 | 0:b00c4699ae6f | 121 | typedef struct |
j3 | 0:b00c4699ae6f | 122 | { |
j3 | 3:312589d8185c | 123 | uint8_t day; //Use decimal value. Member fx's convert to BCD |
j3 | 3:312589d8185c | 124 | uint8_t date; //Use decimal value. Member fx's convert to BCD |
j3 | 3:312589d8185c | 125 | uint8_t month; //Use decimal value. Member fx's convert to BCD |
j3 | 3:312589d8185c | 126 | uint8_t year; //Use decimal value. Member fx's convert to BCD |
j3 | 0:b00c4699ae6f | 127 | }ds3231_calendar_t; |
j3 | 0:b00c4699ae6f | 128 | |
j3 | 0:b00c4699ae6f | 129 | |
j3 | 3:312589d8185c | 130 | //Alarm data |
j3 | 0:b00c4699ae6f | 131 | typedef struct |
j3 | 0:b00c4699ae6f | 132 | { |
j3 | 3:312589d8185c | 133 | //Seconds and am1 not used for alarm2 |
j3 | 3:312589d8185c | 134 | uint8_t seconds; //Use decimal value. Member fx's convert to BCD |
j3 | 3:312589d8185c | 135 | uint8_t minutes; //Use decimal value. Member fx's convert to BCD |
j3 | 3:312589d8185c | 136 | uint8_t hours; //Use decimal value. Member fx's convert to BCD |
j3 | 3:312589d8185c | 137 | uint8_t day; //Use decimal value. Member fx's convert to BCD |
j3 | 3:312589d8185c | 138 | uint8_t date; //Use decimal value. Member fx's convert to BCD |
j3 | 3:312589d8185c | 139 | bool am1; |
j3 | 2:4e6e761c60f2 | 140 | bool am2; |
j3 | 2:4e6e761c60f2 | 141 | bool am3; |
j3 | 2:4e6e761c60f2 | 142 | bool am4; |
j3 | 2:4e6e761c60f2 | 143 | bool am_pm; //TRUE for PM, same logic as datasheet |
j3 | 2:4e6e761c60f2 | 144 | bool mode; //TRUE for 12 hour, same logic as datasheet |
j3 | 2:4e6e761c60f2 | 145 | bool dy_dt; //TRUE for Day, same logic as datasheet |
j3 | 0:b00c4699ae6f | 146 | }ds3231_alrm_t; |
j3 | 0:b00c4699ae6f | 147 | |
j3 | 0:b00c4699ae6f | 148 | |
j3 | 0:b00c4699ae6f | 149 | typedef struct |
j3 | 0:b00c4699ae6f | 150 | { |
j3 | 3:312589d8185c | 151 | uint8_t control; //binary data |
j3 | 3:312589d8185c | 152 | uint8_t status; //binary data |
j3 | 0:b00c4699ae6f | 153 | }ds3231_cntl_stat_t; |
j3 | 0:b00c4699ae6f | 154 | |
j3 | 0:b00c4699ae6f | 155 | |
j3 | 0:b00c4699ae6f | 156 | /******************************************************************//** |
j3 | 0:b00c4699ae6f | 157 | * Ds3231 Class |
j3 | 0:b00c4699ae6f | 158 | **********************************************************************/ |
j3 | 1:c814af60fdbf | 159 | class Ds3231 : public I2C |
j3 | 0:b00c4699ae6f | 160 | { |
j3 | 0:b00c4699ae6f | 161 | uint8_t w_adrs, r_adrs; |
j3 | 0:b00c4699ae6f | 162 | |
j3 | 2:4e6e761c60f2 | 163 | /**********************************************************//** |
j3 | 2:4e6e761c60f2 | 164 | * Private mmber fx, converts unsigned char to BCD |
j3 | 2:4e6e761c60f2 | 165 | * |
j3 | 2:4e6e761c60f2 | 166 | * On Entry: |
j3 | 2:4e6e761c60f2 | 167 | * @param[in] data - 0-255 |
j3 | 2:4e6e761c60f2 | 168 | * |
j3 | 2:4e6e761c60f2 | 169 | * On Exit: |
j3 | 2:4e6e761c60f2 | 170 | * @return bcd_result = BCD representation of data |
j3 | 2:4e6e761c60f2 | 171 | * |
j3 | 2:4e6e761c60f2 | 172 | **************************************************************/ |
j3 | 2:4e6e761c60f2 | 173 | uint16_t uchar_2_bcd(uint8_t data); |
j3 | 2:4e6e761c60f2 | 174 | |
j3 | 2:4e6e761c60f2 | 175 | |
j3 | 2:4e6e761c60f2 | 176 | /**********************************************************//** |
j3 | 2:4e6e761c60f2 | 177 | * Private mmber fx, converts BCD to a uint8_t |
j3 | 2:4e6e761c60f2 | 178 | * |
j3 | 2:4e6e761c60f2 | 179 | * On Entry: |
j3 | 2:4e6e761c60f2 | 180 | * @param[in] bcd - 0-99 |
j3 | 2:4e6e761c60f2 | 181 | * |
j3 | 2:4e6e761c60f2 | 182 | * On Exit: |
j3 | 2:4e6e761c60f2 | 183 | * @return rtn_val = integer rep. of BCD |
j3 | 2:4e6e761c60f2 | 184 | * |
j3 | 2:4e6e761c60f2 | 185 | **************************************************************/ |
j3 | 2:4e6e761c60f2 | 186 | uint8_t bcd_2_uchar(uint8_t bcd); |
j3 | 2:4e6e761c60f2 | 187 | |
j3 | 0:b00c4699ae6f | 188 | public: |
j3 | 0:b00c4699ae6f | 189 | /**********************************************************//** |
j3 | 0:b00c4699ae6f | 190 | * Constructor for Ds3231 Class |
j3 | 0:b00c4699ae6f | 191 | * |
j3 | 0:b00c4699ae6f | 192 | * On Entry: |
j3 | 1:c814af60fdbf | 193 | * @param[in] sda - sda pin of I2C bus |
j3 | 1:c814af60fdbf | 194 | * @param[in] scl - scl pin of I2C bus |
j3 | 0:b00c4699ae6f | 195 | * |
j3 | 0:b00c4699ae6f | 196 | * On Exit: |
j3 | 0:b00c4699ae6f | 197 | * @return none |
j3 | 0:b00c4699ae6f | 198 | * |
j3 | 0:b00c4699ae6f | 199 | * Example: |
j3 | 0:b00c4699ae6f | 200 | * @code |
j3 | 0:b00c4699ae6f | 201 | * |
j3 | 0:b00c4699ae6f | 202 | * //instantiate rtc object |
j3 | 1:c814af60fdbf | 203 | * Ds3231 rtc(D14, D15); |
j3 | 0:b00c4699ae6f | 204 | * |
j3 | 0:b00c4699ae6f | 205 | * @endcode |
j3 | 0:b00c4699ae6f | 206 | **************************************************************/ |
j3 | 1:c814af60fdbf | 207 | Ds3231(PinName sda, PinName scl); |
j3 | 0:b00c4699ae6f | 208 | |
j3 | 0:b00c4699ae6f | 209 | |
j3 | 0:b00c4699ae6f | 210 | /**********************************************************//** |
j3 | 0:b00c4699ae6f | 211 | * Sets the time on DS3231 |
j3 | 2:4e6e761c60f2 | 212 | * Struct data is in integrer format, not BCD. Fx will convert |
j3 | 2:4e6e761c60f2 | 213 | * to BCD for you. |
j3 | 0:b00c4699ae6f | 214 | * |
j3 | 0:b00c4699ae6f | 215 | * On Entry: |
j3 | 0:b00c4699ae6f | 216 | * @param[in] time - struct cotaining time data; |
j3 | 0:b00c4699ae6f | 217 | * |
j3 | 0:b00c4699ae6f | 218 | * On Exit: |
j3 | 0:b00c4699ae6f | 219 | * @return return value = 0 on success, non-0 on failure |
j3 | 0:b00c4699ae6f | 220 | * |
j3 | 0:b00c4699ae6f | 221 | * Example: |
j3 | 0:b00c4699ae6f | 222 | * @code |
j3 | 0:b00c4699ae6f | 223 | * |
j3 | 0:b00c4699ae6f | 224 | * //instantiate rtc object |
j3 | 1:c814af60fdbf | 225 | * Ds3231 rtc(D14, D15); |
j3 | 0:b00c4699ae6f | 226 | * |
j3 | 4:0beb5e9ac927 | 227 | * //time = 12:00:00 AM 12hr mode |
j3 | 4:0beb5e9ac927 | 228 | * ds3231_time_t time = {12, 0, 0, 0, 1} |
j3 | 0:b00c4699ae6f | 229 | * uint16_t rtn_val; |
j3 | 0:b00c4699ae6f | 230 | * |
j3 | 0:b00c4699ae6f | 231 | * rtn_val = rtc.set_time(time); |
j3 | 0:b00c4699ae6f | 232 | * |
j3 | 0:b00c4699ae6f | 233 | * @endcode |
j3 | 0:b00c4699ae6f | 234 | **************************************************************/ |
j3 | 0:b00c4699ae6f | 235 | uint16_t set_time(ds3231_time_t time); |
j3 | 0:b00c4699ae6f | 236 | |
j3 | 0:b00c4699ae6f | 237 | |
j3 | 0:b00c4699ae6f | 238 | /**********************************************************//** |
j3 | 0:b00c4699ae6f | 239 | * Sets the calendar on DS3231 |
j3 | 0:b00c4699ae6f | 240 | * |
j3 | 0:b00c4699ae6f | 241 | * On Entry: |
j3 | 3:312589d8185c | 242 | * @param[in] calendar - struct cotaining calendar data |
j3 | 0:b00c4699ae6f | 243 | * |
j3 | 0:b00c4699ae6f | 244 | * On Exit: |
j3 | 0:b00c4699ae6f | 245 | * @return return value = 0 on success, non-0 on failure |
j3 | 0:b00c4699ae6f | 246 | * |
j3 | 0:b00c4699ae6f | 247 | * Example: |
j3 | 0:b00c4699ae6f | 248 | * @code |
j3 | 0:b00c4699ae6f | 249 | * |
j3 | 0:b00c4699ae6f | 250 | * //instantiate rtc object |
j3 | 1:c814af60fdbf | 251 | * Ds3231 rtc(D14, D15); |
j3 | 0:b00c4699ae6f | 252 | * |
j3 | 0:b00c4699ae6f | 253 | * //see datasheet for calendar format |
j3 | 0:b00c4699ae6f | 254 | * ds3231_calendar_t calendar = {1, 1, 1, 0}; |
j3 | 0:b00c4699ae6f | 255 | * uint16_t rtn_val; |
j3 | 0:b00c4699ae6f | 256 | * |
j3 | 0:b00c4699ae6f | 257 | * rtn_val = rtc.set_calendar(calendar); |
j3 | 0:b00c4699ae6f | 258 | * |
j3 | 0:b00c4699ae6f | 259 | * @endcode |
j3 | 0:b00c4699ae6f | 260 | **************************************************************/ |
j3 | 0:b00c4699ae6f | 261 | uint16_t set_calendar(ds3231_calendar_t calendar); |
j3 | 0:b00c4699ae6f | 262 | |
j3 | 0:b00c4699ae6f | 263 | |
j3 | 0:b00c4699ae6f | 264 | /**********************************************************//** |
j3 | 0:b00c4699ae6f | 265 | * Set either Alarm1 or Alarm2 of DS3231 |
j3 | 0:b00c4699ae6f | 266 | * |
j3 | 0:b00c4699ae6f | 267 | * On Entry: |
j3 | 0:b00c4699ae6f | 268 | * @param[in] alarm - struct cotaining alarm data |
j3 | 3:312589d8185c | 269 | * |
j3 | 0:b00c4699ae6f | 270 | * @param[in] one_r_two - TRUE for Alarm1 and FALSE for |
j3 | 0:b00c4699ae6f | 271 | * Alarm2 |
j3 | 0:b00c4699ae6f | 272 | * |
j3 | 0:b00c4699ae6f | 273 | * On Exit: |
j3 | 0:b00c4699ae6f | 274 | * @return return value = 0 on success, non-0 on failure |
j3 | 0:b00c4699ae6f | 275 | * |
j3 | 0:b00c4699ae6f | 276 | * Example: |
j3 | 0:b00c4699ae6f | 277 | * @code |
j3 | 0:b00c4699ae6f | 278 | * |
j3 | 0:b00c4699ae6f | 279 | * //instantiate rtc object |
j3 | 1:c814af60fdbf | 280 | * Ds3231 rtc(D14, D15); |
j3 | 0:b00c4699ae6f | 281 | * |
j3 | 4:0beb5e9ac927 | 282 | * //see ds3231.h for .members and datasheet for alarm format |
j3 | 4:0beb5e9ac927 | 283 | * ds3231_alrm_t alarm; |
j3 | 0:b00c4699ae6f | 284 | * uint16_t rtn_val; |
j3 | 0:b00c4699ae6f | 285 | * |
j3 | 0:b00c4699ae6f | 286 | * rtn_val = rtc.set_alarm(alarm, FALSE); |
j3 | 0:b00c4699ae6f | 287 | * |
j3 | 0:b00c4699ae6f | 288 | * @endcode |
j3 | 0:b00c4699ae6f | 289 | **************************************************************/ |
j3 | 0:b00c4699ae6f | 290 | uint16_t set_alarm(ds3231_alrm_t alarm, bool one_r_two); |
j3 | 0:b00c4699ae6f | 291 | |
j3 | 0:b00c4699ae6f | 292 | |
j3 | 0:b00c4699ae6f | 293 | /**********************************************************//** |
j3 | 0:b00c4699ae6f | 294 | * Set control and status registers of DS3231 |
j3 | 0:b00c4699ae6f | 295 | * |
j3 | 0:b00c4699ae6f | 296 | * On Entry: |
j3 | 0:b00c4699ae6f | 297 | * @param[in] data - Struct containing control and status |
j3 | 0:b00c4699ae6f | 298 | * register data |
j3 | 0:b00c4699ae6f | 299 | * |
j3 | 0:b00c4699ae6f | 300 | * On Exit: |
j3 | 0:b00c4699ae6f | 301 | * @return return value = 0 on success, non-0 on failure |
j3 | 0:b00c4699ae6f | 302 | * |
j3 | 0:b00c4699ae6f | 303 | * Example: |
j3 | 0:b00c4699ae6f | 304 | * @code |
j3 | 0:b00c4699ae6f | 305 | * |
j3 | 0:b00c4699ae6f | 306 | * //instantiate rtc object |
j3 | 1:c814af60fdbf | 307 | * Ds3231 rtc(D14, D15); |
j3 | 0:b00c4699ae6f | 308 | * |
j3 | 0:b00c4699ae6f | 309 | * //do not use 0xAA, see datasheet for appropriate data |
j3 | 0:b00c4699ae6f | 310 | * ds3231_cntl_stat_t data = {0xAA, 0xAA}; |
j3 | 0:b00c4699ae6f | 311 | * |
j3 | 0:b00c4699ae6f | 312 | * rtn_val = rtc.set_cntl_stat_reg(data); |
j3 | 0:b00c4699ae6f | 313 | * |
j3 | 0:b00c4699ae6f | 314 | * @endcode |
j3 | 0:b00c4699ae6f | 315 | **************************************************************/ |
j3 | 0:b00c4699ae6f | 316 | uint16_t set_cntl_stat_reg(ds3231_cntl_stat_t data); |
j3 | 0:b00c4699ae6f | 317 | |
j3 | 0:b00c4699ae6f | 318 | |
j3 | 0:b00c4699ae6f | 319 | /**********************************************************//** |
j3 | 0:b00c4699ae6f | 320 | * Gets the time on DS3231 |
j3 | 0:b00c4699ae6f | 321 | * |
j3 | 0:b00c4699ae6f | 322 | * On Entry: |
j3 | 4:0beb5e9ac927 | 323 | * @param[in] time - pointer to struct for storing time data |
j3 | 0:b00c4699ae6f | 324 | * |
j3 | 0:b00c4699ae6f | 325 | * On Exit: |
j3 | 2:4e6e761c60f2 | 326 | * @param[out] time - contains current integrer rtc time |
j3 | 2:4e6e761c60f2 | 327 | * data |
j3 | 0:b00c4699ae6f | 328 | * @return return value = 0 on success, non-0 on failure |
j3 | 0:b00c4699ae6f | 329 | * |
j3 | 0:b00c4699ae6f | 330 | * Example: |
j3 | 0:b00c4699ae6f | 331 | * @code |
j3 | 0:b00c4699ae6f | 332 | * |
j3 | 0:b00c4699ae6f | 333 | * //instantiate rtc object |
j3 | 1:c814af60fdbf | 334 | * Ds3231 rtc(D14, D15); |
j3 | 0:b00c4699ae6f | 335 | * |
j3 | 4:0beb5e9ac927 | 336 | * //time = 12:00:00 AM 12hr mode |
j3 | 4:0beb5e9ac927 | 337 | * ds3231_time_t time = {12, 0, 0, 0, 1} |
j3 | 0:b00c4699ae6f | 338 | * uint16_t rtn_val; |
j3 | 0:b00c4699ae6f | 339 | * |
j3 | 3:312589d8185c | 340 | * rtn_val = rtc.get_time(&time); |
j3 | 0:b00c4699ae6f | 341 | * |
j3 | 0:b00c4699ae6f | 342 | * @endcode |
j3 | 0:b00c4699ae6f | 343 | **************************************************************/ |
j3 | 2:4e6e761c60f2 | 344 | uint16_t get_time(ds3231_time_t* time); |
j3 | 0:b00c4699ae6f | 345 | |
j3 | 0:b00c4699ae6f | 346 | |
j3 | 0:b00c4699ae6f | 347 | /**********************************************************//** |
j3 | 0:b00c4699ae6f | 348 | * Gets the calendar on DS3231 |
j3 | 0:b00c4699ae6f | 349 | * |
j3 | 0:b00c4699ae6f | 350 | * On Entry: |
j3 | 2:4e6e761c60f2 | 351 | * @param[in] calendar - pointer to struct for storing |
j3 | 4:0beb5e9ac927 | 352 | * calendar data |
j3 | 0:b00c4699ae6f | 353 | * |
j3 | 0:b00c4699ae6f | 354 | * On Exit: |
j3 | 2:4e6e761c60f2 | 355 | * @param[out] calendar - contains current integer rtc |
j3 | 2:4e6e761c60f2 | 356 | * calendar data |
j3 | 0:b00c4699ae6f | 357 | * @return return value = 0 on success, non-0 on failure |
j3 | 0:b00c4699ae6f | 358 | * |
j3 | 0:b00c4699ae6f | 359 | * Example: |
j3 | 0:b00c4699ae6f | 360 | * @code |
j3 | 0:b00c4699ae6f | 361 | * |
j3 | 0:b00c4699ae6f | 362 | * //instantiate rtc object |
j3 | 1:c814af60fdbf | 363 | * Ds3231 rtc(D14, D15); |
j3 | 0:b00c4699ae6f | 364 | * |
j3 | 0:b00c4699ae6f | 365 | * //see datasheet for calendar format |
j3 | 0:b00c4699ae6f | 366 | * ds3231_calendar_t calendar = {1, 1, 1, 0}; |
j3 | 0:b00c4699ae6f | 367 | * uint16_t rtn_val; |
j3 | 0:b00c4699ae6f | 368 | * |
j3 | 3:312589d8185c | 369 | * rtn_val = rtc.get_calendar(&calendar); |
j3 | 0:b00c4699ae6f | 370 | * |
j3 | 0:b00c4699ae6f | 371 | * @endcode |
j3 | 0:b00c4699ae6f | 372 | **************************************************************/ |
j3 | 2:4e6e761c60f2 | 373 | uint16_t get_calendar(ds3231_calendar_t* calendar); |
j3 | 0:b00c4699ae6f | 374 | |
j3 | 0:b00c4699ae6f | 375 | |
j3 | 0:b00c4699ae6f | 376 | /**********************************************************//** |
j3 | 0:b00c4699ae6f | 377 | * Get either Alarm1 or Alarm2 of DS3231 |
j3 | 0:b00c4699ae6f | 378 | * |
j3 | 0:b00c4699ae6f | 379 | * On Entry: |
j3 | 2:4e6e761c60f2 | 380 | * @param[in] alarm - pointer to struct for storing alarm |
j3 | 2:4e6e761c60f2 | 381 | * data; |
j3 | 2:4e6e761c60f2 | 382 | * |
j3 | 0:b00c4699ae6f | 383 | * @param[in] one_r_two - TRUE for Alarm1 and FALSE for |
j3 | 0:b00c4699ae6f | 384 | * Alarm2 |
j3 | 0:b00c4699ae6f | 385 | * |
j3 | 0:b00c4699ae6f | 386 | * On Exit: |
j3 | 2:4e6e761c60f2 | 387 | * @param[out] alarm - contains integer alarm data |
j3 | 0:b00c4699ae6f | 388 | * @return return value = 0 on success, non-0 on failure |
j3 | 0:b00c4699ae6f | 389 | * |
j3 | 0:b00c4699ae6f | 390 | * Example: |
j3 | 0:b00c4699ae6f | 391 | * @code |
j3 | 0:b00c4699ae6f | 392 | * |
j3 | 0:b00c4699ae6f | 393 | * //instantiate rtc object |
j3 | 1:c814af60fdbf | 394 | * Ds3231 rtc(D14, D15); |
j3 | 0:b00c4699ae6f | 395 | * |
j3 | 4:0beb5e9ac927 | 396 | * //see ds3231.h for .members and datasheet for alarm format |
j3 | 4:0beb5e9ac927 | 397 | * ds3231_alrm_t alarm; |
j3 | 0:b00c4699ae6f | 398 | * uint16_t rtn_val; |
j3 | 0:b00c4699ae6f | 399 | * |
j3 | 3:312589d8185c | 400 | * rtn_val = rtc.get_alarm(&alarm, FALSE); |
j3 | 0:b00c4699ae6f | 401 | * |
j3 | 0:b00c4699ae6f | 402 | * @endcode |
j3 | 0:b00c4699ae6f | 403 | **************************************************************/ |
j3 | 2:4e6e761c60f2 | 404 | uint16_t get_alarm(ds3231_alrm_t* alarm, bool one_r_two); |
j3 | 0:b00c4699ae6f | 405 | |
j3 | 0:b00c4699ae6f | 406 | |
j3 | 0:b00c4699ae6f | 407 | /**********************************************************//** |
j3 | 0:b00c4699ae6f | 408 | * Get control and status registers of DS3231 |
j3 | 0:b00c4699ae6f | 409 | * |
j3 | 0:b00c4699ae6f | 410 | * On Entry: |
j3 | 2:4e6e761c60f2 | 411 | * @param[in] data - pointer to struct for storing control |
j3 | 4:0beb5e9ac927 | 412 | * and status register data |
j3 | 0:b00c4699ae6f | 413 | * |
j3 | 0:b00c4699ae6f | 414 | * On Exit: |
j3 | 0:b00c4699ae6f | 415 | * @param[out] data - contains control and status registers |
j3 | 0:b00c4699ae6f | 416 | * data |
j3 | 0:b00c4699ae6f | 417 | * @return return value = 0 on success, non-0 on failure |
j3 | 0:b00c4699ae6f | 418 | * |
j3 | 0:b00c4699ae6f | 419 | * Example: |
j3 | 0:b00c4699ae6f | 420 | * @code |
j3 | 0:b00c4699ae6f | 421 | * |
j3 | 0:b00c4699ae6f | 422 | * //instantiate rtc object |
j3 | 1:c814af60fdbf | 423 | * Ds3231 rtc(D14, D15); |
j3 | 0:b00c4699ae6f | 424 | * |
j3 | 0:b00c4699ae6f | 425 | * //do not use 0xAA, see datasheet for appropriate data |
j3 | 0:b00c4699ae6f | 426 | * ds3231_cntl_stat_t data = {0xAA, 0xAA}; |
j3 | 0:b00c4699ae6f | 427 | * |
j3 | 3:312589d8185c | 428 | * rtn_val = rtc.get_cntl_stat_reg(&data); |
j3 | 0:b00c4699ae6f | 429 | * |
j3 | 0:b00c4699ae6f | 430 | * @endcode |
j3 | 0:b00c4699ae6f | 431 | **************************************************************/ |
j3 | 2:4e6e761c60f2 | 432 | uint16_t get_cntl_stat_reg(ds3231_cntl_stat_t* data); |
j3 | 0:b00c4699ae6f | 433 | |
j3 | 0:b00c4699ae6f | 434 | |
j3 | 0:b00c4699ae6f | 435 | /**********************************************************//** |
j3 | 0:b00c4699ae6f | 436 | * Get temperature data of DS3231 |
j3 | 0:b00c4699ae6f | 437 | * |
j3 | 0:b00c4699ae6f | 438 | * On Entry: |
j3 | 0:b00c4699ae6f | 439 | * |
j3 | 0:b00c4699ae6f | 440 | * On Exit: |
j3 | 2:4e6e761c60f2 | 441 | * @return return value = raw temperature data |
j3 | 0:b00c4699ae6f | 442 | * |
j3 | 0:b00c4699ae6f | 443 | * Example: |
j3 | 0:b00c4699ae6f | 444 | * @code |
j3 | 0:b00c4699ae6f | 445 | * |
j3 | 0:b00c4699ae6f | 446 | * //instantiate rtc object |
j3 | 1:c814af60fdbf | 447 | * Ds3231 rtc(D14, D15); |
j3 | 0:b00c4699ae6f | 448 | * |
j3 | 0:b00c4699ae6f | 449 | * uint16_t temp; |
j3 | 0:b00c4699ae6f | 450 | * |
j3 | 2:4e6e761c60f2 | 451 | * temp = rtc.get_temperature(); |
j3 | 0:b00c4699ae6f | 452 | * |
j3 | 0:b00c4699ae6f | 453 | * @endcode |
j3 | 0:b00c4699ae6f | 454 | **************************************************************/ |
j3 | 2:4e6e761c60f2 | 455 | uint16_t get_temperature(void); |
j3 | 0:b00c4699ae6f | 456 | |
j3 | 5:61dfe2690360 | 457 | |
j3 | 5:61dfe2690360 | 458 | /**********************************************************//** |
j3 | 5:61dfe2690360 | 459 | * Get epoch time based on current RTC time and date. |
j3 | 5:61dfe2690360 | 460 | * DS3231 must be configured and running before this fx is |
j3 | 5:61dfe2690360 | 461 | * called |
j3 | 5:61dfe2690360 | 462 | * |
j3 | 5:61dfe2690360 | 463 | * On Entry: |
j3 | 5:61dfe2690360 | 464 | * |
j3 | 5:61dfe2690360 | 465 | * On Exit: |
j3 | 5:61dfe2690360 | 466 | * @return return value = epoch time |
j3 | 5:61dfe2690360 | 467 | * |
j3 | 5:61dfe2690360 | 468 | * Example: |
j3 | 5:61dfe2690360 | 469 | * @code |
j3 | 5:61dfe2690360 | 470 | * |
j3 | 5:61dfe2690360 | 471 | * //instantiate rtc object |
j3 | 5:61dfe2690360 | 472 | * Ds3231 rtc(D14, D15); |
j3 | 5:61dfe2690360 | 473 | * |
j3 | 5:61dfe2690360 | 474 | * time_t epoch_time; |
j3 | 5:61dfe2690360 | 475 | * |
j3 | 5:61dfe2690360 | 476 | * epoch_time = rtc.get_epoch(); |
j3 | 5:61dfe2690360 | 477 | * |
j3 | 5:61dfe2690360 | 478 | * @endcode |
j3 | 5:61dfe2690360 | 479 | **************************************************************/ |
j3 | 5:61dfe2690360 | 480 | time_t get_epoch(void); |
j3 | 5:61dfe2690360 | 481 | |
j3 | 0:b00c4699ae6f | 482 | }; |
j3 | 0:b00c4699ae6f | 483 | #endif /* DS3231_H*/ |