当前位置:网站首页>STM - exti external interrupt learning notes
STM - exti external interrupt learning notes
2022-07-26 03:00:00 【The poorest are beggars and immortals will always come out】
One 、 Introduction to external interrupts :
STM32 Of Every IO Can be used as an external interrupt Interrupt input port of , This is also true. STM32 The power of .STM32F103 The interrupt controller supports 19 External interrupts / Event request . Each interrupt is provided with a status bit , Every interrupt / Events have independent trigger and mask settings .
STM32F103 Of 19 An external interrupt is : Line 0~15: Corresponding to the outside IO The input of the port is interrupted ;
Line 16: Connect to PVD Output ;
Line 17: Connect to RTC Alarm clock event ;
Line 18: Connect to USB Wake Events ;
Two 、 Corresponding to interrupt channel IO mouth
GPIO Discipline GPIOx.0~GPIOx.15(x=A,B,C,D,E,F,G) Corresponding to the interrupt line respectively 0~15

3、 ... and 、 Mapping relationship of interrupt function
That is to say, for the break line (A、B、C、D、E、F)0~4, Each interrupt line corresponds to a separate interrupt function
trunk (A、B、C、D、E、F)5~9, Corresponding interrupt function EXTI9_5_IRQHander
trunk (A、B、C、D、E、F)10~15, Corresponding interrupt function EXTI15_10_IRQHander
It may not be easy to understand , for instance , I'm using PB12、PB13、PB14、PB15, These three IO When the port generates an interrupt, it will enter the interrupt function EXTI15_10_IRQHander in , Then determine the specific one inside the interrupt function IO Interrupt caused by port .

Four 、 Configuration process of external interruption
1、 First, configure those that need to use external interrupts IO mouth
example :KEY0→PB12 KEY1→PB13 KEY2→PB14 KEY3→PB15
void KEY_Init(void) //IO initialization
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(KEY1_GPIO_CLK,ENABLE);// Can make PORTB The clock
GPIO_InitStructure.GPIO_Pin = KEY0_GPIO_PIN | KEY1_GPIO_PIN | KEY2_GPIO_PIN | KEY3_GPIO_PIN;//KEY0-4
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; // Set as pull-up input
GPIO_Init(KEY1_GPIO_PORT, &GPIO_InitStructure); // initialization GPIO
}2、 Configure the corresponding interrupt line And Interrupt channel setting
GPIO_EXTILineConfig(GPIO_PortSourceGPIOB,GPIO_PinSource12);
EXTI_InitStructure.EXTI_Line=EXTI_Line12; //PB12 Corresponding EXTI_Line12
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; //( Select interrupt still event ) The interrupt
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling; // Falling edge trigger
EXTI_Init(&EXTI_InitStructure);
//GPIOB.13 Interrupt line and interrupt initialization configuration Falling edge trigger //KEY1
GPIO_EXTILineConfig(GPIO_PortSourceGPIOB,GPIO_PinSource13);
EXTI_InitStructure.EXTI_Line=EXTI_Line13;
EXTI_Init(&EXTI_InitStructure); // according to EXTI_InitStruct The parameter specified in EXTI register
//GPIOB.14 Interrupt line and interrupt initialization configuration Falling edge trigger //KEY2
GPIO_EXTILineConfig(GPIO_PortSourceGPIOB,GPIO_PinSource14);
EXTI_InitStructure.EXTI_Line=EXTI_Line14;
EXTI_Init(&EXTI_InitStructure); // according to EXTI_InitStruct The parameter specified in EXTI register
//GPIOB.14 Interrupt line and interrupt initialization configuration Falling edge trigger //KEY3
GPIO_EXTILineConfig(GPIO_PortSourceGPIOB,GPIO_PinSource15);
EXTI_InitStructure.EXTI_Line=EXTI_Line15;
EXTI_Init(&EXTI_InitStructure); // according to EXTI_InitStruct The parameter specified in EXTI register
NVIC_InitStructure.NVIC_IRQChannel = EXTI15_10_IRQn; // Enable key WK_UP External interrupt channel
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x00; // preemption 2,
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x00; // Sub priority 3
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; // Enable external interrupt channels
NVIC_Init(&NVIC_InitStructure); Four 、 Interrupt function :
void EXTI15_10_IRQHandler(void)
{
if(KEY0 == 0)
{
exti_flag=1;
EXTI_ClearITPendingBit(EXTI_Line12); // eliminate LINE0 Interrupt flag bit on
while(KEY0==0);
}
if(KEY1 == 0)
{
exti_flag=2;
EXTI_ClearITPendingBit(EXTI_Line13); // eliminate LINE0 Interrupt flag bit on
while(KEY1==0);
}
if(KEY2 == 0)
{
exti_flag=3;
EXTI_ClearITPendingBit(EXTI_Line14); // eliminate LINE0 Interrupt flag bit on
while(KEY2==0);
}
if(KEY3 == 0)
{
exti_flag=4;
EXTI_ClearITPendingBit(EXTI_Line15); // eliminate LINE0 Interrupt flag bit on
while(KEY3==0);
}
}边栏推荐
- Win11更改磁盘驱动器号的方法
- 案例:使用keepalived+Haproxy搭建Web群集
- Simply use MySQL index
- OxyCon 2022 网络抓取前沿大会即将开启!
- Neo4j 导入csv数据报错:Neo4j load csv error : Couldn‘t load the external resource
- Is it safe to open galaxy securities account by mobile phone?
- AMD64(x86_64)架构abi文档:中
- Masscode is an excellent open source code fragment manager
- Programming example of STM32 state machine -- fully automatic washing machine (Part 1)
- Pinia plugin persist, a data persistence plug-in of Pinia
猜你喜欢
随机推荐
Self-supervised learning method to solve the inverse problem of Fokker-Planck Equation
Literature speed reading | in the face of danger, anxious people run faster?
Arthas view the source code of the loaded class (JAD)
File operation (I) -- File introduction and file opening and closing methods
[translation] announce Vites 13
Pinia plugin persist, a data persistence plug-in of Pinia
Games101 review: rasterization
ShardingSphere数据分片
Longest Substring Without Repeating Characters
Get hours, minutes and seconds
Games101 review: shading, rendering pipelines
【方向盘】使用IDEA的60+个快捷键分享给你,权为了提效(重构篇)
Neo4j 导入csv数据报错:Neo4j load csv error : Couldn‘t load the external resource
微信公众号互助、开白群,小白报团取暖
富文本转化为普通文本
Pbootcms upload thumbnail size automatically reduces and blurs
Turn on the LED
Arthas download and startup
The El table header merges the first four columns into one cell
.net serialize enumeration as string








![[sql] case expression](/img/05/1bbb0b5099443f7ce5f5511703477e.png)