当前位置:网站首页>[stm32 HAL库] RTC和BKP驱动
[stm32 HAL库] RTC和BKP驱动
2022-06-28 23:04:00 【おもいね】
CubeMX 配置
打开外部时钟

激活时钟和日历

更改RCC时钟为外部低速时钟

以上在CubeMX中的配置就已经完成,点击生成代码即可。
4.这里我需要使用串口进行调试,因此打开了串口一
工程修改
以上配置后,RCC可以正常走时运行,但是当单片机复位后,RCC时钟会清零,这可不符合我们的目的。
因此,在RCC初始化函数中我们添加这两行代码:
开启BKP备用寄存器时钟和取消其写保护。
之后在我们添加55行56行57行和83行代码进行是否第一次设置时间进行判断,如果是第一次进行时间的初始化,然后将标志位改变,之后无论如何操作,复位,关闭电源,这个标志位都不会改变。
实现基本时间走时并读取
- 在主函数中定义两个保存时间和数据的结构体,并配置时间和日期等数据

- 写入时间数据
HAL_RTC_SetTime(&hrtc, &RtcTime, RTC_FORMAT_BIN)
HAL_RTC_SetDate(&hrtc, &RtcDate, RTC_FORMAT_BIN)
- 读取时间数据
HAL_RTC_GetTime(&hrtc, &RtcTime,RTC_FORMAT_BIN);
HAL_RTC_GetDate(&hrtc, &RtcDate,RTC_FORMAT_BIN);

边栏推荐
- [sword finger offer] 50 First character that appears only once
- Online sql to htmltable tool
- Go language - reflect
- C語言-單詞分析解析
- Tanghongbin, Yaya live CTO: to truly localize, the product should not have the attribute of "origin"
- Explanation: Luogu p1762 even number /6.21 internal examination T2
- Fanuc robot_ Introduction to Karel programming (2)_ Usage of general IO signal
- Lost in cloud computing
- Websocket for im instant messaging development: concept, principle and common sense of mistakes
- Basic knowledge diagram of K-line Diagram -- meaning of single K-line
猜你喜欢

第五章 虚拟存储器 练习

Online sql to htmltable tool

Multiomics single cell data integration and regulatory reasoning based on graph linked embedding

两栏布局左边图片显示部分由右边内容高度决定

笔记

第四章 存储器管理练习

Keil project, RTT cannot print after too many programs are written

Pytorch builds transformer to realize multivariable and multi step time series forecasting (load forecasting)

Online text filter less than specified length tool

月薪6万,互联网“降本增效”后,这类人开始被疯抢
随机推荐
Websocket for im instant messaging development: concept, principle and common sense of mistakes
One card can sell tens of millions, and the business expansion is faster than that of players: you don't understand the Jianghu of star cards
【Flutter 问题系列第 71 篇】Flutter 中 Uint8List 和 Image 之间的相互转换
一文读懂,WMS仓储管理系统与ERP有什么区别
Tanghongbin, Yaya live CTO: to truly localize, the product should not have the attribute of "origin"
Prometeus 2.36.0 new features
Is it safe and reliable for changtou school to help open a securities account? How to drive
CIN at QT (the clearest tutorial in the whole network)
Huawei cloud gaussdb (for redis) unveiling issue 19: inventory of six second level capabilities
C language - word analysis
他原来是这么刷题的!
【Flutter 問題系列第 71 篇】Flutter 中 Uint8List 和 Image 之間的相互轉換
A password error occurred when docker downloaded the MySQL image to create a database link
两栏布局左边图片显示部分由右边内容高度决定
全面掌握const的用法《一》
复杂嵌套的对象池(4)——管理多类实例和多阶段实例的对象池
What is the difference between WMS warehouse management system and ERP
k线图基础知识图解——单根K线的含义
生产环境sonarqube安装
老家出资,俞敏洪设立两支基金