当前位置:网站首页>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);
}
}边栏推荐
- 【方向盘】启动命令和IDEA如何传递:VM参数、命令行参数、系统参数、环境变量参数、main方法参数
- Annotation development management third-party beans
- 图像识别(七)| 池化层是什么?有什么作用?
- Difference between soft link and hard link
- [steering wheel] how to transfer the start command and idea: VM parameters, command line parameters, system parameters, environment variable parameters, main method parameters
- 朋友刚学完自动化测试就拿25Koffer,我功能测试何时才能到头?
- [SQL] 自连接的用法
- Oxycon 2022 network capture frontier conference is about to open!
- Arthas download and startup
- Shardingsphere data slicing
猜你喜欢

Turn on the LED

图像识别(七)| 池化层是什么?有什么作用?

DFS Niuke maze problem

JS get the time composition array of two time periods

【方向盘】使用IDEA的60+个快捷键分享给你,权为了提效(Live Template&Postfix Completion篇)

MySQL建Websites数据表

The LAAS protocol elephant of defi 2.0 is the key to revitalizing the development of defi track

ES6 advanced - using prototype object inheritance methods

Keil's operation before programming with C language

Image recognition (VII) | what is the pooling layer? What's the effect?
随机推荐
Be highly vigilant! Weaponization of smartphone location data on the battlefield
HLS Experiment 1 -- multiplier
Chapter 3 business function development (delete clues)
这种动态规划你见过吗——状态机动态规划之股票问题(上)
.net serialize enumeration as string
(9) Attribute introspection
Machine learning foundation plan 0-2: what is machine learning? What does it have to do with AI?
[steering wheel] use the 60 + shortcut keys of idea to share with you, in order to improve efficiency (live template & postfix completion)
How to effectively prevent others from wearing the homepage snapshot of the website
GoLang 抽奖系统 设计
【方向盘】工具提效:Sublime Text 4的常用快捷键合集
手把手教你依赖管理
AMD64(x86_64)架构abi文档:中
Extended Physics-InformedNeural Networks论文详解
MySQL tutorial: MySQL database learning classic (from getting started to mastering)
The El table header merges the first four columns into one cell
[translation] cloud like internal load balancer for kubernetes?
Pbootcms upload thumbnail size automatically reduces and blurs
hello world驱动(二)-初级版
图像识别(六)| 激活函数