微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > STM32 AWU RTC闹钟从停机模式唤醒CPU

STM32 AWU RTC闹钟从停机模式唤醒CPU

时间:11-23 来源:互联网 点击:
网上找不到范例 自已对着PDF整了半天!!

void RTC_EXTI_INITIAL(FunctionalState interrupt_en_or_dis)
{
NVIC_InitTypeDef NVIC_InitStructure;
EXTI_InitTypeDef EXTI_InitStructure;

//------------EXTI 配置 -------------------
EXTI_InitStructure.EXTI_Line = EXTI_Line17;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;
EXTI_InitStructure.EXTI_LineCmd = interrupt_en_or_dis;
EXTI_Init(&EXTI_InitStructure);
//------------设置 中断-------------------
NVIC_InitStructure.NVIC_IRQChannel = RTCAlarm_IRQn;//防拆
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = interrupt_en_or_dis;
NVIC_Init(&NVIC_InitStructure);
//-------------------------------------------
}

void RTC_SET_ALARM(u32 sec)
{
//DEBUG_COM_STREAM("-闹钟-",NULL);
RTC_SetAlarm(RTC_GetCounter()+sec);
//DEBUG_COM_STREAM("-闹钟1-",NULL);
RTC_WaitForLastTask();
//DEBUG_COM_STREAM("-闹钟2-",NULL);
RTC_ITConfig(RTC_FLAG_ALR,ENABLE);
}
void RTC_AWU_SET(void)
{
//启用PWR和BKP的时钟(from APB1)
RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR | RCC_APB1Periph_BKP, ENABLE);
//后备域解锁
PWR_BackupAccessCmd(ENABLE);
RTC_ITConfig(RTC_IT_SEC, DISABLE);
RTC_SET_ALARM(5);
//PWR_BackupAccessCmd(DISABLE);
RTC_EXTI_INITIAL(ENABLE);
}

void RTCAlarm_IRQHandler(void)
{
EXTI_ClearITPendingBit(EXTI_Line17);
//SYS.wake_id|=1<17;
}

void RTC_IRQHandler(void)
{
if (RTC_GetITStatus(RTC_IT_SEC) != RESET)
{

RTC_ClearITPendingBit(RTC_IT_SEC);


RTC_WaitForLastTask();
//TIME_COUNT=RTC_GetCounter();
//RTC_WaitForLastTask();
}
if (RTC_GetITStatus(RTC_FLAG_ALR) != RESET)
{RTC_ClearITPendingBit(RTC_FLAG_ALR);
RTC_WaitForLastTask();
//SYS.wake_id|=1<1;
}

}


Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top