当前位置:网站首页>[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);

边栏推荐
- Progress of dbnn experiment
- Go language - reflect
- Zadig + cave Iast: let safety dissolve in continuous delivery
- Mono 的执行流程
- 在线SQL转HTMLTable工具
- Linq连表查询
- Panxiaoming, senior vice president of IC nansha|amd and President of Greater China: process, architecture and platform optimization break through the computing boundary
- [kotlin] beautiful pop-up box, custom pop-up box (dialog box), extension function, chrysanthemum waiting bar, message prompt box
- keil工程,程序写多后,RTT不能打印
- Oracle set password complexity and timeout exit function
猜你喜欢

在线SQL转HTMLTable工具

Qtcreater5.15.0 source code compilation process record

Realization of 2D code generation in micro build low code

What is the difference between WMS warehouse management system and ERP

第五章 虚拟存储器 练习

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

On the necessity and solution of building a campus online teaching video convergence platform

CIN at QT (the clearest tutorial in the whole network)

2022年PMP项目管理考试敏捷知识点(4)

第三章 处理机调度练习
随机推荐
长投学堂帮忙开证券账户是安全靠谱的吗?个人如何开
邂逅阿维塔 11:强产品力下久违的新鲜感
SqlServer复习
2022 PMP project management examination agile knowledge points (4)
Wechat red envelope cover making tutorial and use guide with link jump
收藏 | VLOOKUP函数的这些妙用你都知道吗?
Fanuc robot_ Introduction to Karel programming (2)_ Usage of general IO signal
Encounter with avita 11: long lost freshness under strong product power
LeetCode 324 摆动排序 II[排序 双指针] HERODING的LeetCode之路
The Best of Many Worlds_ Dual Mirror Descent for Online Allocation Problems
设计电商秒杀系统
FANUC机器人_KAREL编程入门(2)_通用IO信号的使用方法
Huawei cloud gaussdb (for redis) unveiling issue 19: inventory of six second level capabilities
Master the usage of const
Small sample sharp weapon 2 Text confrontation + semi supervised FGSM & VAT & FGM code implementation
第三章 处理机调度练习
Realization of 2D code generation in micro build low code
[sword finger offer] 50 First character that appears only once
Is it safe to open a stock account online?
2022年PMP项目管理考试敏捷知识点(4)