RTC Tick Function

This sample code guide is designed to help users easily and comprehensively understand RTC sample. This sample demonstrates RTC tick function.

Requirements

For hardware requirements, please refer to the Requirements.

Configurations

  1. The following macros can be configured to modify the RTC prescaler value.

    • #define RTC_PRESCALER_VALUE     0

  2. The entry function is as follows, call this function in main() to run this sample code. For more details, please refer to the Initialization.

    rtc_tick_demo();
    

Building and Downloading

For building and downloading, please refer to the Building and Downloading.

Experimental Verification

Press the Reset button on the EVB, after the tick time (31.25us), trigger an RTC interrupt.

Code Overview

This section introduces the code and process description for initialization and corresponding function implementation in the sample.

Source Code Directory

  • For project directory, please refer to Source Code Directory.

  • Source code directory: sdk\src\sample\io_demo\rtc\tick\rtc_tick_demo.c.

Initialization

The initialization flow for peripherals can refer to Initialization Flow.

RTC tick function initialization flow is shown in the following figure.

../../../_images/RTC_Tick_Function_Initialization_Flow_Chart.png

RTC Tick Function Initialization Flow Chart

  1. Call RTC_DeInit() to reset the RTC peripheral.

  2. Call RTC_SetPrescaler() to set the RTC prescaler.

  3. Call RTC_MaskINTConfig() to unmask the RTC tick interrupt _RTC_INT::RTC_INT_TICK.

  4. Call RTC_TickINTConfig() to enable the RTC tick interrupt.

  5. Call NVIC_Init() to enable NVIC of RTC.

  6. Call RTC_RunCmd() to enable the RTC.

Functional Implementation

Interrupt Handle

RTC interrupt handle flow is shown in the following figure.

../../../_images/RTC_Interrupt_Handle_Flow_Chart_3.png

RTC Interrupt Handle Flow Chart

Every time the tick timer expires, it will trigger an RTC interrupt:

  1. Call RTC_GetINTStatus() to check _RTC_INT::RTC_INT_TICK interrupt status flag.

  2. Call RTC_ClearTickINT() to clear the RTC tick interrupt.