In this use case, the RTC is configured for:
- Clock source: 1 kHz from internal 32 kHz ULP
- Prescaling: RTC clock/1024
This use case shows how to set an alarm for the RTC.
Setup steps
Prerequisites
For the setup code of this use case to work, the following must be added to the project:
- PMIC for interrupt handling.
- Sleep Manager.
- A callback function, called alarm, that reschedules the alarm must be provided by the user:
static void alarm(uint32_t time)
{
}
Example code
Content of conf_rtc.h:
#define CONFIG_RTC_PRESCALER RTC_PRESCALER_DIV1024_gc
Needed in conf_clock.h:
#define CONFIG_RTC_SOURCE SYSCLK_RTCSRC_ULP
Add to application initialization:
Workflow
- Ensure that conf_rtc.h is present for the driver.
- Note
- This configuration file is used by the driver and should not be included by the user.
- Call the init function of the PMIC driver to enable all interrupt levels:
- Initialize system clock:
- Note
- Make sure the define CONFIG_RTC_SOURCE is defined in conf_clock.h
- Call the init function of the sleep manager driver to be able to sleep waiting for alarm:
- Call RTC driver's own init function to start up the RTC and start counting from zero:
- Set callback function to call on alarm:
- Note
- The callback function alarm must be defined by the user.
- Enable interrupts globally:
Usage steps
Example code
Workflow
- Set the alarm to trigger on next time unit roll over:
- Sleep between each triggered alarm: