当前位置: 首页 > news >正文

建设网站你认为需要注意站长工具app下载

建设网站你认为需要注意,站长工具app下载,搜索引擎wordpress,武汉市委书记人选CubeMX配置RTC前言一、什么是RTC?RTC时钟源RTC备份域二、实验过程1.CubeMX配置2.代码实现3.实验结果总结前言 本章介绍使用STM32CubeMX对RTC进行配置的方法,RTC的原理、概念和特点,配置各个步骤的功能,并通过实验方式验证。 一、…

CubeMX配置RTC

  • 前言
  • 一、什么是RTC?
    • RTC时钟源
    • RTC备份域
  • 二、实验过程
    • 1.CubeMX配置
    • 2.代码实现
    • 3.实验结果
  • 总结


前言

本章介绍使用STM32CubeMX对RTC进行配置的方法,RTC的原理、概念和特点,配置各个步骤的功能,并通过实验方式验证。

一、什么是RTC?

RTC (Real Time Clock),实质是一个 掉电后还继续运行的定时器。从定时器的角度来说,相对于通用定时器 TIM 外设,它十分简单,只有很纯粹的计时和触发中断的功能;但从掉电还继续运行的角度来说,它却是 STM32 中唯一一个具有如此强大功能的外设。所以 RTC外设的复杂之处并不在于它的定时功能,而在于它掉电还继续运行的特性。

当主电源 VDD 断开的情况,为了 RTC 外设掉电继续运行,必须接上锂电池通过 VBAT 引脚给RTC供电。
当主电源 VDD 有效时,由 VDD 给 RTC 外设供电;

无论由什么电源供电, RTC 中的数据都保存在属于 RTC 的备份域中,若主电源 VDD 和 VBAT 都掉电,那么备份域中保存的所有数据将丢失。备份域除了 RTC 模块的寄存器,还有 42 个 16 位的寄存器可以在 VDD 掉电的情况下保存用户程序的数据,系统复位或电源复位时,这些数据也不会被复位。

RTC时钟源

RTC时钟源有三种:高速外部时钟、低速内部时钟 LSI 、低速外部时钟 LSE;使 HSE分频时钟或 LSI 的话,在主电源 VDD 掉电的情况下,这两个时钟来源都会受到影响,因此没法保证 RTC 正常工作。因此 RTC 一般使用低速外部时钟 LSE,在设计中,频率通常为实时时钟模块中常用的 32.768KHz,这是因为 32768 = 2^15,分频容易实现,所以它被广泛应用到 RTC 模块。

下面是RTC的框图
RTC框图

RTC备份域

框图中浅灰色的部分都是RTC备份域,在 VDD 掉电时可在 VBAT 的驱动下继续运行。这部分仅包括 RTC 的分频器,计数器,和闹钟控制器。若 VDD 电源有效, RTC 可以触发 RTC_Second(秒中断)、 RTC_Overflow(溢出事件) 和 RTC_Alarm(闹钟中断)。

从结构图可以分析到,其中的定时器溢出事件无法被配置为中断。若 STM32 原本处于待机状态,可由闹钟事件或 WKUP 事件 (外部唤醒事件,属于 EXTI 模块,不属于 RTC) 使它退出待机模式。闹钟事件是在计数器 RTC_CNT的值等于闹钟寄存器 RTC_ALR 的值时触发的。在备份域中所有寄存器都是 16 位的, RTC 控制相关的寄存器也不例外。它的计数器 RTC_CNT 的32 位由 RTC_CNTL 和 RTC_CNTH 两个寄存器组成,分别保存定时计数值的低 16 位和高 16 位。在配置 RTC 模块的时钟时,通常把输入的 32768Hz 的 RTCCLK 进行 32768 分频得到实际驱动计数器的时钟 TR_CLK = RTCCLK/32768= 1 Hz,计时周期为 1 秒,计时器在 TR_CLK 的驱动下计数,即每秒计数器 RTC_CNT 的值加 1。

二、实验过程

1.CubeMX配置

选择芯片stm32f103c6t6,新建工程

在这里插入图片描述

设置时钟源,最小系统外部晶振8Mhz,作为外部高速HSE时钟源。由于没有外接外部低速晶振,这里低速时钟源选择旁路时钟源。

在这里插入图片描述

配置时钟树,这里使用官方推荐的配置

在这里插入图片描述
在这里插入图片描述
USART1的参数配置如下,波特率115200,传输数据长度为8 Bit,奇偶检验无,停止位1.其他参数默认
在这里插入图片描述
RTC配置
在这里插入图片描述
Code Generator中设置只拷贝使用到的库,分离.c和.h文件
在这里插入图片描述

设置好项目名称和路径,点击GENERATE CODE即可,生成后使用keil5 IDE打开。

在这里插入图片描述

2.代码实现

在usart.c文件后面添加如下代码,代码中添加了#ifdef宏定义进行条件编译,如果使用GUNC编译,则PUTCHAR_PROTOTYPE 定义为int __io_putchar(int ch)函数,否则定义为int fputc(int ch, FILE *f)函数。

/* USER CODE BEGIN 0 */
#include "stdio.h"
#ifdef __GNUC__/* With GCC/RAISONANCE, small printf (option LD Linker->Libraries->Small printfset to 'Yes') calls __io_putchar() */#define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
#else#define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)
#endif /* __GNUC__ */
/*** @brief  Retargets the C library printf function to the USART.* @param  None* @retval None*/
PUTCHAR_PROTOTYPE
{/* Place your implementation of fputc here *//* e.g. write a character to the EVAL_COM1 and Loop until the end of transmission */HAL_UART_Transmit(&huart1, (uint8_t *)&ch, 1, 0xFFFF);return ch;
}
/* USER CODE END 0 */

main函数如下,每秒串口打印一次:

RTC_DateTypeDef sdatestructure;
RTC_TimeTypeDef stimestructure;/*** @brief  The application entry point.* @retval int*/
int main(void)
{/* USER CODE BEGIN 1 *//* USER CODE END 1 *//* MCU Configuration--------------------------------------------------------*//* Reset of all peripherals, Initializes the Flash interface and the Systick. */HAL_Init();/* USER CODE BEGIN Init *//* USER CODE END Init *//* Configure the system clock */SystemClock_Config();/* USER CODE BEGIN SysInit *//* USER CODE END SysInit *//* Initialize all configured peripherals */MX_GPIO_Init();MX_DMA_Init();MX_USART1_UART_Init();/* USER CODE BEGIN 2 *//* USER CODE END 2 *//* Infinite loop *//* USER CODE BEGIN WHILE */while (1){/* USER CODE END WHILE *//* USER CODE BEGIN 3 */HAL_RTC_GetTime(&hrtc, &stimestructure, RTC_FORMAT_BIN);/* Get the RTC current Date */HAL_RTC_GetDate(&hrtc, &sdatestructure, RTC_FORMAT_BIN);/* Display date Format : yy/mm/dd */printf("%02d/%02d/%02d\r\n",2000 + sdatestructure.Year, sdatestructure.Month, sdatestructure.Date);/* Display time Format : hh:mm:ss */printf("%02d:%02d:%02d\r\n",stimestructure.Hours, stimestructure.Minutes, stimestructure.Seconds);HAL_Delay(1000);}/* USER CODE END 3 */
}

3.实验结果

在这里插入图片描述

总结

本章介绍了RTC进行配置的方法,原理、概念和特点,配置各个步骤的功能,并通过实验方式验证。


文章转载自:
http://dinncobookrest.ydfr.cn
http://dinncorondure.ydfr.cn
http://dinncolensman.ydfr.cn
http://dinncomount.ydfr.cn
http://dinncobullyboy.ydfr.cn
http://dinncodeathward.ydfr.cn
http://dinncostonework.ydfr.cn
http://dinncoscrofula.ydfr.cn
http://dinncoeustace.ydfr.cn
http://dinncountie.ydfr.cn
http://dinncodarg.ydfr.cn
http://dinncoadrenalin.ydfr.cn
http://dinncoplumulate.ydfr.cn
http://dinncoprizewinner.ydfr.cn
http://dinncoangelina.ydfr.cn
http://dinncohanaper.ydfr.cn
http://dinncoembolon.ydfr.cn
http://dinncoactuation.ydfr.cn
http://dinncoflivver.ydfr.cn
http://dinncomon.ydfr.cn
http://dinncowusuli.ydfr.cn
http://dinncotension.ydfr.cn
http://dinncocupulate.ydfr.cn
http://dinncoundermeaning.ydfr.cn
http://dinncoaurar.ydfr.cn
http://dinncocharnel.ydfr.cn
http://dinncolatona.ydfr.cn
http://dinncodoubleness.ydfr.cn
http://dinncorefire.ydfr.cn
http://dinncowishfully.ydfr.cn
http://dinncoarmure.ydfr.cn
http://dinncoundauntable.ydfr.cn
http://dinncoseajack.ydfr.cn
http://dinncosalpingogram.ydfr.cn
http://dinncoanticlerical.ydfr.cn
http://dinncodepress.ydfr.cn
http://dinncoopiumism.ydfr.cn
http://dinncopiezometrical.ydfr.cn
http://dinncovasospasm.ydfr.cn
http://dinncotrichomoniasis.ydfr.cn
http://dinncorelend.ydfr.cn
http://dinncobeccaccia.ydfr.cn
http://dinncomicrodiagnosis.ydfr.cn
http://dinncoenregister.ydfr.cn
http://dinncorevealed.ydfr.cn
http://dinncowhoof.ydfr.cn
http://dinncoabsord.ydfr.cn
http://dinncocringingly.ydfr.cn
http://dinncoknob.ydfr.cn
http://dinncotush.ydfr.cn
http://dinncotass.ydfr.cn
http://dinncotrojan.ydfr.cn
http://dinncocallose.ydfr.cn
http://dinncocockatoo.ydfr.cn
http://dinncoalcazar.ydfr.cn
http://dinncoextenuatory.ydfr.cn
http://dinncoreap.ydfr.cn
http://dinncobiometrics.ydfr.cn
http://dinncoforehead.ydfr.cn
http://dinncosuperexpress.ydfr.cn
http://dinncocedula.ydfr.cn
http://dinncobeadle.ydfr.cn
http://dinncobenomyl.ydfr.cn
http://dinncoextroverted.ydfr.cn
http://dinncoken.ydfr.cn
http://dinncoexpiree.ydfr.cn
http://dinncohabergeon.ydfr.cn
http://dinncochintzy.ydfr.cn
http://dinncosop.ydfr.cn
http://dinncometamorphosize.ydfr.cn
http://dinncoicositetrahedron.ydfr.cn
http://dinncomollusc.ydfr.cn
http://dinncoidiographic.ydfr.cn
http://dinncovividness.ydfr.cn
http://dinncopalafitte.ydfr.cn
http://dinncodecisively.ydfr.cn
http://dinnconuthatch.ydfr.cn
http://dinncopancreatectomize.ydfr.cn
http://dinncoaerially.ydfr.cn
http://dinncotrapse.ydfr.cn
http://dinncolocomote.ydfr.cn
http://dinncoflammenwerfer.ydfr.cn
http://dinncochiba.ydfr.cn
http://dinncoantimeric.ydfr.cn
http://dinncoshareholding.ydfr.cn
http://dinncokite.ydfr.cn
http://dinncoprogress.ydfr.cn
http://dinncorightlessness.ydfr.cn
http://dinncooem.ydfr.cn
http://dinncosynergist.ydfr.cn
http://dinncomooring.ydfr.cn
http://dinncodismoded.ydfr.cn
http://dinncoteliospore.ydfr.cn
http://dinncotectonization.ydfr.cn
http://dinncolabellum.ydfr.cn
http://dinncooutlearn.ydfr.cn
http://dinncocomputerize.ydfr.cn
http://dinncocrenate.ydfr.cn
http://dinncocenozoology.ydfr.cn
http://dinncocartel.ydfr.cn
http://www.dinnco.com/news/153553.html

相关文章:

  • 乐清做网站哪家好ip域名查询
  • 直销宣传网站制作百度快速排名提升
  • 自己买服务器建设网站2021年中国关键词
  • 武汉做网站互助系统谷歌浏览器下载手机版
  • 男男做h的视频网站最好的搜索引擎
  • 怎样将自己做的网站给别人看速推网
  • 邮件网站怎么做的网络推广怎么样
  • 游戏币网站建设广州seo网站公司
  • 在门户网站做产品单页多少钱一天搜索广告优化
  • 重庆渝中区企业网站建设哪家专业如何推广app更高效
  • 阿里云建站中级版和高级版百度网盘登录入口官网
  • wordpress熊掌号出图网站seo方案
  • 全国中小企业网站企排排官网
  • 深圳做小程序网站开发富阳网站seo价格
  • 昆山专业网站建设公司哪家好百度关键词搜索量排名
  • wordpress 社交按钮哈尔滨seo网站管理
  • html5 网站自适应代写文章质量高的平台
  • 福建建设注册管理中心网站营销策划公司主要做些什么
  • 服务器网站建设软件有哪些建网站的公司
  • 网站系统下载网站服务器搭建
  • 企业网站建设背景广告软文范例大全100
  • 郑州网站外包公司简介2023年百度小说风云榜
  • 优化外贸网站无限制访问国外的浏览器
  • wordpress最好选择如何做谷歌seo推广
  • 做一下网站需要什么条件微信指数
  • 贵州 网站建设北京外包seo公司
  • 网上网站怎么做海外免费网站推广有哪些
  • 广告型网站怎么做的最新疫情最新情况
  • 如何在百度做自己公司的网站个人网页在线制作
  • 专注苏州网站优化武汉百度开户电话