外部中断只能响应一次,求大神指点!
时间:10-02
整理:3721RD
点击:
使用PB12,PB13,PE14,PE15作为外部中断,PE14,PE15响应正常,但PB12,PB13无法正常进入中断,代码如下,求指点。
void EXTI15_10_IRQHandler(void)
{
//KEY_OK
if(EXTI_GetITStatus(EXTI_Line14)==SET)
{
IO_OutputData(0x00);
delay_us(10);
EXTI_ClearITPendingBit(EXTI_Line14);
}
//KEY_UP
if(EXTI_GetITStatus(EXTI_Line15)==SET)
{
IO_OutputData(0xff);
delay_us(10);
EXTI_ClearITPendingBit(EXTI_Line15);
}
//KEY_DOWN
if(EXTI_GetITStatus(EXTI_Line12)==SET)
{
IO_OutputData(0xff);
delay_us(10);
EXTI_ClearITPendingBit(EXTI_Line12);
}
//KEY_CANCEL
if(EXTI_GetITStatus(EXTI_Line13)==SET)
{
IO_OutputData(0x00);
delay_us(10);
EXTI_ClearITPendingBit(EXTI_Line13);
}
}
----------------------------------------------------------------------
void NVIC_Configuration(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
NVIC_InitStructure.NVIC_IRQChannel = EXTI15_10_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
--------------------------------------------------------------------------------------
void KEY_config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
EXTI_InitTypeDef EXTI_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOE, ENABLE);
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
//GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Pin = KEY_OK | KEY_UP;
GPIO_Init(GPIOE, &GPIO_InitStructure);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
//GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Pin = KEY_DOWN | KEY_CANCEL;
GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_EXTILineConfig(GPIO_PortSourceGPIOE, GPIO_PinSource14);
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);
GPIO_EXTILineConfig(GPIO_PortSourceGPIOE, GPIO_PinSource15);
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);
GPIO_EXTILineConfig(GPIO_PortSourceGPIOB, GPIO_PinSource12);
EXTI_InitStructure.EXTI_Line = EXTI_Line12 ;
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_PinSource13);
EXTI_InitStructure.EXTI_Line = EXTI_Line13;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
EXTI_ClearITPendingBit(EXTI_Line12);
EXTI_ClearITPendingBit(EXTI_Line13);
EXTI_ClearITPendingBit(EXTI_Line14);
EXTI_ClearITPendingBit(EXTI_Line15);
}
void EXTI15_10_IRQHandler(void)
{
//KEY_OK
if(EXTI_GetITStatus(EXTI_Line14)==SET)
{
IO_OutputData(0x00);
delay_us(10);
EXTI_ClearITPendingBit(EXTI_Line14);
}
//KEY_UP
if(EXTI_GetITStatus(EXTI_Line15)==SET)
{
IO_OutputData(0xff);
delay_us(10);
EXTI_ClearITPendingBit(EXTI_Line15);
}
//KEY_DOWN
if(EXTI_GetITStatus(EXTI_Line12)==SET)
{
IO_OutputData(0xff);
delay_us(10);
EXTI_ClearITPendingBit(EXTI_Line12);
}
//KEY_CANCEL
if(EXTI_GetITStatus(EXTI_Line13)==SET)
{
IO_OutputData(0x00);
delay_us(10);
EXTI_ClearITPendingBit(EXTI_Line13);
}
}
----------------------------------------------------------------------
void NVIC_Configuration(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
NVIC_InitStructure.NVIC_IRQChannel = EXTI15_10_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
--------------------------------------------------------------------------------------
void KEY_config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
EXTI_InitTypeDef EXTI_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOE, ENABLE);
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
//GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Pin = KEY_OK | KEY_UP;
GPIO_Init(GPIOE, &GPIO_InitStructure);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
//GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Pin = KEY_DOWN | KEY_CANCEL;
GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_EXTILineConfig(GPIO_PortSourceGPIOE, GPIO_PinSource14);
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);
GPIO_EXTILineConfig(GPIO_PortSourceGPIOE, GPIO_PinSource15);
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);
GPIO_EXTILineConfig(GPIO_PortSourceGPIOB, GPIO_PinSource12);
EXTI_InitStructure.EXTI_Line = EXTI_Line12 ;
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_PinSource13);
EXTI_InitStructure.EXTI_Line = EXTI_Line13;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
EXTI_ClearITPendingBit(EXTI_Line12);
EXTI_ClearITPendingBit(EXTI_Line13);
EXTI_ClearITPendingBit(EXTI_Line14);
EXTI_ClearITPendingBit(EXTI_Line15);
}
单步调试下,看进入中断后能不能出来
昨晚试过单步调试,发现PB12,PB13上拉不正常,仅在初始化是上拉,一旦拉低,就不能再次拉高,一直保持低电平,所以只能相应一次中断,把NVIC_Configuration();注释掉,上拉就恢复正常了,求大神指点
会不会你pb口有连焊的现象,因为他们优先级都一样,不是很清楚
已解决,原来是
GPIOB->BSRR = (IO_B_L & 0xff)|(~IO_B_L & 0xff)<<16|(IO_B_H & 0xff)<<8|(~IO_B_H & 0xff)<<24;
改成
GPIOB->BSRR = (IO_B_L & 0xff)|(~IO_B_L & 0xff)<<16|(IO_B_H & 0x03)<<8|(~IO_B_H & 0x03)<<24;
就OK了
我的也是,小编的解决了吗?
我的也是,小编的解决了吗?
我的也是,小编的解决了吗?
LZ 可以问个关于STC_12的问题不
你好,我先在也是遇到这个问题,STM32外部中断是下降沿触发,但是只能进一次中断,用示波器看中断引脚电平是由高电平变为低电平不回去了,能加个好友交流一下吗QQ845879972