21ic问答首页 - AT32F421C8T7外部中断问题
AT32F421C8T7外部中断问题
骑行青年2021-01-21
程序将PB2引脚作为外部中断引脚,程序配置之后,引脚上电平变化时程序不能进入中断处理函数。以下为代码,请各位帮忙看看是否有配置不对的地方。
void check_gpio_init(void)
{
GPIO_InitType GPIO_InitStructure;
EXTI_InitType EXTI_InitStructure;
NVIC_InitType NVIC_InitStructure;
RCC_AHBPeriphClockCmd(RCC_AHBPERIPH_GPIOB,ENABLE);
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
GPIO_InitStructure.GPIO_Pull = GPIO_Pull_NOPULL;
GPIO_InitStructure.GPIO_MaxSpeed = GPIO_MaxSpeed_50MHz;
GPIO_InitStructure.GPIO_OutType = GPIO_OutType_PP;
GPIO_InitStructure.GPIO_Pins = GPIO_Pins_2;
GPIO_Init(GPIOB,&GPIO_InitStructure);
SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOB,EXTI_PinSource2);
EXTI_InitStructure.EXTI_Line = EXTI_Line2;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
EXTI_InitStructure.EXTI_LineEnable = ENABLE;
EXTI_Init(&EXTI_InitStructure);
NVIC_InitStructure.NVIC_IRQChannel = EXTI3_2_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
void EXTI3_2_IRQHandler(void)
{
if(EXTI_GetIntStatus(EXTI_Line2) != RESET)
{
if(check_pin_read() == RESET)
{
irq_count++;
if(irq_count >= 20)
{
fault_status = 0;
irq_count = 0;
//device_check_en(DISABLE);
}
}
EXTI_ClearIntPendingBit(EXTI_Line2);
}
}
下载视频
void check_gpio_init(void)
{
GPIO_InitType GPIO_InitStructure;
EXTI_InitType EXTI_InitStructure;
NVIC_InitType NVIC_InitStructure;
RCC_AHBPeriphClockCmd(RCC_AHBPERIPH_GPIOB,ENABLE);
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
GPIO_InitStructure.GPIO_Pull = GPIO_Pull_NOPULL;
GPIO_InitStructure.GPIO_MaxSpeed = GPIO_MaxSpeed_50MHz;
GPIO_InitStructure.GPIO_OutType = GPIO_OutType_PP;
GPIO_InitStructure.GPIO_Pins = GPIO_Pins_2;
GPIO_Init(GPIOB,&GPIO_InitStructure);
SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOB,EXTI_PinSource2);
EXTI_InitStructure.EXTI_Line = EXTI_Line2;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
EXTI_InitStructure.EXTI_LineEnable = ENABLE;
EXTI_Init(&EXTI_InitStructure);
NVIC_InitStructure.NVIC_IRQChannel = EXTI3_2_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
void EXTI3_2_IRQHandler(void)
{
if(EXTI_GetIntStatus(EXTI_Line2) != RESET)
{
if(check_pin_read() == RESET)
{
irq_count++;
if(irq_count >= 20)
{
fault_status = 0;
irq_count = 0;
//device_check_en(DISABLE);
}
}
EXTI_ClearIntPendingBit(EXTI_Line2);
}
}
下载视频
赞0
直接跑bsp中exti example试试。
评论
2021-01-21
您需要登录后才可以回复 登录 | 注册