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)的更多相关文章

  1. MM32 备份域学习(兼容STM32)

    MM32 备份域学习(兼容STM32) 内容提要 备份域工作原理 备份域特性 备份域的保护:侵入检测 备份域侵入检测 备份域电源与主要内容 备份域特性 20字节数据后备寄存器(中容量和小容量产品),或 ...

  2. MM32看门狗学习(兼容STM32)

    MM32看门狗学习(兼容STM32) IWDG独立看门狗 思维导图 IWDG框图与理解 1.独立看门狗分为两个部分,配置寄存器在1.8V供电区,计数器的核心部分在VDD供电区(即使停机/待机模式计数器 ...

  3. MM32初识(兼容STM32)

    MM32初识(兼容STM32) 资源与开发环境 keil 5.0 MM32 miniboard 提要 stm32入门(MM32兼容) 点亮LED思路简介 GPIO配置 stm32寄存器理解与操作步骤 ...

  4. MM32Flash读写操作(兼容STM32)

    MM32Flash读写操作(兼容STM32) Flash基础描述 思维导图 编程实现读写操作 主函数结构 #include "delay.h" #include "sys ...

  5. LwIP学习笔记——STM32 ENC28J60移植与入门

    0.前言     去年(2013年)的整理了LwIP相关代码,并在STM32上"裸奔"成功.一直没有时间深入整理,在这里借博文整理总结.LwIP的移植过程细节很多,博文也不可能一一 ...

  6. TCP/IP协议学习(三) STM32中ETH驱动配置注意事项

    1.MII/RMII/SMI接口连接和配置 SMI又称站点管理接口,用于cpu与外置PHY芯片通讯,配置相关参数,包含MDC和MDIO两个管脚(CPU上有对应引脚,当然用普通GPIO口模拟SMI管理也 ...

  7. Duanxx的STM32学习:STM32下载方式选择

    前几天熟悉了STM32的启动方式.主要由Boot0和Boot1设置 如今须要解决的就是STM32的下载的问题. 一開始的时候,我选择的是SWD下载.这样的下载方式须要Boot0=0.Boot1=0.占 ...

  8. WEB学习-兼容问题

    css选择器 儿子选择器 (IE7开始兼容,IE6不兼容.) div>p{ color:red; } div的儿子p.和div的后代p的截然不同. 能够选择: <div> <p ...

  9. Duanxx的STM32学习:STM32命名规则

随机推荐

  1. Specified VM install not found: type Standard VM, name jdk1.6.0_05

    重装系统换了jdk,之前jdk用的1.6,现在改成1.7了.但是更新之后发现ant打包用不了了,报错 Specified VM install not found: type Standard VM, ...

  2. 可以让PHP编程事半功倍的类库

    在用php开发网站的时候,使用面向对象的方法确实可以提高代码复用率,减少代码冗余.而对初学者更友好的是,PHP开发网站所需要的大部分类库,网上都有十分优秀的类库存在了.作为一个程序猿当然不能重复制造轮 ...

  3. underscorejs-contains学习

    2.12 contains 2.12.1 语法: _.contains(list, item, fromIndex, guard) 2.12.2 说明: list集合包含指定的值则返回true,否则返 ...

  4. VSS迁移

    今天花了一上午的时间,对VSS源代码库从一个服务器A上迁移到另一个服务器B上,包括修改历史.用户.以及权限.具体方法如下: 1.在服务器B上安装vss程序后,创建一database,并设置创建后的文件 ...

  5. 修改PHP的默认时区

    每个地区都有自己的本地时间,在网上及无线电通信中,时间的转换问题显得格外突出.整个地球分为24个时区,每个时区都有自己的本地时间.在国际无线电或网络通信场合,为了统一起见,使用一个统一的时间,成为通用 ...

  6. jquery 操纵 cookies 插件(1)

    当你浏览某网站时,你硬盘上会生产一个非常小的文本文件,它可以记录你的用户ID.密码.浏览过的网页.停留的时间等信息. 当你再次来到该网站时,网站通过读取Cookies,得知你的相关信息,就可以做出相应 ...

  7. ie6789和其他浏览器之间的鼠标左、中、右键的event.button不一致的办法

      左键 中键 右键 Ie6 1 4 2 Ie7 1 4 2 Ie8 1 4 2 Ie9和其它 0 1 2 以下代码将IE6/7/8的值转换成符合W3C标准的方法: var ie678 = !-[1, ...

  8. spring mvc 自定义Handlermapping

    上次大概写了个可以解决velocity 多视图的东西. 但是实际运用过程中又到处找了些资料看了下.这里 小计下: DispatcherServlet解析过程: ..1..HandlerMapping. ...

  9. 集合及特殊集合arrayList

    1,运用集合  arrayList 首先复制Colections加  : 创建arrayList ar =new arrayList(); ArrayList具体提供的功能:属性            ...

  10. js blog

    http://www.csdn.net/article/2013-12-16/2817820-javascript-survey-results 近日DailyJS社区发起了一项针对JavaScrip ...