This use case shows how to set an alarm for the RTC32.
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)
{
}
- Note
- Since the next alarm will be rounded up to the next second pass, this will actually happen in 3 seconds.
Example code
Add to application initialization:
Workflow
- Ensure that conf_rtc32.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:
- Call the init function of the sleep manager driver to be able to sleep waiting for alarm:
- Call RTC32 driver's own init function to initialize the 32kHz oscillator and RTC32:
- 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:
-
- Note
- The lowest value which is safe to use is 3. The use of 2 could happen in a second change, and we would not get an interrupt. A value of 3 causes the alarm to be set of in 3-4 seconds.
- Sleep between each triggered alarm: