Setting Alarms
Waspmote RTC provides two alarms to enable interruptions and wake up the device from a low-power state.
There are two different RTC alarms:
Alarm1: is set by day/date, hour, minutes and seconds.
Alarm2: is set by day/date, hour and minutes. Alarm2 is reserved for the RTC Watchdog.
There are three inputs for setting a new alarm: time, offset and mode.
Time: represents the time/date for the alarm.
Offset: represents the two modes for setting the alarm time: offset or absolute. When offset is selected, the input time is added to the actual time in the RTC and the result is set as the alarm time. When absolute is selected, the input time is set as the alarm time.
Mode: represents the different alarm modes. Alarm1 has 6 modes and Alarm2 has 5 modes.
When the time set in Alarm1 matches the RTC time, the RTC interruption pin is triggered. This pin is connected to a specific microcontroller interruption pin, so the alarm can wake up the microcontroller from a sleep mode.
An example of the functions: https://development.libelium.com/rtc-02-setting-reading-alarms/
Setting the Alarm1 (using a string as input)
It sets the Alarm1 to the specified time, offset and mode.
The input 'time' has the following format: "dd:hh:mm:ss".
The input 'offset' has some possible values:
RTC_OFFSET
: 'time' is added to the current time read from RTCRTC_ABSOLUTE
: 'time' is set as the time for Alarm1
The input 'mode' specifies the mode for Alarm1. Possible values are:
RTC_ALM1_MODE1
: Day, hours, minutes and seconds matchRTC_ALM1_MODE2
: Date, hours, minutes and seconds matchRTC_ALM1_MODE3
: Hours, minutes and seconds matchRTC_ALM1_MODE4
: Minutes and seconds matchRTC_ALM1_MODE5
: Seconds matchRTC_ALM1_MODE6
: Once per second
When this function is called, the Alarm1 is set and no more functions need to be executed.
It returns nothing, but when the Alarm1 matches the time, interruption flags will be modified to indicate it.
Example of use:
Related variables:
day_alarm1
→ stores the day or date of the Alarm1
hour_alarm1
, minute_alarm1
, second_alarm1
→ store the time of the Alarm1
Setting the Alarm1
It sets the Alarm1 to the specified time, offset and mode.
The inputs 'day_date', '_hour', '_minute' and '_second' specify the time for the Alarm1.
The input 'offset' has some possible values:
RTC_OFFSET
: 'time' is added to the current time read from RTCRTC_ABSOLUTE
: 'time' is set as the time for Alarm1
The input 'mode' specifies the mode for the Alarm1. Possible values are:
RTC_ALM1_MODE1
: Day, hours, minutes and seconds matchRTC_ALM1_MODE2
: Date, hours, minutes and seconds matchRTC_ALM1_MODE3
: Hours, minutes and seconds matchRTC_ALM1_MODE4
: Minutes and seconds matchRTC_ALM1_MODE5
: Seconds matchRTC_ALM1_MODE6
: Once per second
When this function is called, the Alarm1 is set and no more functions need to be executed.
It returns nothing, but when the Alarm1 matches the time, interruption flags will be modified to indicate it.
Example of use:
Related variables:
day_alarm1
→ stores the day or date of Alarm1
hour_alarm1
, minute_alarm1
, second_alarm1
→ store the time of Alarm1
Getting the Alarm1
It gets the Alarm1 time from RTC.
It returns a string containing this time and date for the Alarm1.
Example of use:
Related variables:
day_alarm1
→ stores the day or date of the Alarm1
hour_alarm1
, minute_alarm1
, second_alarm1
→ store the time of the Alarm1
Clear alarm flags
It clears alarm flags (A1F
and A2F
) in the RTC. The alarm flag A2F
is related to the Watchdog functionality.
If these flags are not cleared after an interrupt is captured, no more interrupts will be captured.
Example of use:
Disable alarms
There are specific functions to disable preset RTC alarms. These functions avoid the interruption to be executed.
The disableAlarm1()
function disables the RTC Alarm1.
Example of use:
Capture alarms
If an RTC alarm has been set, when the time event happens, some library flags are updated in order to know the alarm has been captured.
The general interruption register intFlag
stores the captured events. In the case of the RTC alarms, it is necessary to check the value of this register so as to identify the RTC alarm generation. For further information refer to the Interruptions Programming Guide.
Example of use:
RTC alarm example: https://development.libelium.com/rtc-06-complete-example/
Last updated