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
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
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
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
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
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
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
Define the
T_UTC_TIME
typedefault_utc_time
, and modify thedefault_utc_time
parameters.Modify the
year
parameter to configure the initial year.Modify the
month
parameter to configure the initial month.Modify the
day
parameter to configure the initial day.Modify the
hour
parameter to configure the initial hour.Modify the
minutes
parameter to configure the initial minutes.Modify the
seconds
parameter to configure the initial seconds.
Call
rtc_calendar_register_callback
to register callback to RTC calendar module.Call
rtc_calendar_int
to initialize RTC calendar module.Call
rtc_calendar_add_alarm_by_utc
to add an alarm to trigger at 10:41:20 on March 28, 2024.Call
rtc_calendar_add_alarm_by_second
to add an alarm to trigger in 5 seconds.Call
rtc_calendar_add_alarm_by_second
to add an alarm to trigger every 15 seconds.Call
bt_power_mode_set()
to set Bluetooth MAC deep sleep mode.Call
io_dlps_register()
to initialize IO store/restore and do not need to worry about which IO peripheral requires specific handling.Call
power_mode_set()
to switch the system to DLPS mode.