打印
[应用相关]

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

[复制链接]
661|0
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主

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;
   }

}


发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

174

主题

3373

帖子

13

粉丝