PCLK频率过高,要先除以4096,再预分频
恩????不应该是T小于W才能喂狗吗?
这里计算的是最大超时时间
硬件复位清除?
main.h
1 #include "exti.h" 2 #include "wwdg.h" 3 #include "delay.h" 4 5 int main(void) 6 { 7 LedInit(); 8 delay_init(); 9 LED0=0; 10 delay_ms(200); 11 wwdg_init(0x7f,0x5f,WWDG_Prescaler_8);//喂狗成功则LED0熄灭,失败则复位,LED0闪烁 12 while(1) 13 { 14 LED0=1; 15 } 16 }
wwdg.c
1 #include "wwdg.h" 2 3 u8 wwdg_CNT=0x7f;//用于取后七位 4 5 void wwdg_NVIC_init() 6 { 7 8 NVIC_InitTypeDef NVIC_InitStructure; 9 NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); 10 11 NVIC_InitStructure.NVIC_IRQChannel=WWDG_IRQn; 12 NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE; 13 NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=2; 14 NVIC_InitStructure.NVIC_IRQChannelSubPriority=3; 15 NVIC_Init(&NVIC_InitStructure); 16 17 } 18 19 void wwdg_init(u8 tr,u8 wr,u32 fprer)//初值,窗口值,预分频系数 20 { 21 RCC_APB1PeriphClockCmd(RCC_APB1Periph_WWDG,ENABLE); 22 wwdg_CNT=tr&wwdg_CNT; 23 WWDG_SetPrescaler(fprer); 24 WWDG_SetWindowValue(wr); 25 WWDG_Enable(wwdg_CNT); 26 27 WWDG_ClearFlag(); 28 wwdg_NVIC_init(); 29 WWDG_EnableIT();//开中断 30 31 } 32 33 34 void wwdg_set_count(u8 cnt) 35 { 36 WWDG_Enable(cnt); 37 } 38 39 40 void WWDG_IRQHandler() 41 { 42 wwdg_set_count(wwdg_CNT); 43 WWDG_ClearFlag(); 44 LED1=!LED1; 45 46 }
wwdg.h
1 #ifndef __WWDG_H 2 #define __WWDG_H 3 4 #include "sys.h" 5 #include "led.h" 6 7 void wwdg_init(u8 tr,u8 wr,u32 fprer);//初值,窗口值,预分频系数 8 void wwdg_set_count(u8 cnt); 9 10 #endif
中断服务函数这里
不能交换位置
原因:
https://blog.csdn.net/weixin_44174362/article/details/86529808