昨晚stm32f101遇到奇怪问题:外部中断函数总是重复进入,但是io绝对没有变化。相关代码如下
请大家指点。原来用stm32f103也是类似用法,这次真的郁闷了,清楚中断标志后还是会再次进来。
void EXTI15_10_IRQHandler(void)
{
if(EXTI_GetITStatus(EXTI_Line13) != RESET)
{
i=GPIO_ReadInputDataBit(RI_GPIO);
if (i==0) noevent_counter=0;
else noevent_counter++;
/EXTI_ClearITPendingBit(EXTI_Line13);
}
}
void open_INT ( void ){
NVIC_InitTypeDef NVIC_InitStructure;
EXTI_InitTypeDef EXTI_InitStructure;
/* Enable the EXTI13 Interrupt */
NVIC_InitStructure.NVIC_IRQChannel = EXTI15_10_IRQChannel;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 3;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
/* Connect EXTI Line1 to Pb.13 */
GPIO_EXTILineConfig(GPIO_PortSourceGPIOB, GPIO_PinSource13);
/* Configure EXTI Line4 to generate an interrupt on falling edge */
EXTI_InitStructure.EXTI_Line = EXTI_Line13;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;//EXTI_Trigger_Falling;
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
EXTI_ClearITPendingBit(EXTI_Line13);
}
void GpioInputInit (void)
{
GPIO_InitTypeDef GPIO_InitStructure;
// GPIO Init
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO | RCC_APB2Periph_GPIOA |
RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOD, ENABLE);
/* Configure the pc as input floating */
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3 |GPIO_Pin_5 |GPIO_Pin_6 |GPIO_Pin_13;
GPIO_Init(GPIOC, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11 ;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin =GPIO_Pin_0 |GPIO_Pin_1 |GPIO_Pin_13 ;
GPIO_Init(GPIOB, &GPIO_InitStructure);
} |