STM32独立看门狗与窗口看门狗
来源:互联网 发布:淘宝助理怎么发布宝贝 编辑:程序博客网 时间:2024/05/06 20:22
香水城:如何使用STM32的窗口看门狗
菜农:看门狗专栏
/*注:stm32f10x_stdperiph_lib_v3.0.0 编译器:MDK3.24A*/
/* Includes -----------------------------------*/
#include "stm32f10x.h"
#include "stm32f10x_wwdg.h"
/* Private function prototypes ----------------------------*/
void RCC_Configuration(void);
void NVIC_Configuration(void);
void GPIO_Configuration(void);
void SysTick_Configuration(void);
void IWDG_Configuration(void);
void WWDG_Configuration(void);
void Delay(__IO uint32_t nCount);
void Test(void);
/* Private functions --------------------------------------*/
/**===============================
* @brief Main program.
* @param None
* @retval : None
=================================*/
int main(void)
{
RCC_Configuration();
GPIO_Configuration();
Test();
NVIC_Configuration();
SysTick_Configuration(); /* Generate an interrupt each 100ms */
IWDG_Configuration();
WWDG_Configuration();
while (1) {
;
}
}
/**---------------------------------------------------------
* @brief [测试]若由IWDG或WWDG引起复位,则Pin4闪一下(注:首次Pin4闪由上电引起,不是由看门狗复位引起);若不断复位,则Pin4不断闪烁。注: 可通过更改程序中的相关值而引起看门狗复位。
* @param None
* @retval : None
------------------------------------------------------*/
void Test(void)
{
GPIO_SetBits(GPIOC, GPIO_Pin_4);
Delay(0xFFFFF);
GPIO_ResetBits(GPIOC, GPIO_Pin_4);
}
/**---------------------------------------------------------
* @brief Configures the different system clocks.
* @param None
* @retval : None
------------------------------------------------------*/
void RCC_Configuration(void)
{
SystemInit();
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_WWDG, ENABLE);
}
/**------------------------------------------------
* @brief Configures the different GPIO ports.
* @param None
* @retval : None
---------------------------------------------------*/
void GPIO_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
/* Configure GPIOC as Output push-pull */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_6 | GPIO_Pin_7;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOC, &GPIO_InitStructure);
}
/**----------------------------------------------------------------
* @brief Configures NVIC and Vector Table base location.
* @param None
* @retval : None
-------------------------------------------------------------------*/
void NVIC_Configuration(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
NVIC_InitStructure.NVIC_IRQChannel = WWDG_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_Init(&NVIC_InitStructure);
/* Set SysTick interrupt vector Preemption Priority to 1 */
NVIC_SetPriority(SysTick_IRQn, 0x08);
}
/**--------------------------------------------------------------------
* @brief Configures SysTick to generate an interrupt.
* @param None
* @retval : None
----------------------------------------------------------------------*/
void SysTick_Configuration(void)
{
/* SysTick interrupt each 100ms */
if (SysTick_Config(SystemFrequency / 10)){
/* Capture error */
while (1);
}
}
/**-----------------------------------------------------------------
* @brief Inserts a delay time.
* @param nCount: specifies the delay time length.
* @retval : None
------------------------------------------------------------------*/
void Delay(__IO uint32_t nCount)
{
for(; nCount != 0; nCount--);
}
/**-------------------------------
* @brief Configures IWDG
* @param None
* @retval : None
------------------------------*/
void IWDG_Configuration(void)
{
/* IWDG timeout equal to 200 ms (the timeout may varies due to LSI frequency dispersion) */
/* Enable write access to IWDG_PR and IWDG_RLR registers */
IWDG_WriteAccessCmd(IWDG_WriteAccess_Enable);
/* IWDG counter clock: 40KHz(LSI) / 16 = ? KHz */
IWDG_SetPrescaler(IWDG_Prescaler_16);
/* Set counter reload value: (500)x16/40K=200msec */
IWDG_SetReload(500);
/* Reload IWDG counter */
IWDG_ReloadCounter();
/* Enable IWDG (the LSI oscillator will be enabled by hardware) */
IWDG_Enable();
}
/**-------------------------------
* @brief Configures WWDG
* @param None
* @retval : None
------------------------------*/
void WWDG_Configuration(void)
{
/* WWDG clock counter = (PCLK1/4096)/8 = 244 Hz (~4 ms) */
WWDG_SetPrescaler(WWDG_Prescaler_8);
/* Set Window value to 65 */
WWDG_SetWindowValue(65);
/* Enable WWDG and set counter value to 127, WWDG timeout = ~4 ms * 64 = 262 ms */
WWDG_Enable(127);
/* Clear EWI flag */
WWDG_ClearFlag();
/* Enable EW interrupt */
WWDG_EnableIT();
}
/* Includes -----------------------------------------*/
#include "stm32f10x_it.h"
#include "stm32f10x_wwdg.h"
/**--------------------------------------------------------
* @brief This function handles SysTick Handler.
* @param None
* @retval : None
------------------------------------------------------*/
void SysTick_Handler(void)
{
/* Reload IWDG counter */
IWDG_ReloadCounter();
/* Toggle GPIO_LED pin 7 */
GPIO_WriteBit(GPIOC, GPIO_Pin_7, (BitAction)(1 - GPIO_ReadOutputDataBit(GPIOC, GPIO_Pin_7)));
}
/**----------------------------------------------------------
* @brief This function handles WWDG interrupt request.
* @param None
* @retval : None
-------------------------------------------------------------*/
void WWDG_IRQHandler(void)
{
/* Update WWDG counter */
WWDG_SetCounter(0x7F);
/* Clear EWI flag */
WWDG_ClearFlag();
/* Toggle GPIO_Led pin 6 */
GPIO_WriteBit(GPIOC, GPIO_Pin_6, (BitAction)(1 - GPIO_ReadOutputDataBit(GPIOC, GPIO_Pin_6)));
}
- STM32 独立看门狗与窗口看门狗
- STM32独立看门狗与窗口看门狗
- STM32 独立看门狗IWDG 与窗口看门狗WWDG
- STM32独立看门狗IWDG与窗口看门狗WWDG研究
- stm32学习笔记 F1系列独立看门狗与窗口看门狗
- stm32 独立看门狗和窗口看门狗区别
- stm8的独立看门狗与窗口看门狗
- stm32独立看门狗和窗口看门狗的区别
- stm32独立看门狗和窗口看门狗的区别
- stm32独立看门狗和窗口看门狗的区别
- stm32独立看门狗和窗口看门狗的区别
- stm32独立看门狗和窗口看门狗的区别
- STM32之独立看门狗和窗口看门狗定时器
- stm32独立看门狗和窗口看门狗的区别和联系
- STM32的独立看门狗
- stm32 独立看门狗学习
- STM32独立看门狗
- STM32 独立看门狗简介
- QT学习 之 QwtPlot(数学绘图)
- C# 编写Windows Service(windows服务程序)
- 30多年程序员生涯总结
- Android第三方资源使用之ImageCache
- 对话框 ~ 更新菜单和工具栏
- STM32独立看门狗与窗口看门狗
- 黑马程序员---Java基础篇之JDK的安装和介绍
- 选择排序
- ProgressBar,双向进度
- 机器学习实战python版决策树以及Matplotlib注解绘制决策树
- Kafka剖析(一):Kafka背景及架构介绍
- 如何搭建基于Jesery框架的Restful服务
- 无线网卡的Master,Managed,ad-hoc,monitor模式
- 协议和代理