[Industrial-grade intelligent control MCU D133CBS] 7 - RTC clock test
[Copy link]
Introduction
The Real Time Clock (RTC) module is used to save and update the date and time, and provide the system with a valid date and time without a network connection. Powered by a backup battery, it can count and save time even in a power outage, and also has an alarm wake-up function. In this section, we will test the RTC clock of the D133CBS in detail.
Preparation in Advance
Before using RTC, please make sure that J9 (the red area in the figure below) has a button battery inserted and is powered normally.
Configuration steps
1- Enter the menuconfig function configuration interface in the root directory of Luban-Litescons --menuconfig and select as follows:
2- Enable the test driver of rtc in menuconfig
At this point the bsp/examples/test-rtc will be configured and added to the compilation context.
The above code is mainly used to set the RTC clock and print the set time, and is executed through Finsh.
3- Create a time printing task (avoid setting the date and time repeatedly)
We create a task to output the current time to the console every second.
#include <rtthread.h>
#include <rtdevice.h>
#include <ulog.h>
#include <finsh.h>
#include <drivers/rtc.h>
#include <drivers/alarm.h>
#include "aic_core.h"
void rtc_printf(void *agrs)
{
struct tm *local_time;
time_t now;
while (1)
{
now = time(RT_NULL);
local_time = localtime(&now);
rt_kprintf("date: %04d-%02d-%02d\n", local_time->tm_year + 1900, local_time->tm_mon + 1, local_time->tm_mday);
rt_kprintf("time: %02d:%02d:%02d\n", local_time->tm_hour, local_time->tm_min, local_time->tm_sec);
rt_thread_delay(1000);
}
}
MSH_CMD_EXPORT(rtc_printf, rtc_printf);
int main(void)
{
rt_thread_t tid = RT_NULL;
tid = rt_thread_create("RTC_read", rtc_printf, RT_NULL, 1024, 20, 5);
rt_thread_startup(tid);
return 0;
}
4- Burn the code into the development board
5- Open the console and enter test_rtc to set the date and time
6-The console outputs the current time every second
So the current time set in the development board is about 2024-11-08 01:01:33. Now I will record the current time and power off the development board, and update the time in the development board tomorrow morning in the comment area.
Historical evaluation link
[Industrial-grade intelligent control MCU D133CBS] 1 - Unboxing and environment setup https://en.eeworld.com/bbs/thread-1290588-1-1.html
[Industrial-grade intelligent control MCU D133CBS] 2 - Creating a project and its precautions https://en.eeworld.com/bbs/thread-1290861-1-1.html
[Industrial-grade intelligent control MCU D133CBS] 3 - GPIO-IO interrupt https://en.eeworld.com/bbs/thread-1290902-1-1.html
[Industrial-grade intelligent control MCU D133CBS] 4- BUG feedback (SDK lunch11 package update error) https://en.eeworld.com/bbs/thread-1290904-1-1.html
[Industrial-grade intelligent control MCU D133CBS] 5- Use RTT-software package combined with IIC to read BH1750 https://en.eeworld.com/bbs/thread-1291002-1-1.html
[Industrial-grade intelligent control MCU D133CBS] 6 - PWM output https://en.eeworld.com/bbs/thread-1291463-1-1.html
|