Real Time Clock
Description
This is a feature present on OI-Core/OI-CoreLite (x1).
The Real Time Clock (RTC) is power from an internal battery. The lifetime of the internal 3V battery is over 60 years. The time derivation is less than ±20 ppm @ 25°C.
Code examples
#include "OpenIndus.h"
#include "Arduino.h"
#include "RTClock.h"
OICore core;
DateTime currTime;
void alarm(void)
{
printf("alarm !\n");
}
void setup(void)
{
core.rtc.begin();
core.rtc.setTime(DateTime(__DATE__, __TIME__));
currTime = core.rtc.now();
DateTime awakeTime( currTime.year(),
currTime.month(),
currTime.day(),
currTime.hour(),
currTime.minute() + 1, // set alarm in a minute
currTime.second());
core.rtc.attachRTCAlarm(alarm, NULL);
core.rtc.enableRTCAlarm();
core.rtc.setRTCAlarm(awakeTime);
}
void loop(void)
{
currTime = core.rtc.now();
printf("[%d-%d %d:%d:%d]\r\n",
currTime.day(),
currTime.month(),
currTime.hour(),
currTime.minute(),
currTime.second());
delay(1000);
}
Software API
-
class RTClock
Public Functions
-
void begin(void)
begin
-
virtual time_t time(void)
Get the current time compute by RTC Clock.
- Returns:
time_t : time since epoch in seconds.
-
virtual DateTime now(void)
Get the current time compute by RTC Clock.
- Returns:
DateTime : current time.
-
virtual void setTime(time_t time)
Set the time of internal RTC Clock.
Note
Must be used with care, RTC Time is setted during factory calibration
- Parameters:
time – [in] Current time since epoch in seconds
-
virtual void setTime(DateTime datetime)
Set the time of internal RTC Clock.
Note
Must be used with care, RTC Time is setted during factory calibration
- Parameters:
datetime – [in] Current date in a DateTime object format
-
virtual void enableRTCAlarm(void)
Enable RTC Alarm.
Note
A callback must be registedred before calling this function.
See attachRTCAlarm function.
-
virtual void disableRTCAlarm(void)
Disable RTC Alarm.
-
virtual void setRTCAlarm(time_t alarm)
Set the time for next RTC Alarm.
Note
If no callback has been registered, nothing will happens.
- Parameters:
alarm – [in] Time since epoch in seconds
-
virtual void setRTCAlarm(DateTime alarm)
Set the time for next RTC Alarm.
Note
If no callback has been registered, nothing will happens.
- Parameters:
alarm – [in] Alarm in a DateTime object format
-
virtual void attachRTCAlarm(void (*callback)(void), void *args = NULL)
Attach a user callback to the RTC Alarm interrupt.
- Parameters:
callback – function to attach
args – optional function arguments
-
virtual void detachRTCAlarm(void)
Detach the RTC interrupt handler if exists.
-
void begin(void)