今天总结RTC(Real Time Clock)实时时钟相关的知识。在进行RTC的讲解前,我先对BKP进行一个简单的讲解。
STM32的RTC模块和时钟配置系统(RCC_BDCR寄存器)处于后备区域,即在系统复位或从待机模式唤醒后, RTC的设置和时间维持不变。
STM32F0的RTC模块和F3的RTC模块最大区别在于F0模块中有“DATE”和“TIME”寄存器,也就是可以直接读取寄存器里面的值,而F3是秒计数寄存器的值,需要通过相关算法下才能得到时间的值。
本文提供的软件工程里面用到BKP的配置,主要是用于掉电保持RTC数值(第一次上电初始化RTC,后面就不用初始化)。例程是在第一次初始化RTC值为:2016年2月29日 周一 23:59:45(自己可修改)。之后每秒读取一次,并通过串口打印出来。这里可以设置秒中断,不用软件等待1秒才去读取。
<strong>1、概述</strong>
<center><img src="http://mouser.eetrend.com/files/2017-06/%E5%8D%9A%E5%AE%A2/100006609-20…; alt=“” width="600"></center>
通过RTC时钟进来分频之后达到1秒(1Hz),没相应一次时间更新RTC时钟寄存器(RTC_TR、RTC_DR),我们读取的数字就会更改。如果配置了中断,相应事件的时候,中断也会响应。如果配置了闹钟,同样达到了闹钟设定的值也会响应闹钟。
RTC的时钟源有3个:LSE(32.768kHz);LSI(40kHz);HSE/32。
<center><img src="http://mouser.eetrend.com/files/2017-06/%E5%8D%9A%E5%AE%A2/100006609-20…; alt=“” width="600"></center>
<strong>2、准备工作</strong>
1)查看STM32f030x数据手册
2)了解USART的运行原理
3)查看STM32F030开发板原理图和封装图
4)电脑装有keil等编译软件
<strong>3、寄存器说明</strong>
<strong>RTC 时间寄存器 (RTC_TR) </strong>
<center><img src="http://mouser.eetrend.com/files/2017-06/%E5%8D%9A%E5%AE%A2/100006609-20…; alt=“” width="600"></center>
<strong>RTC 日期寄存器 (RTC_DR)</strong>
<center><img src="http://mouser.eetrend.com/files/2017-06/%E5%8D%9A%E5%AE%A2/100006609-20…; alt=“” width="600"></center>
RTC 控制寄存器 (RTC_CR)
<center><img src="http://mouser.eetrend.com/files/2017-06/%E5%8D%9A%E5%AE%A2/100006609-20…; alt=“” width="600"></center>
<center><img src="http://mouser.eetrend.com/files/2017-06/%E5%8D%9A%E5%AE%A2/100006609-20…; alt=“” width="600"></center>
<center><img src="http://mouser.eetrend.com/files/2017-06/%E5%8D%9A%E5%AE%A2/100006609-20…; alt=“” width="600"></center>
RTC 初始化和状态寄存器 (RTC_ISR)
<center><img src="http://mouser.eetrend.com/files/2017-06/%E5%8D%9A%E5%AE%A2/100006609-20…; alt=“” width="600"></center>
<center><img src="http://mouser.eetrend.com/files/2017-06/%E5%8D%9A%E5%AE%A2/100006609-20…; alt=“” width="600"></center>
RTC 预分频器寄存器 (RTC_PRER)
<center><img src="http://mouser.eetrend.com/files/2017-06/%E5%8D%9A%E5%AE%A2/100006609-20…; alt=“” width="600"></center>
RTC alarm A 寄存器 (RTC_ALRMAR)
<center><img src="http://mouser.eetrend.com/files/2017-06/%E5%8D%9A%E5%AE%A2/100006609-20…; alt=“” width="600"></center>
<center><img src="http://mouser.eetrend.com/files/2017-06/%E5%8D%9A%E5%AE%A2/100006609-20…; alt=“” width="600"></center>
RTC 亚秒寄存器 (RTC_SSR)
<center><img src="http://mouser.eetrend.com/files/2017-06/%E5%8D%9A%E5%AE%A2/100006609-20…; alt=“” width="600"></center>
RTC 移位控制寄存器 (RTC_SHIFTR)
<center><img src="http://mouser.eetrend.com/files/2017-06/%E5%8D%9A%E5%AE%A2/100006609-20…; alt=“” width="600"></center>
RTC 写保护寄存器 (RTC_WPR)
<center><img src="http://mouser.eetrend.com/files/2017-06/%E5%8D%9A%E5%AE%A2/100006609-20…; alt=“” width="600"></center>
RTC 校准寄存器 (RTC_CALR)
<center><img src="http://mouser.eetrend.com/files/2017-06/%E5%8D%9A%E5%AE%A2/100006609-20…; alt=“” width="600"></center>
<center><img src="http://mouser.eetrend.com/files/2017-06/%E5%8D%9A%E5%AE%A2/100006609-20…; alt=“” width="600"></center>
RTC 侵入和复用功能配置寄存器 (RTC_TAFCR)
<center><img src="http://mouser.eetrend.com/files/2017-06/%E5%8D%9A%E5%AE%A2/100006609-20…; alt=“” width="600"></center>
<center><img src="http://mouser.eetrend.com/files/2017-06/%E5%8D%9A%E5%AE%A2/100006609-20…; alt=“” width="600"></center>
<center><img src="http://mouser.eetrend.com/files/2017-06/%E5%8D%9A%E5%AE%A2/100006609-20…; alt=“” width="600"></center>
<center><img src="http://mouser.eetrend.com/files/2017-06/%E5%8D%9A%E5%AE%A2/100006609-20…; alt=“” width="600"></center>
RTC 备份寄存器 (RTC_BKPxR)
<center><img src="http://mouser.eetrend.com/files/2017-06/%E5%8D%9A%E5%AE%A2/100006609-20…; alt=“” width="600"></center>
<strong>4、RTC配置</strong>
①代码讲解
<center><img src="http://mouser.eetrend.com/files/2017-06/博客/100006609-20771-dm1.jpg" alt=“” width="600"></center>
<center><img src="http://mouser.eetrend.com/files/2017-06/博客/100006609-20782-dm2.jpg" alt=“” width="600"></center>
<center><img src="http://mouser.eetrend.com/files/2017-06/博客/100006609-20783-dm3.jpg" alt=“” width="600"></center>
<center><img src="http://mouser.eetrend.com/files/2017-06/博客/100006609-20784-dm4.jpg" alt=“” width="600"></center>
本文转载自<a href="http://blog.csdn.net/qq_29653157/article/details/70052354">晗生缘</a>