在线时间16 小时
UID303348
ST金币0
蝴蝶豆0
注册时间2011-7-5
金牌会员
- 最后登录
- 1970-1-1
|
发表于 2012-8-14 09:16:40
|
显示全部楼层
a0a.1 0b0c
回复:STM32F10x 的EXTI 問題【悬赏问答】
、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); |
|