j
Fork of ds3231 by
ds3231.h@15:9670e0a3aeec, 2015-09-29 (annotated)
- Committer:
- dexterg
- Date:
- Tue Sep 29 21:29:28 2015 +0000
- Revision:
- 15:9670e0a3aeec
- Parent:
- 14:11630748e2f2
Data logger with SD and onboard RTC
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 | 11:1654fcc0a5ea | 6 | * @version 1.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 | 12:b9f13fd8c1b6 | 17 | * Copyright (C) 2015 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 | #define DS3231_I2C_ADRS 0x68 |
j3 | 0:b00c4699ae6f | 57 | #define I2C_WRITE 0 |
j3 | 0:b00c4699ae6f | 58 | #define I2C_READ 1 |
j3 | 0:b00c4699ae6f | 59 | |
j3 | 2:4e6e761c60f2 | 60 | #define AM_PM (1 << 5) |
j3 | 2:4e6e761c60f2 | 61 | #define MODE (1 << 6) |
j3 | 2:4e6e761c60f2 | 62 | #define DY_DT (1 << 6) |
j3 | 2:4e6e761c60f2 | 63 | #define ALRM_MASK (1 << 7) |
j3 | 0:b00c4699ae6f | 64 | |
j3 | 0:b00c4699ae6f | 65 | //control register bit masks |
j3 | 0:b00c4699ae6f | 66 | #define A1IE (1 << 0) |
j3 | 0:b00c4699ae6f | 67 | #define A2IE (1 << 1) |
j3 | 0:b00c4699ae6f | 68 | #define INTCN (1 << 2) |
j3 | 0:b00c4699ae6f | 69 | #define RS1 (1 << 3) |
j3 | 0:b00c4699ae6f | 70 | #define RS2 (1 << 4) |
j3 | 0:b00c4699ae6f | 71 | #define CONV (1 << 5) |
j3 | 0:b00c4699ae6f | 72 | #define BBSQW (1 << 6) |
j3 | 2:4e6e761c60f2 | 73 | #define EOSC (1 << 7) |
j3 | 0:b00c4699ae6f | 74 | |
j3 | 0:b00c4699ae6f | 75 | //status register bit masks |
j3 | 0:b00c4699ae6f | 76 | #define A1F (1 << 0) |
j3 | 0:b00c4699ae6f | 77 | #define A2F (1 << 1) |
j3 | 0:b00c4699ae6f | 78 | #define BSY (1 << 2) |
j3 | 0:b00c4699ae6f | 79 | #define EN32KHZ (1 << 3) |
j3 | 0:b00c4699ae6f | 80 | #define OSF (1 << 7) |
j3 | 9:e57201ee8921 | 81 | |
j3 | 14:11630748e2f2 | 82 | |
j3 | 14:11630748e2f2 | 83 | /** |
j3 | 14:11630748e2f2 | 84 | * ds3231_time_t - Struct for containing time data. |
j3 | 14:11630748e2f2 | 85 | * |
j3 | 14:11630748e2f2 | 86 | * Members: |
j3 | 14:11630748e2f2 | 87 | * |
j3 | 14:11630748e2f2 | 88 | * - uint32_t seconds - Use decimal value. Member fx's convert to BCD |
j3 | 14:11630748e2f2 | 89 | * |
j3 | 14:11630748e2f2 | 90 | * - uint32_t minutes - Use decimal value. Member fx's convert to BCD |
j3 | 14:11630748e2f2 | 91 | * |
j3 | 14:11630748e2f2 | 92 | * - uint32_t hours - Use decimal value. Member fx's convert to BCD |
j3 | 14:11630748e2f2 | 93 | * |
j3 | 14:11630748e2f2 | 94 | * - bool am_pm - TRUE for PM, same logic as datasheet |
j3 | 14:11630748e2f2 | 95 | * |
j3 | 14:11630748e2f2 | 96 | * - bool mode - TRUE for 12 hour, same logic as datasheet |
j3 | 14:11630748e2f2 | 97 | */ |
j3 | 14:11630748e2f2 | 98 | typedef struct |
j3 | 14:11630748e2f2 | 99 | { |
j3 | 14:11630748e2f2 | 100 | uint32_t seconds; |
j3 | 14:11630748e2f2 | 101 | uint32_t minutes; |
j3 | 14:11630748e2f2 | 102 | uint32_t hours; |
j3 | 14:11630748e2f2 | 103 | bool am_pm; |
j3 | 14:11630748e2f2 | 104 | bool mode; |
j3 | 14:11630748e2f2 | 105 | }ds3231_time_t; |
j3 | 14:11630748e2f2 | 106 | |
j3 | 14:11630748e2f2 | 107 | |
j3 | 14:11630748e2f2 | 108 | /** |
j3 | 14:11630748e2f2 | 109 | * ds3231_calendar_t - Struct for containing calendar data. |
j3 | 14:11630748e2f2 | 110 | * |
j3 | 14:11630748e2f2 | 111 | * Members: |
j3 | 14:11630748e2f2 | 112 | * |
j3 | 14:11630748e2f2 | 113 | * - uint32_t day - Use decimal value. Member fx's convert to BCD |
j3 | 14:11630748e2f2 | 114 | * |
j3 | 14:11630748e2f2 | 115 | * - uint32_t date - Use decimal value. Member fx's convert to BCD |
j3 | 14:11630748e2f2 | 116 | * |
j3 | 14:11630748e2f2 | 117 | * - uint32_t month - Use decimal value. Member fx's convert to BCD |
j3 | 14:11630748e2f2 | 118 | * |
j3 | 14:11630748e2f2 | 119 | * - uint32_t year - Use decimal value. Member fx's convert to BCD |
j3 | 14:11630748e2f2 | 120 | */ |
j3 | 14:11630748e2f2 | 121 | typedef struct |
j3 | 14:11630748e2f2 | 122 | { |
j3 | 14:11630748e2f2 | 123 | uint32_t day; |
j3 | 14:11630748e2f2 | 124 | uint32_t date; |
j3 | 14:11630748e2f2 | 125 | uint32_t month; |
j3 | 14:11630748e2f2 | 126 | uint32_t year; |
j3 | 14:11630748e2f2 | 127 | }ds3231_calendar_t; |
j3 | 14:11630748e2f2 | 128 | |
j3 | 14:11630748e2f2 | 129 | |
j3 | 14:11630748e2f2 | 130 | /** |
j3 | 14:11630748e2f2 | 131 | * ds3231_alrm_t - Struct for containing alarm data. |
j3 | 14:11630748e2f2 | 132 | * |
j3 | 14:11630748e2f2 | 133 | * Members: |
j3 | 14:11630748e2f2 | 134 | * |
j3 | 14:11630748e2f2 | 135 | * - uint32_t seconds - Use decimal value. Member fx's convert to BCD |
j3 | 14:11630748e2f2 | 136 | * |
j3 | 14:11630748e2f2 | 137 | * - uint32_t minutes - Use decimal value. Member fx's convert to BCD |
j3 | 14:11630748e2f2 | 138 | * |
j3 | 14:11630748e2f2 | 139 | * - uint32_t hours - Use decimal value. Member fx's convert to BCD |
j3 | 14:11630748e2f2 | 140 | * |
j3 | 14:11630748e2f2 | 141 | * - uint32_t day - Use decimal value. Member fx's convert to BCD |
j3 | 14:11630748e2f2 | 142 | * |
j3 | 14:11630748e2f2 | 143 | * - uint32_t date - Use decimal value. Member fx's convert to BCD |
j3 | 14:11630748e2f2 | 144 | * |
j3 | 14:11630748e2f2 | 145 | * - bool am1 - Flag for setting alarm rate |
j3 | 14:11630748e2f2 | 146 | * |
j3 | 14:11630748e2f2 | 147 | * - bool am2 - Flag for setting alarm rate |
j3 | 14:11630748e2f2 | 148 | * |
j3 | 14:11630748e2f2 | 149 | * - bool am3 - Flag for setting alarm rate |
j3 | 14:11630748e2f2 | 150 | * |
j3 | 14:11630748e2f2 | 151 | * - bool am4 - Flag for setting alarm rate |
j3 | 14:11630748e2f2 | 152 | * |
j3 | 14:11630748e2f2 | 153 | * - bool am_pm - TRUE for PM, same logic as datasheet |
j3 | 14:11630748e2f2 | 154 | * |
j3 | 14:11630748e2f2 | 155 | * - bool mode - TRUE for 12 hour, same logic as datasheet |
j3 | 14:11630748e2f2 | 156 | * |
j3 | 14:11630748e2f2 | 157 | * - bool dy_dt - TRUE for Day, same logic as datasheet |
j3 | 14:11630748e2f2 | 158 | */ |
j3 | 14:11630748e2f2 | 159 | typedef struct |
j3 | 14:11630748e2f2 | 160 | { |
j3 | 14:11630748e2f2 | 161 | //Seconds and am1 not used for alarm2 |
j3 | 14:11630748e2f2 | 162 | uint32_t seconds; |
j3 | 14:11630748e2f2 | 163 | uint32_t minutes; |
j3 | 14:11630748e2f2 | 164 | uint32_t hours; |
j3 | 14:11630748e2f2 | 165 | uint32_t day; |
j3 | 14:11630748e2f2 | 166 | uint32_t date; |
j3 | 14:11630748e2f2 | 167 | bool am1; |
j3 | 14:11630748e2f2 | 168 | bool am2; |
j3 | 14:11630748e2f2 | 169 | bool am3; |
j3 | 14:11630748e2f2 | 170 | bool am4; |
j3 | 14:11630748e2f2 | 171 | bool am_pm; |
j3 | 14:11630748e2f2 | 172 | bool mode; |
j3 | 14:11630748e2f2 | 173 | bool dy_dt; |
j3 | 14:11630748e2f2 | 174 | }ds3231_alrm_t; |
j3 | 14:11630748e2f2 | 175 | |
j3 | 14:11630748e2f2 | 176 | |
j3 | 14:11630748e2f2 | 177 | /** |
j3 | 14:11630748e2f2 | 178 | * ds3231_cntl_stat_t - Struct for containing control and status |
j3 | 14:11630748e2f2 | 179 | * register data. |
j3 | 14:11630748e2f2 | 180 | * |
j3 | 14:11630748e2f2 | 181 | * Members: |
j3 | 14:11630748e2f2 | 182 | * |
j3 | 14:11630748e2f2 | 183 | * - uint8_t control - Binary data for read/write of control register |
j3 | 14:11630748e2f2 | 184 | * |
j3 | 14:11630748e2f2 | 185 | * - uint8_t status - Binary data for read/write of status register |
j3 | 14:11630748e2f2 | 186 | */ |
j3 | 14:11630748e2f2 | 187 | typedef struct |
j3 | 14:11630748e2f2 | 188 | { |
j3 | 14:11630748e2f2 | 189 | uint8_t control; |
j3 | 14:11630748e2f2 | 190 | uint8_t status; |
j3 | 14:11630748e2f2 | 191 | }ds3231_cntl_stat_t; |
j3 | 9:e57201ee8921 | 192 | |
j3 | 14:11630748e2f2 | 193 | |
j3 | 0:b00c4699ae6f | 194 | /******************************************************************//** |
j3 | 0:b00c4699ae6f | 195 | * Ds3231 Class |
j3 | 0:b00c4699ae6f | 196 | **********************************************************************/ |
j3 | 1:c814af60fdbf | 197 | class Ds3231 : public I2C |
j3 | 0:b00c4699ae6f | 198 | { |
j3 | 0:b00c4699ae6f | 199 | uint8_t w_adrs, r_adrs; |
j3 | 0:b00c4699ae6f | 200 | |
j3 | 2:4e6e761c60f2 | 201 | /**********************************************************//** |
j3 | 2:4e6e761c60f2 | 202 | * Private mmber fx, converts unsigned char to BCD |
j3 | 2:4e6e761c60f2 | 203 | * |
j3 | 2:4e6e761c60f2 | 204 | * On Entry: |
j3 | 2:4e6e761c60f2 | 205 | * @param[in] data - 0-255 |
j3 | 2:4e6e761c60f2 | 206 | * |
j3 | 2:4e6e761c60f2 | 207 | * On Exit: |
j3 | 2:4e6e761c60f2 | 208 | * @return bcd_result = BCD representation of data |
j3 | 2:4e6e761c60f2 | 209 | * |
j3 | 2:4e6e761c60f2 | 210 | **************************************************************/ |
j3 | 2:4e6e761c60f2 | 211 | uint16_t uchar_2_bcd(uint8_t data); |
j3 | 2:4e6e761c60f2 | 212 | |
j3 | 2:4e6e761c60f2 | 213 | |
j3 | 2:4e6e761c60f2 | 214 | /**********************************************************//** |
j3 | 2:4e6e761c60f2 | 215 | * Private mmber fx, converts BCD to a uint8_t |
j3 | 2:4e6e761c60f2 | 216 | * |
j3 | 2:4e6e761c60f2 | 217 | * On Entry: |
j3 | 2:4e6e761c60f2 | 218 | * @param[in] bcd - 0-99 |
j3 | 2:4e6e761c60f2 | 219 | * |
j3 | 2:4e6e761c60f2 | 220 | * On Exit: |
j3 | 2:4e6e761c60f2 | 221 | * @return rtn_val = integer rep. of BCD |
j3 | 2:4e6e761c60f2 | 222 | * |
j3 | 2:4e6e761c60f2 | 223 | **************************************************************/ |
j3 | 2:4e6e761c60f2 | 224 | uint8_t bcd_2_uchar(uint8_t bcd); |
j3 | 2:4e6e761c60f2 | 225 | |
j3 | 0:b00c4699ae6f | 226 | public: |
j3 | 13:aa3eb69b25bb | 227 | |
j3 | 13:aa3eb69b25bb | 228 | /** |
j3 | 13:aa3eb69b25bb | 229 | * ds3231_regs_t - enumerated DS3231 registers |
j3 | 13:aa3eb69b25bb | 230 | */ |
j3 | 13:aa3eb69b25bb | 231 | typedef enum |
j3 | 13:aa3eb69b25bb | 232 | { |
j3 | 13:aa3eb69b25bb | 233 | SECONDS, |
j3 | 13:aa3eb69b25bb | 234 | MINUTES, |
j3 | 13:aa3eb69b25bb | 235 | HOURS, |
j3 | 13:aa3eb69b25bb | 236 | DAY, |
j3 | 13:aa3eb69b25bb | 237 | DATE, |
j3 | 13:aa3eb69b25bb | 238 | MONTH, |
j3 | 13:aa3eb69b25bb | 239 | YEAR, |
j3 | 13:aa3eb69b25bb | 240 | ALRM1_SECONDS, |
j3 | 13:aa3eb69b25bb | 241 | ALRM1_MINUTES, |
j3 | 13:aa3eb69b25bb | 242 | ALRM1_HOURS, |
j3 | 13:aa3eb69b25bb | 243 | ALRM1_DAY_DATE, |
j3 | 13:aa3eb69b25bb | 244 | ALRM2_MINUTES, |
j3 | 13:aa3eb69b25bb | 245 | ALRM2_HOURS, |
j3 | 13:aa3eb69b25bb | 246 | ALRM2_DAY_DATE, |
j3 | 13:aa3eb69b25bb | 247 | CONTROL, |
j3 | 13:aa3eb69b25bb | 248 | STATUS, |
j3 | 13:aa3eb69b25bb | 249 | AGING_OFFSET, //don't touch this register |
j3 | 13:aa3eb69b25bb | 250 | MSB_TEMP, |
j3 | 13:aa3eb69b25bb | 251 | LSB_TEMP |
j3 | 13:aa3eb69b25bb | 252 | }ds3231_regs_t; |
j3 | 14:11630748e2f2 | 253 | |
j3 | 9:e57201ee8921 | 254 | |
j3 | 0:b00c4699ae6f | 255 | /**********************************************************//** |
j3 | 0:b00c4699ae6f | 256 | * Constructor for Ds3231 Class |
j3 | 0:b00c4699ae6f | 257 | * |
j3 | 0:b00c4699ae6f | 258 | * On Entry: |
j3 | 1:c814af60fdbf | 259 | * @param[in] sda - sda pin of I2C bus |
j3 | 1:c814af60fdbf | 260 | * @param[in] scl - scl pin of I2C bus |
j3 | 0:b00c4699ae6f | 261 | * |
j3 | 0:b00c4699ae6f | 262 | * On Exit: |
j3 | 0:b00c4699ae6f | 263 | * @return none |
j3 | 0:b00c4699ae6f | 264 | * |
j3 | 0:b00c4699ae6f | 265 | * Example: |
j3 | 0:b00c4699ae6f | 266 | * @code |
j3 | 0:b00c4699ae6f | 267 | * |
j3 | 0:b00c4699ae6f | 268 | * //instantiate rtc object |
j3 | 1:c814af60fdbf | 269 | * Ds3231 rtc(D14, D15); |
j3 | 0:b00c4699ae6f | 270 | * |
j3 | 0:b00c4699ae6f | 271 | * @endcode |
j3 | 0:b00c4699ae6f | 272 | **************************************************************/ |
j3 | 1:c814af60fdbf | 273 | Ds3231(PinName sda, PinName scl); |
j3 | 0:b00c4699ae6f | 274 | |
j3 | 0:b00c4699ae6f | 275 | |
j3 | 0:b00c4699ae6f | 276 | /**********************************************************//** |
j3 | 0:b00c4699ae6f | 277 | * Sets the time on DS3231 |
j3 | 2:4e6e761c60f2 | 278 | * Struct data is in integrer format, not BCD. Fx will convert |
j3 | 2:4e6e761c60f2 | 279 | * to BCD for you. |
j3 | 0:b00c4699ae6f | 280 | * |
j3 | 0:b00c4699ae6f | 281 | * On Entry: |
j3 | 0:b00c4699ae6f | 282 | * @param[in] time - struct cotaining time data; |
j3 | 0:b00c4699ae6f | 283 | * |
j3 | 0:b00c4699ae6f | 284 | * On Exit: |
j3 | 0:b00c4699ae6f | 285 | * @return return value = 0 on success, non-0 on failure |
j3 | 0:b00c4699ae6f | 286 | * |
j3 | 0:b00c4699ae6f | 287 | * Example: |
j3 | 0:b00c4699ae6f | 288 | * @code |
j3 | 0:b00c4699ae6f | 289 | * |
j3 | 0:b00c4699ae6f | 290 | * //instantiate rtc object |
j3 | 1:c814af60fdbf | 291 | * Ds3231 rtc(D14, D15); |
j3 | 0:b00c4699ae6f | 292 | * |
j3 | 4:0beb5e9ac927 | 293 | * //time = 12:00:00 AM 12hr mode |
j3 | 4:0beb5e9ac927 | 294 | * ds3231_time_t time = {12, 0, 0, 0, 1} |
j3 | 0:b00c4699ae6f | 295 | * uint16_t rtn_val; |
j3 | 0:b00c4699ae6f | 296 | * |
j3 | 0:b00c4699ae6f | 297 | * rtn_val = rtc.set_time(time); |
j3 | 0:b00c4699ae6f | 298 | * |
j3 | 0:b00c4699ae6f | 299 | * @endcode |
j3 | 0:b00c4699ae6f | 300 | **************************************************************/ |
j3 | 0:b00c4699ae6f | 301 | uint16_t set_time(ds3231_time_t time); |
j3 | 0:b00c4699ae6f | 302 | |
j3 | 0:b00c4699ae6f | 303 | |
j3 | 0:b00c4699ae6f | 304 | /**********************************************************//** |
j3 | 0:b00c4699ae6f | 305 | * Sets the calendar on DS3231 |
j3 | 0:b00c4699ae6f | 306 | * |
j3 | 0:b00c4699ae6f | 307 | * On Entry: |
j3 | 3:312589d8185c | 308 | * @param[in] calendar - struct cotaining calendar data |
j3 | 0:b00c4699ae6f | 309 | * |
j3 | 0:b00c4699ae6f | 310 | * On Exit: |
j3 | 0:b00c4699ae6f | 311 | * @return return value = 0 on success, non-0 on failure |
j3 | 0:b00c4699ae6f | 312 | * |
j3 | 0:b00c4699ae6f | 313 | * Example: |
j3 | 0:b00c4699ae6f | 314 | * @code |
j3 | 0:b00c4699ae6f | 315 | * |
j3 | 0:b00c4699ae6f | 316 | * //instantiate rtc object |
j3 | 1:c814af60fdbf | 317 | * Ds3231 rtc(D14, D15); |
j3 | 0:b00c4699ae6f | 318 | * |
j3 | 0:b00c4699ae6f | 319 | * //see datasheet for calendar format |
j3 | 0:b00c4699ae6f | 320 | * ds3231_calendar_t calendar = {1, 1, 1, 0}; |
j3 | 0:b00c4699ae6f | 321 | * uint16_t rtn_val; |
j3 | 0:b00c4699ae6f | 322 | * |
j3 | 0:b00c4699ae6f | 323 | * rtn_val = rtc.set_calendar(calendar); |
j3 | 0:b00c4699ae6f | 324 | * |
j3 | 0:b00c4699ae6f | 325 | * @endcode |
j3 | 0:b00c4699ae6f | 326 | **************************************************************/ |
j3 | 0:b00c4699ae6f | 327 | uint16_t set_calendar(ds3231_calendar_t calendar); |
j3 | 0:b00c4699ae6f | 328 | |
j3 | 0:b00c4699ae6f | 329 | |
j3 | 0:b00c4699ae6f | 330 | /**********************************************************//** |
j3 | 0:b00c4699ae6f | 331 | * Set either Alarm1 or Alarm2 of DS3231 |
j3 | 0:b00c4699ae6f | 332 | * |
j3 | 0:b00c4699ae6f | 333 | * On Entry: |
j3 | 0:b00c4699ae6f | 334 | * @param[in] alarm - struct cotaining alarm data |
j3 | 3:312589d8185c | 335 | * |
j3 | 0:b00c4699ae6f | 336 | * @param[in] one_r_two - TRUE for Alarm1 and FALSE for |
j3 | 0:b00c4699ae6f | 337 | * Alarm2 |
j3 | 0:b00c4699ae6f | 338 | * |
j3 | 0:b00c4699ae6f | 339 | * On Exit: |
j3 | 0:b00c4699ae6f | 340 | * @return return value = 0 on success, non-0 on failure |
j3 | 0:b00c4699ae6f | 341 | * |
j3 | 0:b00c4699ae6f | 342 | * Example: |
j3 | 0:b00c4699ae6f | 343 | * @code |
j3 | 0:b00c4699ae6f | 344 | * |
j3 | 0:b00c4699ae6f | 345 | * //instantiate rtc object |
j3 | 1:c814af60fdbf | 346 | * Ds3231 rtc(D14, D15); |
j3 | 0:b00c4699ae6f | 347 | * |
j3 | 4:0beb5e9ac927 | 348 | * //see ds3231.h for .members and datasheet for alarm format |
j3 | 4:0beb5e9ac927 | 349 | * ds3231_alrm_t alarm; |
j3 | 0:b00c4699ae6f | 350 | * uint16_t rtn_val; |
j3 | 0:b00c4699ae6f | 351 | * |
j3 | 0:b00c4699ae6f | 352 | * rtn_val = rtc.set_alarm(alarm, FALSE); |
j3 | 0:b00c4699ae6f | 353 | * |
j3 | 0:b00c4699ae6f | 354 | * @endcode |
j3 | 0:b00c4699ae6f | 355 | **************************************************************/ |
j3 | 0:b00c4699ae6f | 356 | uint16_t set_alarm(ds3231_alrm_t alarm, bool one_r_two); |
j3 | 0:b00c4699ae6f | 357 | |
j3 | 0:b00c4699ae6f | 358 | |
j3 | 0:b00c4699ae6f | 359 | /**********************************************************//** |
j3 | 0:b00c4699ae6f | 360 | * Set control and status registers of DS3231 |
j3 | 0:b00c4699ae6f | 361 | * |
j3 | 0:b00c4699ae6f | 362 | * On Entry: |
j3 | 0:b00c4699ae6f | 363 | * @param[in] data - Struct containing control and status |
j3 | 0:b00c4699ae6f | 364 | * register data |
j3 | 0:b00c4699ae6f | 365 | * |
j3 | 0:b00c4699ae6f | 366 | * On Exit: |
j3 | 0:b00c4699ae6f | 367 | * @return return value = 0 on success, non-0 on failure |
j3 | 0:b00c4699ae6f | 368 | * |
j3 | 0:b00c4699ae6f | 369 | * Example: |
j3 | 0:b00c4699ae6f | 370 | * @code |
j3 | 0:b00c4699ae6f | 371 | * |
j3 | 0:b00c4699ae6f | 372 | * //instantiate rtc object |
j3 | 1:c814af60fdbf | 373 | * Ds3231 rtc(D14, D15); |
j3 | 0:b00c4699ae6f | 374 | * |
j3 | 0:b00c4699ae6f | 375 | * //do not use 0xAA, see datasheet for appropriate data |
j3 | 0:b00c4699ae6f | 376 | * ds3231_cntl_stat_t data = {0xAA, 0xAA}; |
j3 | 0:b00c4699ae6f | 377 | * |
j3 | 0:b00c4699ae6f | 378 | * rtn_val = rtc.set_cntl_stat_reg(data); |
j3 | 0:b00c4699ae6f | 379 | * |
j3 | 0:b00c4699ae6f | 380 | * @endcode |
j3 | 0:b00c4699ae6f | 381 | **************************************************************/ |
j3 | 0:b00c4699ae6f | 382 | uint16_t set_cntl_stat_reg(ds3231_cntl_stat_t data); |
j3 | 0:b00c4699ae6f | 383 | |
j3 | 0:b00c4699ae6f | 384 | |
j3 | 0:b00c4699ae6f | 385 | /**********************************************************//** |
j3 | 0:b00c4699ae6f | 386 | * Gets the time on DS3231 |
j3 | 0:b00c4699ae6f | 387 | * |
j3 | 0:b00c4699ae6f | 388 | * On Entry: |
j3 | 4:0beb5e9ac927 | 389 | * @param[in] time - pointer to struct for storing time data |
j3 | 0:b00c4699ae6f | 390 | * |
j3 | 0:b00c4699ae6f | 391 | * On Exit: |
j3 | 2:4e6e761c60f2 | 392 | * @param[out] time - contains current integrer rtc time |
j3 | 2:4e6e761c60f2 | 393 | * data |
j3 | 0:b00c4699ae6f | 394 | * @return return value = 0 on success, non-0 on failure |
j3 | 0:b00c4699ae6f | 395 | * |
j3 | 0:b00c4699ae6f | 396 | * Example: |
j3 | 0:b00c4699ae6f | 397 | * @code |
j3 | 0:b00c4699ae6f | 398 | * |
j3 | 0:b00c4699ae6f | 399 | * //instantiate rtc object |
j3 | 1:c814af60fdbf | 400 | * Ds3231 rtc(D14, D15); |
j3 | 0:b00c4699ae6f | 401 | * |
j3 | 4:0beb5e9ac927 | 402 | * //time = 12:00:00 AM 12hr mode |
j3 | 4:0beb5e9ac927 | 403 | * ds3231_time_t time = {12, 0, 0, 0, 1} |
j3 | 0:b00c4699ae6f | 404 | * uint16_t rtn_val; |
j3 | 0:b00c4699ae6f | 405 | * |
j3 | 3:312589d8185c | 406 | * rtn_val = rtc.get_time(&time); |
j3 | 0:b00c4699ae6f | 407 | * |
j3 | 0:b00c4699ae6f | 408 | * @endcode |
j3 | 0:b00c4699ae6f | 409 | **************************************************************/ |
j3 | 2:4e6e761c60f2 | 410 | uint16_t get_time(ds3231_time_t* time); |
j3 | 0:b00c4699ae6f | 411 | |
j3 | 0:b00c4699ae6f | 412 | |
j3 | 0:b00c4699ae6f | 413 | /**********************************************************//** |
j3 | 0:b00c4699ae6f | 414 | * Gets the calendar on DS3231 |
j3 | 0:b00c4699ae6f | 415 | * |
j3 | 0:b00c4699ae6f | 416 | * On Entry: |
j3 | 2:4e6e761c60f2 | 417 | * @param[in] calendar - pointer to struct for storing |
j3 | 4:0beb5e9ac927 | 418 | * calendar data |
j3 | 0:b00c4699ae6f | 419 | * |
j3 | 0:b00c4699ae6f | 420 | * On Exit: |
j3 | 2:4e6e761c60f2 | 421 | * @param[out] calendar - contains current integer rtc |
j3 | 2:4e6e761c60f2 | 422 | * calendar data |
j3 | 0:b00c4699ae6f | 423 | * @return return value = 0 on success, non-0 on failure |
j3 | 0:b00c4699ae6f | 424 | * |
j3 | 0:b00c4699ae6f | 425 | * Example: |
j3 | 0:b00c4699ae6f | 426 | * @code |
j3 | 0:b00c4699ae6f | 427 | * |
j3 | 0:b00c4699ae6f | 428 | * //instantiate rtc object |
j3 | 1:c814af60fdbf | 429 | * Ds3231 rtc(D14, D15); |
j3 | 0:b00c4699ae6f | 430 | * |
j3 | 0:b00c4699ae6f | 431 | * //see datasheet for calendar format |
j3 | 0:b00c4699ae6f | 432 | * ds3231_calendar_t calendar = {1, 1, 1, 0}; |
j3 | 0:b00c4699ae6f | 433 | * uint16_t rtn_val; |
j3 | 0:b00c4699ae6f | 434 | * |
j3 | 3:312589d8185c | 435 | * rtn_val = rtc.get_calendar(&calendar); |
j3 | 0:b00c4699ae6f | 436 | * |
j3 | 0:b00c4699ae6f | 437 | * @endcode |
j3 | 0:b00c4699ae6f | 438 | **************************************************************/ |
j3 | 2:4e6e761c60f2 | 439 | uint16_t get_calendar(ds3231_calendar_t* calendar); |
j3 | 0:b00c4699ae6f | 440 | |
j3 | 0:b00c4699ae6f | 441 | |
j3 | 0:b00c4699ae6f | 442 | /**********************************************************//** |
j3 | 0:b00c4699ae6f | 443 | * Get either Alarm1 or Alarm2 of DS3231 |
j3 | 0:b00c4699ae6f | 444 | * |
j3 | 0:b00c4699ae6f | 445 | * On Entry: |
j3 | 2:4e6e761c60f2 | 446 | * @param[in] alarm - pointer to struct for storing alarm |
j3 | 2:4e6e761c60f2 | 447 | * data; |
j3 | 2:4e6e761c60f2 | 448 | * |
j3 | 0:b00c4699ae6f | 449 | * @param[in] one_r_two - TRUE for Alarm1 and FALSE for |
j3 | 0:b00c4699ae6f | 450 | * Alarm2 |
j3 | 0:b00c4699ae6f | 451 | * |
j3 | 0:b00c4699ae6f | 452 | * On Exit: |
j3 | 2:4e6e761c60f2 | 453 | * @param[out] alarm - contains integer alarm data |
j3 | 0:b00c4699ae6f | 454 | * @return return value = 0 on success, non-0 on failure |
j3 | 0:b00c4699ae6f | 455 | * |
j3 | 0:b00c4699ae6f | 456 | * Example: |
j3 | 0:b00c4699ae6f | 457 | * @code |
j3 | 0:b00c4699ae6f | 458 | * |
j3 | 0:b00c4699ae6f | 459 | * //instantiate rtc object |
j3 | 1:c814af60fdbf | 460 | * Ds3231 rtc(D14, D15); |
j3 | 0:b00c4699ae6f | 461 | * |
j3 | 4:0beb5e9ac927 | 462 | * //see ds3231.h for .members and datasheet for alarm format |
j3 | 4:0beb5e9ac927 | 463 | * ds3231_alrm_t alarm; |
j3 | 0:b00c4699ae6f | 464 | * uint16_t rtn_val; |
j3 | 0:b00c4699ae6f | 465 | * |
j3 | 3:312589d8185c | 466 | * rtn_val = rtc.get_alarm(&alarm, FALSE); |
j3 | 0:b00c4699ae6f | 467 | * |
j3 | 0:b00c4699ae6f | 468 | * @endcode |
j3 | 0:b00c4699ae6f | 469 | **************************************************************/ |
j3 | 2:4e6e761c60f2 | 470 | uint16_t get_alarm(ds3231_alrm_t* alarm, bool one_r_two); |
j3 | 0:b00c4699ae6f | 471 | |
j3 | 0:b00c4699ae6f | 472 | |
j3 | 0:b00c4699ae6f | 473 | /**********************************************************//** |
j3 | 0:b00c4699ae6f | 474 | * Get control and status registers of DS3231 |
j3 | 0:b00c4699ae6f | 475 | * |
j3 | 0:b00c4699ae6f | 476 | * On Entry: |
j3 | 2:4e6e761c60f2 | 477 | * @param[in] data - pointer to struct for storing control |
j3 | 4:0beb5e9ac927 | 478 | * and status register data |
j3 | 0:b00c4699ae6f | 479 | * |
j3 | 0:b00c4699ae6f | 480 | * On Exit: |
j3 | 0:b00c4699ae6f | 481 | * @param[out] data - contains control and status registers |
j3 | 0:b00c4699ae6f | 482 | * data |
j3 | 0:b00c4699ae6f | 483 | * @return return value = 0 on success, non-0 on failure |
j3 | 0:b00c4699ae6f | 484 | * |
j3 | 0:b00c4699ae6f | 485 | * Example: |
j3 | 0:b00c4699ae6f | 486 | * @code |
j3 | 0:b00c4699ae6f | 487 | * |
j3 | 0:b00c4699ae6f | 488 | * //instantiate rtc object |
j3 | 1:c814af60fdbf | 489 | * Ds3231 rtc(D14, D15); |
j3 | 0:b00c4699ae6f | 490 | * |
j3 | 0:b00c4699ae6f | 491 | * //do not use 0xAA, see datasheet for appropriate data |
j3 | 0:b00c4699ae6f | 492 | * ds3231_cntl_stat_t data = {0xAA, 0xAA}; |
j3 | 0:b00c4699ae6f | 493 | * |
j3 | 3:312589d8185c | 494 | * rtn_val = rtc.get_cntl_stat_reg(&data); |
j3 | 0:b00c4699ae6f | 495 | * |
j3 | 0:b00c4699ae6f | 496 | * @endcode |
j3 | 0:b00c4699ae6f | 497 | **************************************************************/ |
j3 | 2:4e6e761c60f2 | 498 | uint16_t get_cntl_stat_reg(ds3231_cntl_stat_t* data); |
j3 | 0:b00c4699ae6f | 499 | |
j3 | 0:b00c4699ae6f | 500 | |
j3 | 0:b00c4699ae6f | 501 | /**********************************************************//** |
j3 | 0:b00c4699ae6f | 502 | * Get temperature data of DS3231 |
j3 | 0:b00c4699ae6f | 503 | * |
j3 | 0:b00c4699ae6f | 504 | * On Entry: |
j3 | 0:b00c4699ae6f | 505 | * |
j3 | 0:b00c4699ae6f | 506 | * On Exit: |
j3 | 2:4e6e761c60f2 | 507 | * @return return value = raw temperature data |
j3 | 0:b00c4699ae6f | 508 | * |
j3 | 0:b00c4699ae6f | 509 | * Example: |
j3 | 0:b00c4699ae6f | 510 | * @code |
j3 | 0:b00c4699ae6f | 511 | * |
j3 | 0:b00c4699ae6f | 512 | * //instantiate rtc object |
j3 | 1:c814af60fdbf | 513 | * Ds3231 rtc(D14, D15); |
j3 | 0:b00c4699ae6f | 514 | * |
j3 | 0:b00c4699ae6f | 515 | * uint16_t temp; |
j3 | 0:b00c4699ae6f | 516 | * |
j3 | 2:4e6e761c60f2 | 517 | * temp = rtc.get_temperature(); |
j3 | 0:b00c4699ae6f | 518 | * |
j3 | 0:b00c4699ae6f | 519 | * @endcode |
j3 | 0:b00c4699ae6f | 520 | **************************************************************/ |
j3 | 2:4e6e761c60f2 | 521 | uint16_t get_temperature(void); |
j3 | 0:b00c4699ae6f | 522 | |
j3 | 5:61dfe2690360 | 523 | |
j3 | 5:61dfe2690360 | 524 | /**********************************************************//** |
j3 | 5:61dfe2690360 | 525 | * Get epoch time based on current RTC time and date. |
j3 | 5:61dfe2690360 | 526 | * DS3231 must be configured and running before this fx is |
j3 | 5:61dfe2690360 | 527 | * called |
j3 | 5:61dfe2690360 | 528 | * |
j3 | 5:61dfe2690360 | 529 | * On Entry: |
j3 | 5:61dfe2690360 | 530 | * |
j3 | 5:61dfe2690360 | 531 | * On Exit: |
j3 | 5:61dfe2690360 | 532 | * @return return value = epoch time |
j3 | 5:61dfe2690360 | 533 | * |
j3 | 5:61dfe2690360 | 534 | * Example: |
j3 | 5:61dfe2690360 | 535 | * @code |
j3 | 5:61dfe2690360 | 536 | * |
j3 | 5:61dfe2690360 | 537 | * //instantiate rtc object |
j3 | 5:61dfe2690360 | 538 | * Ds3231 rtc(D14, D15); |
j3 | 5:61dfe2690360 | 539 | * |
j3 | 5:61dfe2690360 | 540 | * time_t epoch_time; |
j3 | 5:61dfe2690360 | 541 | * |
j3 | 5:61dfe2690360 | 542 | * epoch_time = rtc.get_epoch(); |
j3 | 5:61dfe2690360 | 543 | * |
j3 | 5:61dfe2690360 | 544 | * @endcode |
j3 | 5:61dfe2690360 | 545 | **************************************************************/ |
j3 | 5:61dfe2690360 | 546 | time_t get_epoch(void); |
j3 | 5:61dfe2690360 | 547 | |
j3 | 0:b00c4699ae6f | 548 | }; |
j3 | 0:b00c4699ae6f | 549 | #endif /* DS3231_H*/ |