STM32看门狗配置说明

系统时钟:
在这里插入图片描述

The WWDG clock is prescaled from the APB clock and has a configurable time-window that
can be programmed to detect abnormally late or early application behavior.

/** @defgroup WWDG_Prescaler WWDG Prescaler
  * @{
  */
#define WWDG_PRESCALER_1   0x00000000u     /*!< WWDG counter clock = (PCLK1/4096)/1 */
#define WWDG_PRESCALER_2   WWDG_CFR_WDGTB_0      /*!< WWDG counter clock = (PCLK1/4096)/2 */
#define WWDG_PRESCALER_4   WWDG_CFR_WDGTB_1     /*!< WWDG counter clock = (PCLK1/4096)/4 */
#define WWDG_PRESCALER_8  (WWDG_CFR_WDGTB_1 | WWDG_CFR_WDGTB_0)    /*!< WWDG counter clock = (PCLK1/4096)/8 */

寄存器配置

  hwwdg.Instance = WWDG;
  hwwdg.Init.Prescaler = WWDG_PRESCALER_1;
  hwwdg.Init.Window = 240;
  hwwdg.Init.Counter = 240;
  hwwdg.Init.EWIMode = WWDG_EWI_DISABLE;
  if (HAL_WWDG_Init(&hwwdg) != HAL_OK)
  {
    Error_Handler();
  }

理论计算时间(1分频)
T = 240 ∗ 4096 8000000 ∗ 1000 = 122.88 m s T = \frac{240*4096}{8000000} *1000= 122.88ms T=800000024040961000=122.88ms

2分频时间为: 2*122.88 = 245.76ms

喂狗:

/**
  * @brief  Refresh the WWDG.
  * @param  hwwdg  pointer to a WWDG_HandleTypeDef structure that contains
  *                the configuration information for the specified WWDG module.
  * @retval HAL status
  */
HAL_StatusTypeDef HAL_WWDG_Refresh(WWDG_HandleTypeDef *hwwdg)
{
  /* Write to WWDG CR the WWDG Counter value to refresh with */
  WRITE_REG(hwwdg->Instance->CR, (hwwdg->Init.Counter));

  /* Return function status */
  return HAL_OK;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值