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.

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 RTC
  • RTC_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 match
  • RTC_ALM1_MODE2: Date, hours, minutes and seconds match
  • RTC_ALM1_MODE3: Hours, minutes and seconds match
  • RTC_ALM1_MODE4: Minutes and seconds match
  • RTC_ALM1_MODE5: Seconds match
  • RTC_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:
1
{
2
// Example: Sets Alarm1 for 29th of the month at 11:00:00
3
RTC.setAlarm1(29:11:00:00, RTC_ABSOLUTE, RTC_ALM1_MODE2 );
4
5
// Example: Sets Alarm1 for 5 minutes from now
6
RTC.setAlarm1(00:00:05:00, RTC_OFFSET, RTC_ALM1_MODE4 );
7
}
Copied!
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 RTC
  • RTC_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 match
  • RTC_ALM1_MODE2: Date, hours, minutes and seconds match
  • RTC_ALM1_MODE3: Hours, minutes and seconds match
  • RTC_ALM1_MODE4: Minutes and seconds match
  • RTC_ALM1_MODE5: Seconds match
  • RTC_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:
1
{
2
// Example: Sets Alarm1 for 29th of the month at 11:00:00
3
RTC.setAlarm1( 29,11,0,0, RTC_ABSOLUTE, RTC_ALM1_MODE2 );
4
5
// Example: Sets Alarm1 for 5 minutes from now
6
RTC.setAlarm1( 0,0,5,0, RTC_OFFSET, RTC_ALM1_MODE4 );
7
}
Copied!
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:
1
{
2
// Gets time for Alarm1
3
USB.println(RTC.getAlarm1());
4
}
Copied!
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:
1
{
2
RTC.clearAlarmFlag();
3
}
Copied!

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:
1
{
2
RTC.disableAlarm1();
3
}
Copied!

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:
1
{
2
if (intFlag & RTC_INT)
3
{
4
// RTC captured
5
}
6
}
Copied!