#include "RTC_Alarm.h"
//RTC中断配置
static void RTC_NVIC_Config(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
NVIC_InitStructure.NVIC_IRQChannel = RTC_IRQn; //RTC全局中断
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 3; //先占优先级1位,从优先级3位
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //使能该通道中断
NVIC_Init(&NVIC_InitStructure); //根据NVIC_InitStruct中指定的参数初始化外设NVIC寄存器
}
//RTC闹钟初始化:启动时钟、配置LSI做RTC时钟、设置预分频40000得到1Hz
//设置运行时间WORK_TIMES
void RTC_Alarm_Configuration(void)
{
/* Enable PWR and BKP clocks */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR | RCC_APB1Periph_BKP, ENABLE);
/* Allow access to BKP Domain */
PWR_BackupAccessCmd(ENABLE);
/* Reset Backup Domain */
BKP_DeInit();
/* RTC clock source configuration ----------------------------------------*/
/* Enable the LSI OSC */
RCC_LSICmd(ENABLE);
/* Wait till LSI is ready */
while(RCC_GetFlagStatus(RCC_FLAG_LSIRDY) == RESET)
{
}
/* Select the RTC Clock Source */
RCC_RTCCLKConfig(RCC_RTCCLKSource_LSI);
/* Enable the RTC Clock */
RCC_RTCCLKCmd(ENABLE);
/* Wait for RTC registers synchronization */
RTC_WaitForSynchro();
/* Wait until last write operation on RTC registers has finished */
RTC_WaitForLastTask();
/* 使能RTC闹钟中断*/
RTC_ITConfig(RTC_IT_ALR, ENABLE);
/* Wait until last write operation on RTC registers has finished */
RTC_WaitForLastTask();
/* 使能RTC秒判断*/
RTC_ITConfig(RTC_IT_SEC, ENABLE);
/* Wait until last write operation on RTC registers has finished */
RTC_WaitForLastTask();
/* Set RTC prescaler: set RTC period to 1sec */
RTC_SetPrescaler(32767);
/* Wait until last write operation on RTC registers has finished */
RTC_WaitForLastTask();
//中断配置
//RTC_NVIC_Config();
//设置运行WORK_TIMES
//RTC_SetAlarm(RTC_GetCounter() + WORK_TIMES);
RTC_SetAlarm(10);
RTC_WaitForLastTask();
}
//设置闹钟时长并进入待机
//s为中断秒数
void RTC_Enter_StandbyMode(u32 s)
{
RTC_SetAlarm(RTC_GetCounter() + s);
RTC_WaitForLastTask();
// 进入待机模式, 此时所有1.8V域的时钟都关闭,HIS和HSE的振荡器关闭, 电压调节器关闭.
// 只有WKUP引脚上升沿,RTC警告事件,NRST引脚的外部复位,IWDG复位.
/* Request to enter STANDBY mode (Wake Up flag is cleared in PWR_EnterSTANDBYMode function) */
PWR_EnterSTANDBYMode();
}
/*
//中断服务函数
void RTC_IRQHandler(void)
{
if(RTC_GetITStatus(RTC_IT_ALR)!= RESET)//闹钟中断
{
RTC_ClearITPendingBit(RTC_IT_ALR); //清闹钟中断
RTC_Enter_StandbyMode(STANDBY_TIMES);//进入待机
}
}
*/
/*******************************************************************************
* Function Name : RTC_Alarm_Init
* Description : RTC Initialization
* Input : None
* Output : None
* Return : None
* Attention : None
*******************************************************************************/
void RTC_Alarm_Init(void)
{
if (BKP_ReadBackupRegister(BKP_DR1) != 0xA5A5)
{
/* Backup data register value is not correct or not yet programmed (when
the first time the program is executed) */
printf("RTC 还没有被设置....\r\n");
/* RTC Configuration */
RTC_Alarm_Configuration();
//Time_Regulate();
//Time_Adjust();
/* Adjust time by values entred by the user on the hyperterminal */
printf("RTC 初始化....\r\n");
BKP_WriteBackupRegister(BKP_DR1, 0xA5A5);
}
else
{
/* Check if the Power On Reset flag is set */
if (RCC_GetFlagStatus(RCC_FLAG_PORRST) != RESET)
{
printf("发生一次电源上电重启....\r\n");
}
/* Check if the Pin Reset flag is set */
else if (RCC_GetFlagStatus(RCC_FLAG_PINRST) != RESET)
{
printf("发生一次外部复位....\r\n");
}
printf("不需要设置RCT....\r\n");
/* Wait for RTC registers synchronization */
//RTC_WaitForSynchro();
/* Enable the RTC Second */
RTC_ITConfig(RTC_IT_SEC, ENABLE);
/* Wait until last write operation on RTC registers has finished */
RTC_WaitForLastTask();
RTC_ITConfig(RTC_IT_ALR, ENABLE); //naozhong
RTC_WaitForLastTask(); //等待写入完成
}
/* NVIC configuration */
RTC_NVIC_Config();
#ifdef RTCClockOutput_Enable
/* Enable PWR and BKP clocks */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR | RCC_APB1Periph_BKP, ENABLE);
/* Allow access to BKP Domain */
PWR_BackupAccessCmd(ENABLE);
/* Disable the Tamper Pin */
BKP_TamperPinCmd(DISABLE); /* To output RTCCLK/64 on Tamper pin, the tamper
functionality must be disabled */
/* Enable RTC Clock Output on Tamper Pin */
BKP_RTCOutputConfig(BKP_RTCOutputSource_CalibClock);
#endif
/* Clear reset flags */
RCC_ClearFlag();
return;
}
RTC_Alarm.rar_RTC闹钟_STM32 RTC_rtc alarm_rtc alarm中断
版权申诉
53 浏览量
2022-09-19
23:08:31
上传
评论 2
收藏 2KB RAR 举报
小波思基
- 粉丝: 70
- 资源: 1万+
最新资源
- 南京邮电大学数学实验:熟练掌握 Matlab 软件的基本命令和操作
- 2017校招真题校园招聘真题算法题(37道)Python源码.zip
- 基于单片机protues仿真的多功能自动饮水机系统设计(仿真图、源代码、演示视频)
- 二叉树7-1-1.cpp
- android 9.0 原生模拟器 签名文件
- 技术面试最后反问面试官的话 校招面试非技术问题有哪些 非技术问题如何回答.png
- NB-IOT-BC26全网通模块Altium+ CADENCE +PADS三种格式(原理图SCH+PCB封装库)文件.zip
- 基于微信小程序开发的校园失物招领系统源码毕业设计(优质项目源码).zip
- 词向量是一种将自然语言中的单词转换为数值向量的技术,它能够捕捉词义和上下文信息
- nmap与masscan的简单使用
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
评论0