1、PA0 … PF0 共用一个中止标志 EXT0
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);