22.5.3 Alarm

In Gregorian and Persian modes, the RTC has five programmable fields for month, date, hours, minutes and seconds.

Each of these fields can be enabled or disabled to match the alarm condition:

  • If all the fields are enabled, an alarm flag is generated (the corresponding flag is asserted and an interrupt generated if enabled) at a given month, date, hour/minute/second.
  • If only the “seconds” field is enabled, then an alarm is generated every minute.

Depending on the fields that are enabled in Calendar Alarm register (RTC_CALALR) and Time Alarm register (RTC_TIMALR), a large number of possibilities are available to the user ranging from minutes to 365/366 days.

Note: To change one of the RTC_TIMALR.SEC, MIN, HOUR, RTC_CALALR.DATE, MONTH fields, it is recommended to disable the field before changing the value and then re-enable it after the change has been made. This requires up to three accesses to the RTC_TIMALR or RTC_CALALR. The first access clears the enable corresponding to the field to change (SECEN, MINEN, HOUREN, DATEEN, MTHEN). If the field is already cleared, this access is not required. The second access performs the change of the value (SEC, MIN, HOUR, DATE, MONTH). The third access is required to re-enable the field by writing 1 in SECEN, MINEN, HOUREn, DATEEN, MTHEN fields.

In UTC mode, RTC_TIMALR must be configured to set the UTC alarm value and bit 0 in RTC_CALALR must be used to enable or disable the UTC alarm. If the UTC alarm is enabled, the alarm is generated once the UTC time matches the programmed UTC_TIME alarm field.

To change the RTC_TIMALR.UTC_TIME alarm field, proceed as follows:

  1. Disable the UTC alarm by clearing the RTC_CALALR.UTCEN bit if it is not already cleared.
  2. Change the RTC_TIMALR.UTC_TIME value.
  3. Re-enable the UTC alarm by setting the RTC_CALALR.UTCEN bit.