STM32学习笔记--EXTI
PA1 ... PF1 共用一个中断标志 EXT1
. .
. .
PA15... PF15共用一个中断标志 EXT15
2、EXT5-9 共用一个中断源
EXT10-15 共用一个中断源
3、启用中断前,需ENABLE IO口的复用功能(AFIO)
4、设置中断IO口
5、将IO口注册到中断线(将IO口映射到中断线N)
例:GPIO_EXTILineConfig(GPIO_PortSourceGPIOD, GPIO_PinSource3); 将GPIOD.3注册至
中断线EXTILine3
GPIO_EXTILineConfig(GPIO_PortSourceGPIOD, GPIO_PinSource4); 将GPIOD.4注册至
中断线EXTILine4
6、配置中断
EXTI_InitStructure.EXTI_Line = EXTI_Line3;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; 中断
= EXTI_Mode_Event 事件(触发其它模块)
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising 上升沿触发
= EXTI_Trigger_Falling 下降沿触发
= EXTI_Trigger_Rising_Falling 脉冲触发
7、配置NVIC
8、如果使用库函数写中断,要开放stm32f10x_conf.h中的相应中断
----------------------------------------------------------------------------------------------------
例:
RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOD|RCC_APB2Periph_AFIO, ENABLE);
/* PD3,4,5,6按键输入*/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3|GPIO_Pin_4|GPIO_Pin_5|GPIO_Pin_6;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; //上拉输入
GPIO_Init(GPIOD, &GPIO_InitStructure);
/* 连接IO口到中断线 */
GPIO_EXTILineConfig(GPIO_PortSourceGPIOD, GPIO_PinSource3);
GPIO_EXTILineConfig(GPIO_PortSourceGPIOD, GPIO_PinSource4);
GPIO_EXTILineConfig(GPIO_PortSourceGPIOD, GPIO_PinSource5);
GPIO_EXTILineConfig(GPIO_PortSourceGPIOD, GPIO_PinSource6);
/* 配置中断线3为边降沿触发*/
EXTI_InitStructure.EXTI_Line = EXTI_Line3;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising_Falling;
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
/*其他为下降沿触发*/
EXTI_InitStructure.EXTI_Line = EXTI_Line4|EXTI_Line5|EXTI_Line6;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
STM32EXT 相关文章:
- STM32 之 EXTI(12-03)
- stm32学习之六(12-03)
- STM32的exti中断调试遇到一奇怪问题总结(11-30)
- STM32 EXTI中断设置五步曲(11-26)
- STM32 EXTI的配置(11-18)
- STM32 EXTI外部中断(11-13)