在窗口看门狗的初始化化配置函数Wwdg_Config里面WWDG_Enable(count)函数必须放在WWDG_ClearFlag()和WWDG_EnableIT()之前才能正常运行,这是为什么?
void Wwdg_Config(uint32_t pre ,uint8_t count ,uint8_t up)
{
RCC_APB1PeriphClockCmd(RCC_APB1Periph_WWDG, ENABLE);
WWDG_SetCounter(count);
WWDG_SetPrescaler(pre);
WWDG_SetWindowValue(up);
WWDG_Enable(count);
Wwdg_NVIC_Config();
WWDG_ClearFlag();
WWDG_EnableIT();
}
这样的配置是正常的。
一旦WWDG_Enable(count)没有放在WWDG_ClearFlag()和WWDG_EnableIT()之前,无论是在中间还是最后,都会不断地直接复位
main函数如下:
int main(void)
{
USART_Config();
if(RCC_GetFlagStatus(RCC_FLAG_WWDGRST)==SET)
{
RCC_ClearFlag();
printf("Wwdg reset!\r\n");
}
else printf("power reset!\r\n");
printf("Wwdg_test\r\n");
Wwdg_Config(WWDG_Prescaler_8, 0x7F,0x5E);
for (;;)
{
SysTick_Delay_Ms(31);
Wwdg_Feed(0x7F);
}
}
其他相关函数:
static void Wwdg_NVIC_Config(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
NVIC_InitStructure.NVIC_IRQChannel = WWDG_IRQn;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_Init(&NVIC_InitStructure);
}
void Wwdg_Feed(uint8_t count)
{
WWDG_SetCounter(count);
printf("Wwdg Feed!\r\n");
}
void WWDG_IRQHandler(void)
{
WWDG_ClearFlag();
Wwdg_Feed(0x7F);
printf("wwdg_TimeEnd\r\n");
} |