正确操作步骤:
开时钟;配置电源检测;配置中断优先级
/* Includes ------------------------------------------------------------------*/
#include "stm32f10x.h"
#include "stm32_eval.h"
void EXTI_Configuration(void);
void NVIC_Configuration(void);
int main(void)
{
STM_EVAL_LEDInit(LED1);
GPIO_SetBits(GPIOC, GPIO_Pin_7);
/* Enable PWR and BKP clock */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR | RCC_APB1Periph_BKP, ENABLE);//电源管理部分时钟开启
EXTI_Configuration();
NVIC_Configuration();
PWR_PVDLevelConfig(PWR_PVDLevel_2V9);// 设定监控阀值
/* Enable the PVD Output */
PWR_PVDCmd(ENABLE);// 使能PVD
while (1)
{
}
}
void EXTI_Configuration(void)
{
EXTI_InitTypeDef EXTI_InitStructure;
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);// 初始
}
void NVIC_Configuration(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);//中断优先级配置
//设置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);
}
注意:GPIO驱动LED模式为GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;还是推挽输出。
中断处理函数:
void PVD_IRQHandler(void)
{
if(EXTI_GetITStatus(EXTI_Line16) != RESET)
{
STM_EVAL_LEDToggle(LED1);
EXTI_ClearITPendingBit(EXTI_Line16);
}
}
『本文转载自网络,版权归原作者所有,如有侵权请联系删除』