我现在用的外部中断引脚是PB5,中断向量是EXTI9_5_IRQChannel,但是进入中断1次后就死机了。然后就是can't halt the core。 AFIO也打开了,郁闷了好几天了。
以下是我的配置程序:
时钟:
RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1|RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOB| RCC_APB2Periph_AFIO|RCC_APB2Periph_GPIOC|RCC_APB2Periph_USART1, ENABLE);
I/O:
//PB5作为PDI外部中断,IO设为输悬浮输入
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
GPIO_Init(GPIOB, &GPIO_InitStructure);
EXTI初始化:
void ExtiInit(void)
{
EXTI_InitTypeDef EXTI_InitStructure;
/* Connect Key Button EXTI Line to Key Button GPIO Pin */
EXTI_InitStructure.EXTI_Line = EXTI_Line5;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
GPIO_EXTILineConfig(GPIO_PortSourceGPIOB, GPIO_PinSource5);
}
配置NVIC:
void DrvierNVICConfig(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
#ifdef VECT_TAB_RAM
/* Set the Vector Table base location at 0x20000000 */
NVIC_SetVectorTable(NVIC_VectTab_RAM, 0x0);
#else /* VECT_TAB_FLASH */
/* Set the Vector Table base location at 0x08000000 */
NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0);
#endif
/* enable DMA1_Channel1 interrupt from nivc */
NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQChannel;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
/* Enable the EXTI5_IRQChannel Interrupt */
NVIC_InitStructure.NVIC_IRQChannel = EXTI9_5_IRQChannel; //PDI掉电中断
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
中断服务程序:
void EXTI9_5_IRQHandler(void)
{
if(EXTI_GetITStatus(EXTI_Line5) != RESET)
{
if(PDI_FLAG==0)
{
LcdCommand(0xAE); //关显示
PDI_FLAG=1;
}
else
{
LcdCommand(0xAF); //开显示
PDI_FLAG=0;
}
// /* Clear the Key Button EXTI line pending bit */
EXTI_ClearITPendingBit(EXTI_Line5);
}
} |