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. KB006: CSS 框模型( Box module )

    框和布局 在 KB005: CSS 层叠 中已经介绍了 CSS 的重要之处.CSS 可以说是页面表现的基础, CSS 可以控制布局,控制元素的渲染. 布局是讲在电影画面构图中,对环境的布置.人物地位的 ...

  2. 理解javascript之 对象

    大纲: 1.介绍attribute property的异同,翻译自http://javascript.info/tutorial/attributes-and-custom-properties#pr ...

  3. 模块化的JavaScript开发的优势在哪里

    如今模块化的 JavaScript 的开发越来越火热,无论是模块加载器还是优秀的 JavaScript 模块,都是层出不穷.既然这么火,肯定是有存在的理由,肯定是解决了某些实际问题.很多没接触过模块化 ...

  4. jQuery 选择器和JavaScript 选择器的技巧与异常原因

    jquery的选择器借鉴了css选择器,核心依然依靠JavaScript的getElementById()和getElementsByTagName()方法,但是他封装了2个方法,让jquery选择器 ...

  5. JQUERY1.9学习笔记 之基本过滤器(十) 非选择器

    非选择器jQuery( ":not(selector)" ) 例:找出所有input标签为非"checked"的,并且高亮其邻居元素span. <!DOC ...

  6. 用soaplib的django webserver

    前面写过怎么利用suds来调用webservicePython调用基于https协议的SOAP WebService,这篇讲的是如何用soaplib开发SOAP WebService(最近发现国外开源 ...

  7. Chapter 2. OpenSSL的安装和配置学习笔记

    Chapter 2. OpenSSL的安装和配置学习笔记 2.1 在linux上面安装OpenSSL我还是做点No paper事情比较在行,正好和老师的课程接轨一下.以前尝试过在Windows上面安装 ...

  8. ISO7816 传输协议 T0 T1

    T=0协议不能用一条命令来实现,必须分为两步实现:第一条命令为卡片提供数据,然后用另外一条相关的命令来取回数据.这样给卡片的编程带来很大麻烦,同时卡片内存中必须保留上一次操作需要返回的数据.这时如果不 ...

  9. sphinx,github和readthedocs配合使用

    http://daler.github.io/sphinxdoc-test/includeme.html http://pages.github.com/ http://www.lulinfeng.c ...

  10. COJ 3016 WZJ的图论问题

    传送门:http://oj.cnuschool.org.cn/oj/home/problem.htm?problemID=1046 试题描述: WZJ又有一个问题想问问大家.WZJ用数据生成器生成了一 ...