更改

跳转至: 导航搜索

NBDK-L4:基础实验教程

删除358字节2019年2月20日 (三) 12:06
无编辑摘要
也就是说独立看门狗完全是独立运行,不受其他部分程序影响。
 
''<span class="tlid-translation-gender-indicator translation-gender-indicator"></span><span class="tlid-translation-gender-indicator translation-gender-indicator"></span><span class="tlid-translation-gender-indicator translation-gender-indicator"></span><span class="tlid-translation-gender-indicator translation-gender-indicator"></span><span class="tlid-translation-gender-indicator translation-gender-indicator"></span><span class="tlid-translation-gender-indicator translation-gender-indicator"></span><span class="tlid-translation-gender-indicator translation-gender-indicator"></span><span class="tlid-translation-gender-indicator translation-gender-indicator"></span><span class="tlid-translation-gender-indicator translation-gender-indicator"></span><span class="tlid-translation-gender-indicator translation-gender-indicator"></span>''
=== 硬件设计 ===
}
}
</syntaxhighlight>独立看门狗喂狗函数,也就是清除计数值。窗口看门狗初始化,使能窗口看门狗时钟,使能中断。<syntaxhighlight lang="c++" line="1" start="5767">void IWDG_FeedHAL_WWDG_MspInit(void){ HAL_IWDG_Refresh(&hiwdg); // 喂狗}</syntaxhighlight>初始化按键S2(PC2引脚)为一般上拉输入。<syntaxhighlight lang="c++" line="1" start="72">void IWDG_FeedIO_Init(voidWWDG_HandleTypeDef *hwwdg)
{
GPIO_InitTypeDef GPIO_InitStructure; // 定义引脚参数结构体  __HAL_RCC_GPIOC_CLK_ENABLE __HAL_RCC_WWDG_CLK_ENABLE(); // 使能GPIOC时钟使能窗口看门狗时钟
GPIO_InitStructure.Pin= GPIO_PIN_2; // 引脚编号为2 GPIO_InitStructure.Mode = GPIO_MODE_INPUT; // 输入 GPIO_InitStructure.Speed = GPIO_SPEED_FREQ_LOW HAL_NVIC_SetPriority(WWDG_IRQn, 10, 0); // 低频率抢占优先级10,子优先级为0 GPIO_InitStructure.Pull = GPIO_PULLUP; // 上拉 HAL_GPIO_Init HAL_NVIC_EnableIRQ(GPIOC, &GPIO_InitStructureWWDG_IRQn); // 初始化PC2使能窗口看门狗中断
}
</syntaxhighlight>检测当前S2引脚电平,并且返回当前电平状态。窗口看门狗唤醒中断回调函数,我们可以在这个函数中去调用喂狗的函数。<syntaxhighlight lang="c++" line="1" start="9483">uint8_t IWDG_FeedIO_Readvoid HAL_WWDG_EarlyWakeupCallback(voidWWDG_HandleTypeDef* hwwdg)
{
return HAL_GPIO_ReadPinHAL_WWDG_Refresh(GPIOC,GPIO_PIN_2hwwdg); // 喂狗
}
</syntaxhighlight>
510
个编辑

本PDF由谷雨文档中心自动生成,点击下方链接阅读最新内容。

取自“http://doc.iotxx.com/特殊:移动版差异/1614

导航菜单