STM32中共有23根中断总线
中断/事件线 | 输入源 |
---|---|
EXTI0 | PX0(X可为A、B、C、D、E、F~~) |
EXIT1 | PX1(X可为A、B、C、D、E、F~~) |
EXTI2 | PX2(X可为A、B、C、D、E、F~~) |
EXIT3 | PX3(X可为A、B、C、D、E、F~~) |
EXTI4 | PX4(X可为A、B、C、D、E、F~~) |
EXIT5 | PX5(X可为A、B、C、D、E、F~~) |
EXTI6 | PX6(X可为A、B、C、D、E、F~~) |
EXIT7 | PX7(X可为A、B、C、D、E、F~~) |
EXTI8 | PX8(X可为A、B、C、D、E、F~~) |
EXIT9 | PX9(X可为A、B、C、D、E、F~~) |
EXTI10 | PX10(X可为A、B、C、D、E、F~~) |
EXIT11 | PX11(X可为A、B、C、D、E、F~~) |
EXTI12 | PX12(X可为A、B、C、D、E、F~~) |
EXIT13 | PX13(X可为A、B、C、D、E、F~~) |
EXTI14 | PX14(X可为A、B、C、D、E、F~~) |
EXIT15 | PX15(X可为A、B、C、D、E、F~~) |
EXTI16 | PVD输出 |
EXIT17 | RTC闹钟事件 |
EXTI18 | USB OTG FS唤醒事件 |
EXIT19 | 太网唤醒事件 |
EXTI20 | USB OTG HS(在FS中配置)唤醒事件 |
EXIT21 | 连接到RTC入侵和时间戳事件 |
EXTI22 | 连接到RTC唤醒事件 |
详见[https://blog.csdn.net/conjurer_yft/article/details/106963994]
RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);//使能SYSCFG时钟
SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOA, EXTI_PinSource0);
参数1:端口组 EXTI_PortSourceGPIOA,
EXTI_PortSourceGPIOB,
EXTI_PortSourceGPIOC ~~~
参数2:中断线:EXTI_PinSource0 ~ EXTI_PinSource15
EXTI_InitTypeDef EXTI_InitStructure;
EXTI_InitStructure.EXTI_Line=中断线号;
中断线号:取值范围为EXTI_Line0~EXTI_Line15 //外部中断线0~15
EXTI_InitStructure.EXTI_Mode = 中断模式;
中断模式:
EXTI_Mode_Interrupt //设置EXIT为中断请求
EXTI_Mode_Event //设置EXIT为事件请求
EXTI_InitStructure.EXTI_Trigger =触发方式;
触发方式:
EXTI_Trigger_Falling //下降沿触发
EXTI_Trigger_Rising //上升沿触发
EXTI_Trigger_Rising_ Falling //上升沿和下降沿触发
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure); //初始化外设EXTI寄存器
| 优先级分组 | 主优先级(抢占优先级) | 子优先级 (响应优先级) | 描述 |
--------------------------------------------------------------------------
| NVIC_PriorityGroup_0 | 0 | 0-15 | 主-0bit,子-4bit |
| NVIC_PriorityGroup_1 | 0-1 | 0-7 | 主-1bit,子-3bit |
| NVIC_PriorityGroup_2 | 0-3 | 0-3 | 主-2bit,子-2bit |
| NVIC_PriorityGroup_3 | 0-7 | 0-1 | 主-3bit,子-1bit |
| NVIC_PriorityGroup_4 | 0-15 | 0 | 主-4bit,子-0bit |
--------------------------------------------------------------------------*/
NVIC_PriorityGroupConfig(优先级分组);
NVIC_InitTypeDef NVIC_InitStructure;
NVIC_InitStructure.NVIC_IRQChannel=中断通道;
中断通道:
EXTI0_IRQn
EXTI1_IRQn
EXTI2_IRQn
EXTI3_IRQn
EXTI9_5IRQn
EXTI5_10IRQn
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 抢占优先级
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 响应优先级
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
STM32F4的IO口外部中断函数只有7个,分别为:
EXPORT EXTI0_IRQHandler
EXPORT EXTI1_IRQHandler
EXPORT EXTI2_IRQHandler
EXPORT EXTI3_IRQHandler
EXPORT EXTI4_IRQHandler
EXPORT EXTI9_5_IRQHandler
EXPORT EXTI15_10_IRQHandler
中断线0-4每个中断线对应一个中断函数,中断线5-9共用中断函数EXTI9_5_IRQHandler,中断线10-15共用中断函数EXTI15_10_IRQHandler
void 外部中断函数(void)
{
}
EXTI_GetITStatus(中断线)!=RESET
EXTI_ClearITPendingBit(中断线);
中断线号:取值范围为EXTI_Line0~EXTI_Line15 //外部中断线0~15
void EXTI15_10_IRQHandler(void)
{
if (EXTI_GetITStatus(EXTI_Line13) != RESET)
{
EXTI_ClearITPendingBit(EXTI_Line13);
}
}