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. php 时间戳 总结 今日,昨日,上周,本周,最近三个月,上季,本季,去年,最近七天,今年,最近三十天

    if($time=="今日"){ $beginToday=mktime(0,0,0,date('m'),date('d'),date('Y')); $endToday=mktime ...

  2. C++简单工厂模式

    核心思想:用一个工厂类根据不同的输入条件new出不同的派生类指针,然后由多态调用不同派生类中virtual函数,得到不同的结果 所有的判断处理在工厂类中完成,通过CreateFactory函数,根据不 ...

  3. [UML]UML中几种类间关系

    UML中类间关系主要有六种,分别是继承.实现.依赖.关联.聚合.组合 1.继承 继承是指A类继承B类,继承它private除外的所有属性和方法,这种关系是最常见的关系,在java中使用extends表 ...

  4. 在linux下将当前目录文件全部小写含目录名

    ls | sed -n '/[A-Z]/s/.*/mv & \L&/e' 公司以前用的windows server 服务器  文件大小写都一样.  新迁移到centos 服务器上,发现 ...

  5. jQuery中$.get()、$.post()和$.ajax()

    jQuery.get()方法: $.get(url,data,success(response,status,xhr),dataType) 该函数是简写的 Ajax 函数,等价于: $.ajax({ ...

  6. jquery获取元素方式

    1 从集合中通过指定的序号获取元素 html: <div> <p>0</p> <p>1</p> <p>2</p> & ...

  7. Linux socket编程 DNS查询IP地址

    本来是一次计算机网络的实验,但是还没有完全写好,DNS的响应请求报文的冗余信息太多了,不只有IP地址.所以这次的实验主要就是解析DNS报文.同时也需要正确的填充请求报文.如果代码有什么bug,欢迎指正 ...

  8. MVC中的HtmlHelper

    authour: chenboyi updatetime: 2015-04-27 21:57:17 friendly link:   目录: 1,思维导图 2,CodeSimple 1.思维导图:

  9. [Android] 输入系统(三):加载按键映射

    映射表基本概念 由于Android调用getEvents得到的key是linux发送过来的scan code,而Android处理的是类似于KEY_UP这种统一类型的key code,因此需要有映射表 ...

  10. UNDO 100%

    另外查了下v$undostat,发现begin_time已经很久没有改变, BEGIN_TIME           END_TIME             MAXQUERYLEN MAXCONCU ...