ArduinoLibs
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
DS3231RTC.h
1 /*
2  * Copyright (C) 2012 Southern Storm Software, Pty Ltd.
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included
12  * in all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20  * DEALINGS IN THE SOFTWARE.
21  */
22 
23 /*
24  * Adapted from DS3232RTC library for DS3231 RTC chip by Thijs Oppermann
25  * 2014-12-07
26  */
27 
28 #ifndef DS3231RTC_h
29 #define DS3231RTC_h
30 
31 #include "RTC.h"
32 
33 class I2CMaster;
34 
35 class DS3231RTC : public RTC {
36  public:
37  DS3231RTC(I2CMaster &bus, uint8_t oneHzPin = 255);
38 
39  bool isRealTime() const {
40  return _isRealTime;
41  }
42 
43  bool hasUpdates();
44 
45  void readTime(RTCTime* value);
46  void readDate(RTCDate* value);
47 
48  void writeTime(const RTCTime* value);
49  void writeDate(const RTCDate* value);
50 
51  void readAlarm(uint8_t alarmNum, RTCAlarm* value);
52  void writeAlarm(uint8_t alarmNum, const RTCAlarm* value);
53  bool setAlarm(uint8_t alarmNum, const RTCAlarm* value);
54 
55  int readTemperature();
56 
57  void enableAlarmInterrupts();
59  int firedAlarm();
60 
61  void enable32kHzOutput();
62  void disable32kHzOutput();
63 
64  void enableAlarm(uint8_t alarmNum);
65  void disableAlarm(uint8_t alarmNum);
66 
67  private:
68  I2CMaster* _bus;
69  uint8_t _oneHzPin;
70  bool prevOneHz;
71  bool _isRealTime;
72  bool alarmInterrupts;
73 
74  void alarmSecondValues(uint8_t read_value, RTCAlarm* value);
75  void alarmMinuteValues(uint8_t read_value, RTCAlarm* value);
76  void alarmHourValues(uint8_t read_value, RTCAlarm* value);
77  void alarmDayValues(uint8_t read_value, RTCAlarm* value);
78 
79  uint8_t getAlarmDayValue(const RTCAlarm* value);
80 
81  void clearAlarm(uint8_t alarmNum);
82 
83  uint8_t readRegister(uint8_t reg);
84  bool writeRegister(uint8_t reg, uint8_t value);
85 };
86 
87 #endif
void enable32kHzOutput()
Enables the 32 kHz output on the DS3231 chip.
Definition: DS3231RTC.cpp:562
void disableAlarmInterrupts()
Disables the generation of interrupts for alarms 0 and 1.
Definition: DS3231RTC.cpp:508
void readDate(RTCDate *value)
Reads the current date from the realtime clock into value.
Definition: DS3231RTC.cpp:228
int readTemperature()
Reads the value of the temperature sensor and returns the temperature in quarters of a degree celcius...
Definition: DS3231RTC.cpp:470
void enableAlarmInterrupts()
Enables the generation of interrupts for alarms 0 and 1.
Definition: DS3231RTC.cpp:494
Communicates with a DS3231 realtime clock chip via I2C.
Definition: DS3231RTC.h:35
bool isRealTime() const
Returns true if the realtime clock is on the I2C bus; false if the time and date are simulated...
Definition: DS3231RTC.h:39
void enableAlarm(uint8_t alarmNum)
Enables a specific alarm.
Definition: DS3231RTC.cpp:606
Stores date information from a realtime clock chip.
Definition: RTC.h:35
void readAlarm(uint8_t alarmNum, RTCAlarm *value)
Reads the details of the alarm with index alarmNum into value.
Definition: DS3231RTC.cpp:280
DS3231RTC(I2CMaster &bus, uint8_t oneHzPin=255)
Attaches to a realtime clock slave device on bus.
Definition: DS3231RTC.cpp:125
void disableAlarm(uint8_t alarmNum)
Disables a specific alarm.
Definition: DS3231RTC.cpp:625
bool setAlarm(uint8_t alarmNum, const RTCAlarm *value)
Sets the alarm with index alarmNum from value.
Definition: DS3231RTC.cpp:408
void writeDate(const RTCDate *value)
Updates the date in the realtime clock to match value.
Definition: DS3231RTC.cpp:266
void writeAlarm(uint8_t alarmNum, const RTCAlarm *value)
Updates the details of the alarm with index alarmNum from value.
Definition: DS3231RTC.cpp:374
void disable32kHzOutput()
Disables the 32 kHz output on the DS3231 chip.
Definition: DS3231RTC.cpp:575
Stores time information from a realtime clock chip.
Definition: RTC.h:28
void writeTime(const RTCTime *value)
Updates the time in the realtime clock to match value.
Definition: DS3231RTC.cpp:252
Abstract base class for I2C master implementations.
Definition: I2CMaster.h:28
Stores alarm information from a realtime clock chip.
Definition: RTC.h:42
bool hasUpdates()
Returns true if there are updates.
Definition: DS3231RTC.cpp:166
void readTime(RTCTime *value)
Reads the current time from the realtime clock into value.
Definition: DS3231RTC.cpp:207
int firedAlarm()
Determines which of alarms 0 or 1 have fired since the last call.
Definition: DS3231RTC.cpp:530
Base class for realtime clock handlers.
Definition: RTC.h:52