void Iwdg_Interrupt_Config()
{
NVIC_InitTypeDef NVIC_InitStructure;
EXTI_InitTypeDef EXTI_InitStructure;
EXTI_DeInit();
EXTI_StructInit(&EXTI_InitStructure);
EXTI_InitStructure.EXTI_Line = EXTI_Line17 ;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt ;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising_Falling ;
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
EXTI_ClearITPendingBit(EXTI_Line17);
NVIC_InitStructure.NVIC_IRQChannel = WWDG_IWDG_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
//GPIO_LED_Config();//使用LED显示看门狗是否进入中断
}
#define IWDG_FLAG_IVU ((uint16_t)0x0004)
void IVU_CheckStatus(void)
{
while(1) {
if(IWDG_GetFlagStatus(IWDG_FLAG_IVU) == RESET) {
break;
}
}
}
void WWDG_IWDG_IRQHandler(void)
{
iwdg_flag= 1;
EXTI_ClearFlag(EXTI_Line17);
IWDG_WriteAccessCmd(0x5555);
IWDG->CR |= 0x03;
IWDG->KR = 0xAAAA;
}
void Interrput_Iwdg_ON(u16 IWDG_Prescaler, u16 Reload)
{
RCC_LSICmd(ENABLE);
while(RCC_GetFlagStatus(RCC_FLAG_LSIRDY) == RESET);
PVU_CheckStatus();
IWDG_WriteAccessCmd(0x5555);
IWDG_SetPrescaler(IWDG_Prescaler);
RVU_CheckStatus();
IWDG_WriteAccessCmd(0x5555);
IWDG_SetReload(Reload & 0xfff);
IVU_CheckStatus();
IWDG_WriteAccessCmd(0x5555);
IWDG->IGEN = 0x50;
IWDG_ReloadCounter();
IWDG_WriteAccessCmd(0x5555);
IWDG->CR |= 1;
IWDG_Enable();
}
int main()
{ my_delay_ms(10000);
Iwdg_Interrupt_Config();//中断配置
Interrput_Iwdg_ON(IWDG_Prescaler_32, 0x86a); //配置并使能IWDG
PWR_EnterSTOPMode(0, PWR_STOPEntry_WFI);//进入STOP模式
while (1)
{
iwdg_flag = 0;
my_delay_ms(10);
Interrput_Iwdg_ON(IWDG_Prescaler_32, 0x186a); //退出中断函数后重新配置IWDG,建议在清除中断标志位之后有一个延迟在执行这一函数
PWR_EnterSTOPMode(0, PWR_STOPEntry_WFI); //进入STOP模式
my_delay_ms(3000);
// IWDG_ReloadCounter(); //取消注释开启喂狗
}
}
大佬们帮我看看明明配置了看门狗开启中断模式还会复位
|