Fork of Ds3231 library that replaces inheritance of I2C class with a private member var of type I2C *
Dependents: ard2pmod DS3231_Alarm_Demo MAXREFDES130_131_Demo MAXREFDES130_Demo
Fork of ds3231 by
ds3231.h@3:312589d8185c, 2014-11-20 (annotated)
- Committer:
- j3
- Date:
- Thu Nov 20 21:06:57 2014 +0000
- Revision:
- 3:312589d8185c
- Parent:
- 2:4e6e761c60f2
- Child:
- 4:0beb5e9ac927
updated comments
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 | * seconds, minutes and hours |
j3 | 0:b00c4699ae6f | 218 | * |
j3 | 0:b00c4699ae6f | 219 | * On Exit: |
j3 | 0:b00c4699ae6f | 220 | * @return return value = 0 on success, non-0 on failure |
j3 | 0:b00c4699ae6f | 221 | * |
j3 | 0:b00c4699ae6f | 222 | * Example: |
j3 | 0:b00c4699ae6f | 223 | * @code |
j3 | 0:b00c4699ae6f | 224 | * |
j3 | 0:b00c4699ae6f | 225 | * //instantiate rtc object |
j3 | 1:c814af60fdbf | 226 | * Ds3231 rtc(D14, D15); |
j3 | 0:b00c4699ae6f | 227 | * |
j3 | 0:b00c4699ae6f | 228 | * ds3231_time_t time = {0, 0, 0} // time = 0:0:0 24hr format |
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 | 0:b00c4699ae6f | 282 | * //see datasheet for alarm format |
j3 | 0:b00c4699ae6f | 283 | * ds3231_alrm_t alarm = {0, 0, 0, 0, 0}; |
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 | 2:4e6e761c60f2 | 323 | * @param[in] time - pointer to struct for storing time |
j3 | 2:4e6e761c60f2 | 324 | * data; seconds, minutes and hours |
j3 | 0:b00c4699ae6f | 325 | * |
j3 | 0:b00c4699ae6f | 326 | * On Exit: |
j3 | 2:4e6e761c60f2 | 327 | * @param[out] time - contains current integrer rtc time |
j3 | 2:4e6e761c60f2 | 328 | * data |
j3 | 0:b00c4699ae6f | 329 | * @return return value = 0 on success, non-0 on failure |
j3 | 0:b00c4699ae6f | 330 | * |
j3 | 0:b00c4699ae6f | 331 | * Example: |
j3 | 0:b00c4699ae6f | 332 | * @code |
j3 | 0:b00c4699ae6f | 333 | * |
j3 | 0:b00c4699ae6f | 334 | * //instantiate rtc object |
j3 | 1:c814af60fdbf | 335 | * Ds3231 rtc(D14, D15); |
j3 | 0:b00c4699ae6f | 336 | * |
j3 | 0:b00c4699ae6f | 337 | * ds3231_time_t time = {0, 0, 0} // time = 0:0:0 24hr format |
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 | 2:4e6e761c60f2 | 352 | * calendar data; |
j3 | 0:b00c4699ae6f | 353 | * day, date, month, year |
j3 | 0:b00c4699ae6f | 354 | * |
j3 | 0:b00c4699ae6f | 355 | * On Exit: |
j3 | 2:4e6e761c60f2 | 356 | * @param[out] calendar - contains current integer rtc |
j3 | 2:4e6e761c60f2 | 357 | * calendar data |
j3 | 0:b00c4699ae6f | 358 | * @return return value = 0 on success, non-0 on failure |
j3 | 0:b00c4699ae6f | 359 | * |
j3 | 0:b00c4699ae6f | 360 | * Example: |
j3 | 0:b00c4699ae6f | 361 | * @code |
j3 | 0:b00c4699ae6f | 362 | * |
j3 | 0:b00c4699ae6f | 363 | * //instantiate rtc object |
j3 | 1:c814af60fdbf | 364 | * Ds3231 rtc(D14, D15); |
j3 | 0:b00c4699ae6f | 365 | * |
j3 | 0:b00c4699ae6f | 366 | * //see datasheet for calendar format |
j3 | 0:b00c4699ae6f | 367 | * ds3231_calendar_t calendar = {1, 1, 1, 0}; |
j3 | 0:b00c4699ae6f | 368 | * uint16_t rtn_val; |
j3 | 0:b00c4699ae6f | 369 | * |
j3 | 3:312589d8185c | 370 | * rtn_val = rtc.get_calendar(&calendar); |
j3 | 0:b00c4699ae6f | 371 | * |
j3 | 0:b00c4699ae6f | 372 | * @endcode |
j3 | 0:b00c4699ae6f | 373 | **************************************************************/ |
j3 | 2:4e6e761c60f2 | 374 | uint16_t get_calendar(ds3231_calendar_t* calendar); |
j3 | 0:b00c4699ae6f | 375 | |
j3 | 0:b00c4699ae6f | 376 | |
j3 | 0:b00c4699ae6f | 377 | /**********************************************************//** |
j3 | 0:b00c4699ae6f | 378 | * Get either Alarm1 or Alarm2 of DS3231 |
j3 | 0:b00c4699ae6f | 379 | * |
j3 | 0:b00c4699ae6f | 380 | * On Entry: |
j3 | 2:4e6e761c60f2 | 381 | * @param[in] alarm - pointer to struct for storing alarm |
j3 | 2:4e6e761c60f2 | 382 | * data; |
j3 | 0:b00c4699ae6f | 383 | * seconds, minutes, hours, day, date |
j3 | 0:b00c4699ae6f | 384 | * seconds used on Alarm1 only |
j3 | 2:4e6e761c60f2 | 385 | * |
j3 | 0:b00c4699ae6f | 386 | * @param[in] one_r_two - TRUE for Alarm1 and FALSE for |
j3 | 0:b00c4699ae6f | 387 | * Alarm2 |
j3 | 0:b00c4699ae6f | 388 | * |
j3 | 0:b00c4699ae6f | 389 | * On Exit: |
j3 | 2:4e6e761c60f2 | 390 | * @param[out] alarm - contains integer alarm data |
j3 | 0:b00c4699ae6f | 391 | * @return return value = 0 on success, non-0 on failure |
j3 | 0:b00c4699ae6f | 392 | * |
j3 | 0:b00c4699ae6f | 393 | * Example: |
j3 | 0:b00c4699ae6f | 394 | * @code |
j3 | 0:b00c4699ae6f | 395 | * |
j3 | 0:b00c4699ae6f | 396 | * //instantiate rtc object |
j3 | 1:c814af60fdbf | 397 | * Ds3231 rtc(D14, D15); |
j3 | 0:b00c4699ae6f | 398 | * |
j3 | 0:b00c4699ae6f | 399 | * //see datasheet for alarm format |
j3 | 0:b00c4699ae6f | 400 | * ds3231_alrm_t alarm = {0, 0, 0, 0, 0}; |
j3 | 0:b00c4699ae6f | 401 | * uint16_t rtn_val; |
j3 | 0:b00c4699ae6f | 402 | * |
j3 | 3:312589d8185c | 403 | * rtn_val = rtc.get_alarm(&alarm, FALSE); |
j3 | 0:b00c4699ae6f | 404 | * |
j3 | 0:b00c4699ae6f | 405 | * @endcode |
j3 | 0:b00c4699ae6f | 406 | **************************************************************/ |
j3 | 2:4e6e761c60f2 | 407 | uint16_t get_alarm(ds3231_alrm_t* alarm, bool one_r_two); |
j3 | 0:b00c4699ae6f | 408 | |
j3 | 0:b00c4699ae6f | 409 | |
j3 | 0:b00c4699ae6f | 410 | /**********************************************************//** |
j3 | 0:b00c4699ae6f | 411 | * Get control and status registers of DS3231 |
j3 | 0:b00c4699ae6f | 412 | * |
j3 | 0:b00c4699ae6f | 413 | * On Entry: |
j3 | 2:4e6e761c60f2 | 414 | * @param[in] data - pointer to struct for storing control |
j3 | 2:4e6e761c60f2 | 415 | * nd status register data |
j3 | 0:b00c4699ae6f | 416 | * |
j3 | 0:b00c4699ae6f | 417 | * On Exit: |
j3 | 0:b00c4699ae6f | 418 | * @param[out] data - contains control and status registers |
j3 | 0:b00c4699ae6f | 419 | * data |
j3 | 0:b00c4699ae6f | 420 | * @return return value = 0 on success, non-0 on failure |
j3 | 0:b00c4699ae6f | 421 | * |
j3 | 0:b00c4699ae6f | 422 | * Example: |
j3 | 0:b00c4699ae6f | 423 | * @code |
j3 | 0:b00c4699ae6f | 424 | * |
j3 | 0:b00c4699ae6f | 425 | * //instantiate rtc object |
j3 | 1:c814af60fdbf | 426 | * Ds3231 rtc(D14, D15); |
j3 | 0:b00c4699ae6f | 427 | * |
j3 | 0:b00c4699ae6f | 428 | * //do not use 0xAA, see datasheet for appropriate data |
j3 | 0:b00c4699ae6f | 429 | * ds3231_cntl_stat_t data = {0xAA, 0xAA}; |
j3 | 0:b00c4699ae6f | 430 | * |
j3 | 3:312589d8185c | 431 | * rtn_val = rtc.get_cntl_stat_reg(&data); |
j3 | 0:b00c4699ae6f | 432 | * |
j3 | 0:b00c4699ae6f | 433 | * @endcode |
j3 | 0:b00c4699ae6f | 434 | **************************************************************/ |
j3 | 2:4e6e761c60f2 | 435 | uint16_t get_cntl_stat_reg(ds3231_cntl_stat_t* data); |
j3 | 0:b00c4699ae6f | 436 | |
j3 | 0:b00c4699ae6f | 437 | |
j3 | 0:b00c4699ae6f | 438 | /**********************************************************//** |
j3 | 0:b00c4699ae6f | 439 | * Get temperature data of DS3231 |
j3 | 0:b00c4699ae6f | 440 | * |
j3 | 0:b00c4699ae6f | 441 | * On Entry: |
j3 | 0:b00c4699ae6f | 442 | * |
j3 | 0:b00c4699ae6f | 443 | * On Exit: |
j3 | 2:4e6e761c60f2 | 444 | * @return return value = raw temperature data |
j3 | 0:b00c4699ae6f | 445 | * |
j3 | 0:b00c4699ae6f | 446 | * Example: |
j3 | 0:b00c4699ae6f | 447 | * @code |
j3 | 0:b00c4699ae6f | 448 | * |
j3 | 0:b00c4699ae6f | 449 | * //instantiate rtc object |
j3 | 1:c814af60fdbf | 450 | * Ds3231 rtc(D14, D15); |
j3 | 0:b00c4699ae6f | 451 | * |
j3 | 0:b00c4699ae6f | 452 | * uint16_t temp; |
j3 | 0:b00c4699ae6f | 453 | * |
j3 | 2:4e6e761c60f2 | 454 | * temp = rtc.get_temperature(); |
j3 | 0:b00c4699ae6f | 455 | * |
j3 | 0:b00c4699ae6f | 456 | * @endcode |
j3 | 0:b00c4699ae6f | 457 | **************************************************************/ |
j3 | 2:4e6e761c60f2 | 458 | uint16_t get_temperature(void); |
j3 | 0:b00c4699ae6f | 459 | |
j3 | 0:b00c4699ae6f | 460 | }; |
j3 | 0:b00c4699ae6f | 461 | #endif /* DS3231_H*/ |