本帖最后由 aaa2742 于 2016-10-29 16:28 编辑
问题是这样的:有一个光电开关,不挡光输出为5v,挡光后为0v,连接到中断引脚,测试用的PB14.光电开关是NPN型的,为了输出高电平加了一个几k的上拉。
外部中断IO的配置,我配置为下降沿触发,一般情况下外界传输到引脚为5v,某一时刻挡光后会进入中断,在中断处理函数中已经清了标记,但是我如果一直挡遮光,它会一直的进中断,不应该这样啊,挡住光后一直为低电平,没触发下降沿啊,这样岂不是成了电平触发了?
在配置上中断IO上,上拉,下拉,不拉都试过了,一直不停的进中断,哪位指点下?
初始化:void Exit_Init()
{
GPIO_InitTypeDef GPIO_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
EXTI_InitTypeDef EXTI_InitStructure;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);//使能GPIOB时钟
RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);//使能SYSCFG时钟
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;//普通输入模式
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN;
GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_14|GPIO_Pin_15;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;//普通输入模式
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOB, &GPIO_InitStructure);
SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOB, EXTI_PinSource13);
SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOB, EXTI_PinSource14);
SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOB, EXTI_PinSource15);
EXTI_InitStructure.EXTI_Line = EXTI_Line13;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;//中断事件
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising; //上升沿触发
EXTI_InitStructure.EXTI_LineCmd = ENABLE;//中断线使能
EXTI_Init(&EXTI_InitStructure);//配置
EXTI_InitStructure.EXTI_Line = EXTI_Line14;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;//中断事件
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling; //上升沿触发
EXTI_InitStructure.EXTI_LineCmd = ENABLE;//中断线使能
EXTI_Init(&EXTI_InitStructure);//配置
EXTI_InitStructure.EXTI_Line = EXTI_Line15;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;//中断事件
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling; //上升沿触发
EXTI_InitStructure.EXTI_LineCmd = ENABLE;//中断线使能
EXTI_Init(&EXTI_InitStructure);//配置
NVIC_InitStructure.NVIC_IRQChannel = EXTI15_10_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x02;//抢占优先级2
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x03;//子优先级2
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;//使能外部中断通道
NVIC_Init(&NVIC_InitStructure);//配置
}
中断处理:
void EXTI15_10_IRQHandler(void)
{
rt_interrupt_enter();
if(EXTI_GetITStatus(EXTI_Line13) != RESET)//轴电机物理零点
{
TimerRadialStop();
TimerRadialSetAngle(ShiftToZeroR);
TimerRadialStart();
//rt_event_send(&Intevent,(1 << 3));
EXTI_ClearITPendingBit(EXTI_Line13);
EXTI_ClearFlag(EXTI_Line13);
}
if(EXTI_GetITStatus(EXTI_Line14) != RESET)//径电机门限点
{
rt_event_send(&Intevent,(1 << 1));
EXTI_ClearITPendingBit(EXTI_Line14);
EXTI_ClearFlag(EXTI_Line14);
}
if(EXTI_GetITStatus(EXTI_Line15) != RESET)//径电机零点
{
rt_event_send(&Intevent,(1 << 2));
EXTI_ClearITPendingBit(EXTI_Line15);
EXTI_ClearFlag(EXTI_Line15);
}
rt_interrupt_leave();
}
|