微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > STM32学习笔记--EXTI

STM32学习笔记--EXTI

时间:11-11 来源:互联网 点击:
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);

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top