Microchip® Advanced Software Framework

Use case #1

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:

  1. PMIC for interrupt handling.
  2. Sleep Manager.
  3. 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

  1. 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.
  2. Call the init function of the PMIC driver to enable all interrupt levels:
  3. Initialize system clock:
  4. Call the init function of the sleep manager driver to be able to sleep waiting for alarm:
  5. Call RTC32 driver's own init function to initialize the 32kHz oscillator and RTC32:
  6. Set callback function to call on alarm:
  7. Enable interrupts globally:

Usage steps

Example code

Workflow

  1. 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.
  2. Sleep between each triggered alarm: