MM32 RTC学习(兼容STM32)
RTC学习
RTC简述
实时时钟是一个独立的定时器。
RTC模块拥有一组连续计数的计数器,在相应软件配置下,可提供时钟日历的功能。
修改计数器的值可以重新设置系统当前的时间和日期。
RTC模块和时钟配置系统(RCC_BDCR寄存器)处于后备区域,即在系统复位或从待机模式唤醒后, RTC的设置和时间维持不变。
思维导图

RTC框图

RTC电源框图(详细请看电源控制(PWM)章节)

认识理解
- RTC在相应软件配置下,可以提供日历功能。
- 有独立的时钟源与电源(RTC处在备份域)
- RTC与计算机的时钟相似,系统断电(关闭Vdd电源),Vbak电源供电(可以是纽扣电池),这样重启计算机时钟依旧可以显示正确。
配置简单RTC(寄存器版)(注意修改头文件)
#include "all.h"
void delay(uint32_t num)
{
uint32_t i;
for(i=0;i<num;i++);
}
void rtc_work_cfg()
{
uint32_t scaler;
uint32_t cnt;
RCC->APB1ENR |= 1<<28; //Enable the PWREN clock.
RCC->APB1ENR |= 1<<27; //Enable the PWREN clock.
PWR->CR |= 1<<8; //Enable access to the RTC and backup registers.
RCC->BDCR |= 1<<16; //Force the Backup domain reset.
RCC->BDCR &= ~(1<<16); //Release the Backup domain reset.
RCC->BDCR |= 1<<15; //Enable RTC clock.
RCC->BDCR |= 1<<8; //select LES as RTC clock source.
RCC->BDCR |= 1<<0; //External low-speed oscillar enable.
while(!(RCC->BDCR & 0x1<<1)); //External low-speed clock ready flag.
while(!(RTC->CRL & 1<<5)); //Wait until last write operation on RTC registers has finished.
RTC->CRL |= 1<<4; //Enter the RTC configuration mode.
RTC->ALRH = 0x0; //Set the RTC alarm value.
RTC->ALRL = 0x300;
RTC->PRLH = 0x0; //Set the RTC prescaler value.
RTC->PRLL = 0x10;
RTC->CNTH = 0x0; //Set the RTC counter value.
RTC->CNTL = 0x50;
RTC->CRL &= ~(1<<4); //Exit from the RTC configuration mode.
while(!(RTC->CRL & 1<<5)); //Wait until last write operation on RTC registers has finished.
while(!(RTC->CRL & 1<<3)); //wait until the RTC registers (RTC_CNT, RTC_ALR and RTC_PRL) are synchronized with RTC APB clock.
delay(1000);
cnt = RTC->CNTL;
cnt |= RTC->CNTH << 16;
scaler = RTC->PRLL;
scaler |= RTC->PRLH << 16;
delay(100);
printf_info("Prescaler = %x,cnt = %x\n",scaler,cnt);
}
void main()
{
rtc_work_cfg();
}
配置简单RTC(库函数版)(注意修改头文件)
#include "all.h"
void delay(uint32_t num)
{
uint32_t i;
for(i=0;i<num;i++);
}
void rtc_work_cfg()
{
uint32_t scaler;
uint32_t cnt;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR,ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_BKP,ENABLE);
PWR_BackupAccessCmd(ENABLE); // Enable or disables access to the RTC and backup registers.
RCC_BackupResetCmd(ENABLE);
RCC_BackupResetCmd(DISABLE);
RCC_RTCCLKCmd(ENABLE); //Enable or disables the RTC clock.
RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE); //Configure the RTC clock (RTCCLK).
RCC_LSEConfig(RCC_LSE_ON); //Configure the External Low Speed oscillator (LSE).
while(!(RCC->BDCR & 0x1<<1)); // //External low-speed clock ready flag.
RTC_WaitForLastTask(); //Wait until last write operation on RTC registers has finished.
RTC_EnterConfigMode(); //Enter the RTC configuration mode.
RTC_SetPrescaler(0x80); //Set the RTC prescaler value.
RTC_SetCounter(0x50); //Set the RTC counter value.
RTC_SetAlarm(0x150); //Set the RTC alarm value.
RTC_ExitConfigMode(); //Exit from the RTC configuration mode.
RTC_WaitForLastTask(); //Wait until last write operation on RTC registers has finished.
RTC_WaitForSynchro(); //wait until the RTC registers (RTC_CNT, RTC_ALR and RTC_PRL) are synchronized with RTC APB clock.
delay(8000);
//***************************************************
RTC_WaitForLastTask(); //Wait until last write operation on RTC registers has finished.
RTC_EnterConfigMode(); //Enter the RTC configuration mode.
RTC_SetCounter(0x500); //Set the RTC counter value.
RTC_ExitConfigMode(); //Exit from the RTC configuration mode.
RTC_WaitForLastTask(); //Wait until last write operation on RTC registers has finished.
RTC_WaitForSynchro(); //wait until the RTC registers (RTC_CNT, RTC_ALR and RTC_PRL) are synchronized with RTC APB clock.
//***************************************************
delay(8000);
cnt = RTC_GetCounter();
scaler = RTC_GetDivider();
delay(100);
printf_info("Prescaler = %x,cnt = %x\n",scaler,cnt);
}
void main()
{
rtc_work_cfg();
}
参考资料
[1]. MM32 miniboard资料
MM32 RTC学习(兼容STM32)的更多相关文章
- MM32 备份域学习(兼容STM32)
MM32 备份域学习(兼容STM32) 内容提要 备份域工作原理 备份域特性 备份域的保护:侵入检测 备份域侵入检测 备份域电源与主要内容 备份域特性 20字节数据后备寄存器(中容量和小容量产品),或 ...
- MM32看门狗学习(兼容STM32)
MM32看门狗学习(兼容STM32) IWDG独立看门狗 思维导图 IWDG框图与理解 1.独立看门狗分为两个部分,配置寄存器在1.8V供电区,计数器的核心部分在VDD供电区(即使停机/待机模式计数器 ...
- MM32初识(兼容STM32)
MM32初识(兼容STM32) 资源与开发环境 keil 5.0 MM32 miniboard 提要 stm32入门(MM32兼容) 点亮LED思路简介 GPIO配置 stm32寄存器理解与操作步骤 ...
- MM32Flash读写操作(兼容STM32)
MM32Flash读写操作(兼容STM32) Flash基础描述 思维导图 编程实现读写操作 主函数结构 #include "delay.h" #include "sys ...
- LwIP学习笔记——STM32 ENC28J60移植与入门
0.前言 去年(2013年)的整理了LwIP相关代码,并在STM32上"裸奔"成功.一直没有时间深入整理,在这里借博文整理总结.LwIP的移植过程细节很多,博文也不可能一一 ...
- TCP/IP协议学习(三) STM32中ETH驱动配置注意事项
1.MII/RMII/SMI接口连接和配置 SMI又称站点管理接口,用于cpu与外置PHY芯片通讯,配置相关参数,包含MDC和MDIO两个管脚(CPU上有对应引脚,当然用普通GPIO口模拟SMI管理也 ...
- Duanxx的STM32学习:STM32下载方式选择
前几天熟悉了STM32的启动方式.主要由Boot0和Boot1设置 如今须要解决的就是STM32的下载的问题. 一開始的时候,我选择的是SWD下载.这样的下载方式须要Boot0=0.Boot1=0.占 ...
- WEB学习-兼容问题
css选择器 儿子选择器 (IE7开始兼容,IE6不兼容.) div>p{ color:red; } div的儿子p.和div的后代p的截然不同. 能够选择: <div> <p ...
- Duanxx的STM32学习:STM32命名规则
随机推荐
- 你好,C++(11)如何用string数据类型表示一串文字?根据初始值自动推断数据类型的auto关键字(C++ 11)
3.5.2 字符串类型 使用char类型的变量我们可以表示单个字符,那么,我们又该如何表示拥有多个字符的字符串呢? 我们注意到,一个字符串是由多个字符串连起来形成的.很自然地,一种最简单直接的方法就 ...
- java计算一个月有多少天和多少周
import java.util.Calendar; /** * 功能概述:计算指定年月的天数和周数<br> * 创建时间:2010-5-17 下午05:25:58<br> * ...
- 广东移动NGBOSS系统话费查询
基于很多客户的需要 现承接广东移动NGBOSS华为系统的各项功能开发 承接广东深圳.佛山.东莞.广州.惠州.汕头.湛江移动NGBOSS的全球通开户,批量话费查询.缴费,号码导出等功能开发. 有需要者联 ...
- Math.round()、Math.ceil()、Math.floor()与Math.random()的区别?
Math.round(x) 四舍五入 加上0.5向下取整 Math.round(1.5) 2 Math.round(-11.5) -11 Math.round(-11.2) -10 Math.ceil ...
- sql如何向一个表中批量插入大量数据
--如果是一个表插入另外一个表.insert into tb1 需要的列名 select 按照前面写上需要的列名 from tb2 --如果两表结构一样.insert into tb1 * selec ...
- PartialFunction(偏函数)
val one:PartialFunction[Int,String]={ case 1 => "one" case 2 => "two" case ...
- poj Monthly Expense
http://poj.org/problem?id=3273 #include<cstdio> #include<cstring> #include<cmath> ...
- Keil C51中变量的使用
引言 8051内核单片机是一种通用单片机,在国内占有较大的市场份额.在将C语言用于51内核单片机的研究方面,Keil公司做得最为成功.由于51内核单片机的存储结构的特殊性,Keil C51中变量的使用 ...
- win2k,XP下用setupapi.dll自动安装Driver
win2k,XP下用setupapi.dll自动安装Driver 在驱网看到54cndr 写的这篇文章,虽然自己一直都用Installshield,但还是觉得这个也是一个很好的思路,故摘录在此. 用s ...
- html幻灯效果页面
方式一: <!DOCTYPE HTML> <html> <head> <style> #cont { position: relative; heigh ...