RT-Thread learning record
1. New Studio Project
2. Brief description of console usage
3. PIN device framework learning
4.UART device framework learning
5.I2C device framework learning
6. SPI device framework learning
RTC Device
First, check the RTC driver framework under the Components setting. There are two options here, use the alarm and turn on the simulated RTC. The STM32 with hardware RTC can be used directly without simulation, as shown below:
Then check the RTC device routine under the Samples setting and save it. As shown in the figure below, you can see that the routine has been added to the project.
/*
* Copyright (c) 2006-2018, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2018-11-30 misonyo first implementation.
*/
/*
* Program Listing: This is a RTC device usage routine
* The routine exports the rtc_sample command to the control terminal
* Command calling format: rtc_sample
* Program function: Set the date and time of the RTC device, obtain the current time after a delay and print it out.
*/
#include <rtthread.h>
#include <rtdevice.h>
static int rtc_sample(int argc, char *argv[])
{
rt_err_t ret = RT_EOK;
time_t now;
/* Set the date */
ret = set_date(2018, 12, 3);
if (ret != RT_EOK)
{
rt_kprintf("set RTC date failed\n");
return ret;
}
/* Set time */
ret = set_time(11, 15, 50);
if (ret != RT_EOK)
{
rt_kprintf("set RTC time failed\n");
return ret;
}
/* Delay 3 seconds */
rt_thread_mdelay(3000);
/* Get time */
now = time(RT_NULL);
rt_kprintf("%s\n", ctime(&now));
return ret;
}c
/* Export to msh command list */
MSH_CMD_EXPORT(rtc_sample, rtc sample)
;
Then, in the RTC CONFIG section of the board.h file, enable RTC driver support.
Save, compile, and run. You can see that the routine sets the RTC time and prints it. We can also view the current time through the date command and update the time with parameters.
The above is the instructions for using the RTC device
This content is originally created by EEWORLD forum user ID.LODA. If you want to reprint or use it for commercial purposes, you must obtain the author's consent and indicate the source