stm32f4xx 的IWDG使用的一般步骤

 


需要注意的是:

 

  STM32系列的MCU内部的RC频率会在30kHz到60kHz之间变化。此外,即使RC振荡器的频率是精确的,确切的时序仍然依赖于APB接口时钟与RC振荡器时钟之间的相位差,因此总会有一个完整的RC周期是不确定的。stm32f10x,通过对LSI进行校准可获得相对精确的看门狗超时时间。但是在stm32f4 中并没有对它校准的说明。

通常我们在估算的时候,以 40Khz 的频率来计算      

 

 

1)取消寄存器写保护(向 IWDG_KR 写入 0X5555)
  通过这步,我们取消 IWDG_PR 和 IWDG_RLR 的写保护,使后面可以操作这两个寄存器,设置 IWDG_PR 和 IWDG_RLR 的值。这在库函数中的实现函数是:

IWDG_WriteAccessCmd(IWDG_WriteAccess_Enable);

这个函数非常简单,顾名思义就是开启/取消写保护,也就是使能/失能写权限。

2)设置独立看门狗的预分频系数和重装载值

设置看门狗的分频系数的函数是:

1 void IWDG_SetPrescaler(uint8_t IWDG_Prescaler); //设置 IWDG 预分频值

设置看门狗的重装载值的函数是:

1 void IWDG_SetReload(uint16_t Reload); //设置 IWDG 重装载值

设置好看门狗的分频系数 prer 和重装载值就可以知道看门狗的喂狗时间 (也就是看门狗溢出时间) ,该时间的计算方式为:

      Tout=((4×2^prer) ×rlr) /40
   

   其中 Tout 为看门狗溢出时间(单位为 ms) ;prer 为看门狗时钟预分频值(IWDG_PR 值),范围为 0~7;rlr 为看门狗的重装载值(IWDG_RLR 的值) ;比如我们设定 prer 值为 4, rlr 值为 625,那么就可以得到 Tout=64×625/40=1000ms,这样,看门狗的溢出时间就是 1s,只要你在一秒钟之内,有一次写入 0XAAAA 到 IWDG_KR,就不会导致看门狗复位(当然写入多次也是可以的)。这里需要提醒大家的是,看门狗的时钟不是准确的 40Khz,所以在喂狗的时候,最好不要太晚了,否则,有可能发生看门狗复位。     

3)重载计数值喂狗(向 IWDG_KR 写入 0XAAAA)
库函数里面重载计数值的函数是:

1 IWDG_ReloadCounter(); //按照 IWDG 重装载寄存器的值重装载 IWDG 计数器

通过这句,将使 STM32 重新加载 IWDG_RLR 的值到看门狗计数器里面。 即实现独立看门狗的喂狗操作。

4) 启动看门狗(向 IWDG_KR 写入 0XCCCC)
库函数里面启动独立看门狗的函数是:

1 IWDG_Enable(); //使能 IWDG

通过这句,来启动 STM32 的看门狗。注意 IWDG 在一旦启用,就不能再被关闭!想要关闭,只能重启,并且重启之后不能打开 IWDG,否则问题依旧,所以在这里提醒大家,如果不用 IWDG 的话,就不要去打开它,免得麻烦。

 

转载于:https://www.cnblogs.com/kalo1111/p/3337207.html

*** Using Compiler 'V5.06 update 5 (build 528)', folder: 'D:\Keil 524\ARM\ARMCC\Bin' Rebuild target 'Target 1' assembling startup_stm32f411xe.s... compiling stm32f4xx_dcmi.c... compiling stm32f4xx_it.c... compiling stm32f4xx_dac.c... compiling stm32f4xx_cryp_tdes.c... compiling misc.c... compiling stm32f4xx_cryp_des.c... compiling stm32f4xx_can.c... compiling stm32f4xx_dbgmcu.c... compiling stm32f4xx_adc.c... compiling stm32f4xx_cryp.c... compiling stm32f4xx_cec.c... compiling stm32f4xx_crc.c... compiling system_stm32f4xx.c... compiling stm32f4xx_cryp_aes.c... compiling stm32f4xx_dfsdm.c... compiling stm32f4xx_dma.c... compiling stm32f4xx_dma2d.c... compiling stm32f4xx_flash.c... compiling stm32f4xx_dsi.c... compiling stm32f4xx_exti.c... compiling stm32f4xx_flash_ramfunc.c... compiling stm32f4xx_ltdc.c... compiling stm32f4xx_iwdg.c... compiling stm32f4xx_i2c.c... compiling stm32f4xx_lptim.c... compiling stm32f4xx_fmpi2c.c... compiling stm32f4xx_gpio.c... compiling stm32f4xx_hash.c... compiling stm32f4xx_hash_md5.c... compiling stm32f4xx_hash_sha1.c... compiling main.c... ..\USER\main.c(2): error: #5: cannot open source input file "tjc_usart_hmi.h": No such file or directory #include "tjc_usart_hmi.h" ..\USER\main.c: 0 warnings, 1 error compiling tjc_usart_hmi.c... tjc_usart_hmi.h(27): warning: #1-D: last line of file ends without a newline #endif tjc_usart_hmi.c(7): error: #5: cannot open source input file "stm32f10x_usart.h": No such file or directory #include <stm32f10x_usart.h> tjc_usart_hmi.c: 1 warning, 1 error compiling stm32f4xx_qspi.c... compiling stm32f4xx_pwr.c... compiling stm32f4xx_rtc.c... compiling stm32f4xx_rcc.c... compiling stm32f4xx_sai.c... compiling stm32f4xx_rng.c... compiling stm32f4xx_syscfg.c... compiling stm32f4xx_sdio.c... compiling stm32f4xx_wwdg.c... compiling stm32f4xx_spdifrx.c... compiling stm32f4xx_spi.c... compiling stm32f4xx_usart.c... compiling stm32f4xx_tim.c... "..\OUTPUT\STM32F411CEU6.axf" - 2 Error(s), 1 Warning(s). Target not created. Build Time Elapsed: 00:03:35
最新发布
08-02
Rebuild started: Project: stm32f407 *** Using Compiler 'V5.06 update 7 (build 960)', folder: 'D:\cjc\keil\ARM\ARMCC\Bin' Rebuild target 'stm32f407' assembling startup_stm32f40_41xxx.s... compiling main.c... ..\app\main.c(23): error: #167: argument of type "struct led_desc" is incompatible with parameter of type "led_desc_t" led_on(led1); ..\app\main.c(35): warning: #1-D: last line of file ends without a newline ..\app\main.c: 1 warning, 1 error compiling boad.c... compiling led.c... ..\driver\led.c(51): warning: #1-D: last line of file ends without a newline ..\driver\led.c: 1 warning, 0 errors compiling stm32f4xx_crc.c... compiling misc.c... compiling stm32f4xx_can.c... compiling stm32f4xx_cec.c... compiling system_stm32f4xx.c... compiling stm32f4xx_adc.c... compiling stm32f4xx_cryp.c... compiling stm32f4xx_cryp_des.c... compiling stm32f4xx_cryp_tdes.c... compiling stm32f4xx_cryp_aes.c... compiling stm32f4xx_dac.c... compiling stm32f4xx_dbgmcu.c... compiling stm32f4xx_dcmi.c... compiling stm32f4xx_dfsdm.c... compiling stm32f4xx_dma.c... compiling stm32f4xx_dma2d.c... compiling stm32f4xx_dsi.c... compiling stm32f4xx_exti.c... compiling stm32f4xx_flash_ramfunc.c... compiling stm32f4xx_flash.c... compiling stm32f4xx_fmpi2c.c... compiling stm32f4xx_fsmc.c... compiling stm32f4xx_gpio.c... compiling stm32f4xx_hash.c... compiling stm32f4xx_hash_md5.c... compiling stm32f4xx_hash_sha1.c... compiling stm32f4xx_i2c.c... compiling stm32f4xx_iwdg.c... compiling stm32f4xx_lptim.c... compiling stm32f4xx_ltdc.c... compiling stm32f4xx_pwr.c... compiling stm32f4xx_qspi.c... compiling stm32f4xx_rcc.c... compiling stm32f4xx_rng.c... compiling stm32f4xx_rtc.c... compiling stm32f4xx_sai.c... compiling stm32f4xx_sdio.c... compiling stm32f4xx_spdifrx.c... compiling stm32f4xx_syscfg.c... compiling stm32f4xx_spi.c... compiling stm32f4xx_tim.c... compiling stm32f4xx_usart.c... compiling stm32f4xx_wwdg.c... ".\Objects\stm32f407.axf" - 1 Error(s), 2 Warning(s). Target not created. Build Time Elapsed: 00:00:10
06-23
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值