Stm32之配置WWDG流程

看门狗初始化

void WWDG_Init(u8 tr, u8wr, u8 fprer)
RCC->APB1ENR |= 1 << 11; //使能wwdg时钟
WWDG->CFR |= fprer << 7; //PCLK1 / 4096 再除2^fprer
WWDG->CFR &= 0xff80;
WWDG->CFR |= wr;	//设定窗口值
WWDG->CR |= tr;		//设定计数器值
WWDG->CR |= 1 << 7;//开启看门狗
MY_NVIC_Init(2,3,WWDG_IRQn,2);
WWDG->SR  = 0x00; //清除提前唤醒中断标志位
WWDG->SR |= 1<< 9;//使能提前唤醒中断

喂狗

void WWDG_Set_Counter(u8 cnt)
{
	WWDG->CR = (cnt & 0x7f);
}

中断服务程序

void WWDG_IRQHandler(void)
{
	WWDG_Set_Counter(0x7f);
	WWDG->SR= 0x00;//清除提前唤醒中断标志位
	{}
}

看门狗的超时公式
Twwdg=(4096 * 2^WDGTB * (T[5:0] + 1)) / Fpclk1;

你可能感兴趣的:(Stm32之配置WWDG流程)