RTC Calendar

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

Requirements

For hardware requirements, please refer to the Requirements.

Configurations

  1. 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_calendar_demo();
    

Building and Downloading

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

Experimental Verification

  1. Press the Reset button on the EVB, print the following log in Debug Analyzer.

    rtc_calendar_int: year 2024, month 3, day 28, hour 10, minute 41, second 0
    
  2. After 5 seconds, print the information of ALARM_1 in Debug Analyzer.

    alarm_callback: alarm 1 year 2024, month 3, day 28, hour 10, minute 41, second 5
    
  3. Print the time information log in Debug Analyzer every 10 seconds.

    rtc_callback: year xx, month xx, day xx, hour xx, minute xx, second xx
    
  4. Print the information of ALARM_2 in Debug Analyzer every 15 seconds.

    alarm_callback: alarm 2 year xx, month xx, day xx, hour xx, minute xx, second xx
    
  5. After 20 seconds, print the information of ALARM_0 in Debug Analyzer.

    alarm_callback: alarm 0 year 2024, month 3, day 28, hour 10, minute 41, second 20
    

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\calendar_demo\rtc_calendar_demo.c.

Initialization

  1. Define the T_UTC_TIME type default_utc_time, and modify the default_utc_time parameters.

    1. Modify the year parameter to configure the initial year.

    2. Modify the month parameter to configure the initial month.

    3. Modify the day parameter to configure the initial day.

    4. Modify the hour parameter to configure the initial hour.

    5. Modify the minutes parameter to configure the initial minutes.

    6. Modify the seconds parameter to configure the initial seconds.

  2. Call rtc_calendar_register_callback to register callback to RTC calendar module.

  3. Call rtc_calendar_int to initialize RTC calendar module.

  4. Call rtc_calendar_add_alarm_by_utc to add an alarm to trigger at 10:41:20 on March 28, 2024.

  5. Call rtc_calendar_add_alarm_by_second to add an alarm to trigger in 5 seconds.

  6. Call rtc_calendar_add_alarm_by_second to add an alarm to trigger every 15 seconds.

  7. Call bt_power_mode_set() to set Bluetooth MAC deep sleep mode.

  8. Call io_dlps_register() to initialize IO store/restore and do not need to worry about which IO peripheral requires specific handling.

  9. Call power_mode_set() to switch the system to DLPS mode.