PCLK频率过高,要先除以4096,再预分频

恩????不应该是T小于W才能喂狗吗?

这里计算的是最大超时时间

硬件复位清除?

 main.h

#include "exti.h"
#include "wwdg.h"
#include "delay.h"

int main(void)
{
    LedInit();
    delay_init();
    LED0=0;
    delay_ms(200);
    wwdg_init(0x7f,0x5f,WWDG_Prescaler_8);//喂狗成功则LED0熄灭,失败则复位,LED0闪烁
    while(1)
    {
        LED0=1;
    }
}

wwdg.c

#include "wwdg.h"

u8 wwdg_CNT=0x7f;//用于取后七位

void wwdg_NVIC_init()
{

    NVIC_InitTypeDef NVIC_InitStructure;
    NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);

    NVIC_InitStructure.NVIC_IRQChannel=WWDG_IRQn;
    NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE;
    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=2;
    NVIC_InitStructure.NVIC_IRQChannelSubPriority=3;
    NVIC_Init(&NVIC_InitStructure);

}

void wwdg_init(u8 tr,u8 wr,u32 fprer)//初值,窗口值,预分频系数
{
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_WWDG,ENABLE);
    wwdg_CNT=tr&wwdg_CNT;
    WWDG_SetPrescaler(fprer);
    WWDG_SetWindowValue(wr);
    WWDG_Enable(wwdg_CNT);

    WWDG_ClearFlag();
    wwdg_NVIC_init();
    WWDG_EnableIT();//开中断

}


void wwdg_set_count(u8 cnt)
{
    WWDG_Enable(cnt);
}


void WWDG_IRQHandler()
{
    wwdg_set_count(wwdg_CNT);
    WWDG_ClearFlag();
    LED1=!LED1;

}

wwdg.h

#ifndef __WWDG_H
#define __WWDG_H

#include "sys.h"
#include "led.h"

void wwdg_init(u8 tr,u8 wr,u32 fprer);//初值,窗口值,预分频系数
void wwdg_set_count(u8 cnt);

#endif

中断服务函数这里

不能交换位置

原因:

 https://blog.csdn.net/weixin_44174362/article/details/86529808