如果VDD或者VDDA电压高于或低于PVD设定阈值都产生中断,表现为每中断一次,LED1就亮变灭或者灭变亮。
/********************************************************************************
* @file PWR/PVD/main.c
* @author MCD Application Team
* @version V3.4.0
* @date 10/15/2010
* @brief Main program body.
******************************************************************************/
/* Includes ------------------------------------------------------------------*/
#include 'stm32f10x.h'
#include 'stm32_eval.h'
void EXTI_Configuration(void);
void NVIC_Configuration(void);
/**
* @brief Main program.
* @param None
* @retval None
*/
int main(void)
{
/*!< At this stage the microcontroller clock setting is already configured,
this is done through SystemInit() function which is called from startup
file (startup_stm32f10x_xx.s) before to branch to application main.
To reconfigure the default setting of SystemInit() function, refer to
system_stm32f10x.c file
*/
/* Initialize LEDs and Key Button mounted on STM3210X-EVAL board */
STM_EVAL_LEDInit(LED1);
GPIO_SetBits(GPIOC, GPIO_Pin_7);
/* Enable PWR and BKP clock */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR | RCC_APB1Periph_BKP, ENABLE);//电源管理部分时钟开启
/* Configure EXTI Line to generate an interrupt on falling edge */
EXTI_Configuration();
/* NVIC configuration */
NVIC_Configuration();
/* Configure the PVD Level to 2.9V */
PWR_PVDLevelConfig(PWR_PVDLevel_2V9);// 设定监控阀值
/* Enable the PVD Output */
PWR_PVDCmd(ENABLE);// 使能PVD
while (1)
{
}
}
/**
* @brief Configures EXTI Lines.
* @param None
* @retval None
*/
void EXTI_Configuration(void)
{
EXTI_InitTypeDef EXTI_InitStructure;
/* Configure EXTI Line16(PVD Output) to generate an interrupt on rising and
falling edges */
EXTI_ClearITPendingBit(EXTI_Line16);
EXTI_InitStructure.EXTI_Line = EXTI_Line16;// PVD连接到中断线16上
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;//使用中断模式
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising_Falling;//电压上升或下降越过设定阀值时都产生中断。
EXTI_InitStructure.EXTI_LineCmd = ENABLE;// 使能中断线
EXTI_Init(&EXTI_InitStructure);// 初始
}
/**
* @brief Configures NVIC and Vector Table base location.
* @param None
* @retval None
*/
void NVIC_Configuration(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
/* Configure one bit for preemption priority */
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);//中断优先级配置
/* Enable the PVD Interrupt */ //设置PVD中断
NVIC_InitStructure.NVIC_IRQChannel = PVD_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
/******************* (C) COPYRIGHT 2010 STMicroelectronics *****END OF FILE****/
注意:GPIO驱动LED模式为GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;还是推挽输出。
中断处理函数:
void PVD_IRQHandler(void)
{
if(EXTI_GetITStatus(EXTI_Line16) != RESET)
{
/* LED1翻转 */
STM_EVAL_LEDToggle(LED1);
/* Clear the Key Button EXTI line pending bit */
EXTI_ClearITPendingBit(EXTI_Line16);
}
}
上一篇:STM32硬件电路设计注意事项
下一篇:STM32之Flash
推荐阅读最新更新时间:2024-11-09 10:36
设计资源 培训 开发板 精华推荐
- 使用 Analog Devices 的 LTC3568 的参考设计
- 使用 Analog Devices 的 AD8067ART 的参考设计
- NOIX4SE5000BLFB-GEVB:XGS 5000,RGB FBD HB
- LTM8052AIY 具有 4.75A 准确电流限制的 36Vin、3.3Vout 降压转换器的典型应用
- 使用 Microchip Technology 的 TC33167E 的参考设计
- NCV891334MW50GEVB:降压稳压器,双模评估板
- L7885C 高输入输出稳压器的典型应用
- STM8AF系列评估板-带有STM8AF51AA / STM8AF52AA MCU
- DC1185A-A,使用 LTC3850EUF 的演示板 4.5V = VIN = 14V,VOUT1:2V @ 10A,VOUT2:1.8V @ 10A 同步降压转换器
- 具有双输入的 LTC3126EFE 5V、2MHz 降压转换器的典型应用电路