RTC Overflow Function

This sample code guide is designed to help users easily and comprehensively understand RTC sample. This sample demonstrates RTC count overflow 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_overflow_demo();
    

Building and Downloading

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

Experimental Verification

Preparation Phase

Press the Reset button on the EVB, when the RTC counts to the maximum value, it will trigger an RTC interrupt:

  • For RTL87x3D, rtc_handler function is executed every 134217.728s.

  • For RTL87x3E and RTL87x3EP, rtc_handler function is executed every 524.288s.

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\overflow\rtc_overflow_demo.c.

Initialization

The initialization flow for peripherals can refer to Initialization Flow.

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

../../../_images/RTC_Overflow_Function_Initialization_Flow_Chart.png

RTC Overflow 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 overflow interrupt _RTC_INT::RTC_INT_OVF.

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

  5. 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_2.png

RTC Interrupt Handle Flow Chart

When the RTC counts to the maximum value, it will trigger an RTC interrupt:

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

  2. Call RTC_ClearOverFlowINT() to clear the RTC overflow interrupt.