当前位置:网站首页>[stm32 Hal library] RTC and BKP drives
[stm32 Hal library] RTC and BKP drives
2022-06-28 23:09:00 【おもいね】
CubeMX To configure
Turn on the external clock

Activate the clock and calendar

change RCC The clock is an external low-speed clock

Above in CubeMX The configuration in has been completed , Click generate code .
4. Here I need to use the serial port for debugging , Therefore, the serial port 1 is opened 
Engineering modification
After the above configuration ,RCC It can run normally , But when the MCU is reset ,RCC The clock will clear , This is not in line with our purpose .
therefore , stay RCC We add these two lines of code to the initialization function :
Turn on BKP Standby register clock and cancel its write protection .
Then we add 55 That's ok 56 That's ok 57 Row sum 83 Line code to judge whether the time is set for the first time , If it is the first time to initialize the time , Then change the flag bit , After that, do it anyway , Reset , Turn off the power , This flag bit will not change .
Realize the basic time travel and read
- Define two structures for saving time and data in the main function , And configure data such as time and date

- Write time data
HAL_RTC_SetTime(&hrtc, &RtcTime, RTC_FORMAT_BIN)
HAL_RTC_SetDate(&hrtc, &RtcDate, RTC_FORMAT_BIN)
- Read time data
HAL_RTC_GetTime(&hrtc, &RtcTime,RTC_FORMAT_BIN);
HAL_RTC_GetDate(&hrtc, &RtcDate,RTC_FORMAT_BIN);

边栏推荐
猜你喜欢
随机推荐
Code example of hiredis
浅析搭建校园在线教学视频汇聚平台的必要性及解决方案
超级工厂里的生意图鉴
How to use London gold to draw support resistance line
网上办理股票开户安全性高吗?
Undefined symbol main (referred from entry9a.o).
lock4j--分布式锁中间件--使用/实例
他原来是这么刷题的!
老家出资,俞敏洪设立两支基金
【深度学习】(3) Transformer 中的 Encoder 机制,附Pytorch完整代码
C interview questions_ 20220627 record
flowable 边界定时器
[stm32 HAL库] 串口通信
keil工程,程序写多后,RTT不能打印
【kotlin】好看的弹出框、自定义弹出框(对话框)、扩展函数、菊花等待条、消息提示框
Is it safe and reliable for changtou school to help open a securities account? How to drive
月薪6万,互联网“降本增效”后,这类人开始被疯抢
frameworks/base/core/res/res/values/symbols.xml:3915: error: no definition for declared symbol解决办法
C# 面试题目_20220627记录一下
全面掌握const的用法《一》








![[stm32 HAL库] 串口通信](/img/2c/23a2ecf75141b8f38ab99ac6b2eaef.png)