我用一个灯监视WWG中断,正常的话每进20次中断改一次灯的状态,(主要是因为看门狗58.25MS喂一次狗,想让LED大约1S闪一次),但是不知哪里出现问题,灯从没闪烁过,说明WWDG中断没有进入,我将断点设在WWDG中断程序中,结果也没有跑到中断程序中。
我的程序大概如下:
int main(void)
{
LED_GPIO_Configuration();
EXTI_Configuration();
/* Check if the system has resumed from WWDG reset -------------------------*/
if(RCC_GetFlagStatus(RCC_FLAG_WWDGRST) != RESET)
{ /* WWDGRST flag set */
/* Turn on led connected to PC.06 */
GPIO_WriteBit(GPIOC, GPIO_Pin_6, Bit_SET);
/* Clear reset flags */
RCC_ClearFlag();
}
else
{ /* WWDGRST flag is not set */
/* Turn off led connected to PC.06 */
GPIO_WriteBit(GPIOC, GPIO_Pin_6, Bit_RESET);
}
NVIC_Configuration();
WWDG_Configutration();
/* Infinite loop */
while (1)
{
}
}
//看门狗初始化
void WWDG_Configutration()
{
RCC_APB1PeriphClockCmd(RCC_APB1Periph_WWDG, ENABLE);//WWDG
//软件看门狗初始化
WWDG_SetPrescaler(WWDG_Prescaler_8); //时钟8分频
// (PCLK1/4096)/8=1099 Hz (~910 us)
WWDG_SetWindowValue(65); //Window value数值为65
WWDG_Enable(127); //启动计数器,设置计数值为127设置喂狗时间
// WWDG timeout = ~910 us * 64 = 58.25 ms
WWDG_ClearFlag(); //清除标志位
WWDG_EnableIT(); //启动中断
}
void NVIC_Configuration(void)
{
NVIC_InitStructure.NVIC_IRQChannel = WWDG_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
/* Enable the EXTI3_IRQn Interrupt */
NVIC_InitStructure.NVIC_IRQChannel = EXTI3_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
void EXTI_Configuration(void)
{
EXTI_InitTypeDef EXTI_InitStructure;
/* Connect EXTI Line3 to PD3*/
GPIO_EXTILineConfig(GPIO_PortSourceGPIOD, GPIO_PinSource3);
/* Configure EXTI Line3 to generate an interrupt on falling edge */
EXTI_ClearITPendingBit(EXTI_Line3);
EXTI_InitStructure.EXTI_Line = EXTI_Line3;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
}
void LED_GPIO_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
//LED3<=>PC.6 LED2<=>PC.7
/* Configure PC.06 and PC.07 as Output push-pull */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 |GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOC, &GPIO_InitStructure);
/* Configure KEY2<=> PD3 as input floating (EXTI Line3) */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOD, &GPIO_InitStructure);
}
void WWDG_IRQHandler(void)
{
wwdg_count++;
led_count++;
/* Update WWDG counter */
WWDG_SetCounter(0x7F);
/* Clear EWI flag */
WWDG_ClearFlag();
wwdg_count = 0;
/* Toggle led connected to PC.04 */
GPIO_WriteBit(GPIOC, GPIO_Pin_4, (BitAction)(1-GPIO_ReadOutputDataBit(GPIOC, GPIO_Pin_4)));
if(led_count>=20)//用于监视WWDG是否工作正常
{
/* Toggle led connected to PC.07 */
GPIO_WriteBit(GPIOC, GPIO_Pin_7, (BitAction)(1-GPIO_ReadOutputDataBit(GPIOC, GPIO_Pin_7)));
wwdg_count = 0;
}
}
void EXTI3_IRQHandler(void)
{
if(EXTI_GetITStatus(EXTI_Line3) != RESET)
{
/* Turn off led connected to PC.05 */
GPIO_WriteBit(GPIOC, GPIO_Pin_5, Bit_SET);
/* As EXTI line3 pending bit is not cleared, the CPU will execute indefinitely
this ISR and when the WWDG counter falls to 3Fh the WWDG reset occurs */
}
}