问题描述
- stm32 PVD掉电检测,进不了中断
-
芯片是stm32f103C8T6,PVD掉电检测,中断服务函数是通过串口发送数据。可是并没有发送,不知道是没有进入中断,还是进入了中断,但电压值过低,串口发送数据失败。求大神看看,写了好久没解决问题。代码如下:void PVD_Init(void)
{
SystemInit();EXTI_InitTypeDef EXTI_InitStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR,ENABLE);//PWR????/* Configure EXTI Line16(PVD Output) to generate an interrupt on rising and falling edges */
EXTI_ClearITPendingBit(EXTI_Line16);
EXTI_InitStructure.EXTI_Line = EXTI_Line16;
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 PVD_NVIC(void)
{
NVIC_InitTypeDef NVIC_InitStructure;/* Configure one bit for preemption priority */
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);/* Enable the PVD Interrupt */
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);
}void PVD_IRQHandler(void)
{
if(EXTI_GetITStatus(EXTI_Line16) != RESET)
{
GPIO_SetBits(GPIOA,GPIO_Pin_1);
start();//串口发送数据
EXTI_ClearITPendingBit(EXTI_Line16);
}
}int main()
{
.....PWR_PVDLevelConfig(PWR_PVDLevel_2V9);
PWR_PVDCmd(ENABLE);PVD_Init(); PVD_NVIC(); .... while(1) { ; }
}
解决方案
http://www.openedv.com/posts/list/10824.htm