当前位置:网站首页>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);
}
}边栏推荐
- MySQL tutorial: MySQL database learning classic (from getting started to mastering)
- 简单使用 MySQL 索引
- File operation (I) -- File introduction and file opening and closing methods
- Information system project managers must recite the core examination site (50). The contract content is not clearly stipulated
- ShardingSphere数据分片
- assert _Aligns
- High score technical document sharing of ink Sky Wheel - Database Security (48 in total)
- 【方向盘】使用IDEA的60+个快捷键分享给你,权为了提效(重构篇)
- The sixth day of the third question of daily Luogu
- Shardingsphere data slicing
猜你喜欢

AMD64 (x86_64) architecture ABI document: medium

(9) Attribute introspection

软件测试岗:阿里三面,幸好做足了准备,已拿offer

Influence of middle tap change on ZVS oscillation circuit

DFS Niuke maze problem

朋友刚学完自动化测试就拿25Koffer,我功能测试何时才能到头?

Software testing post: Ali has three sides. Fortunately, he has made full preparations and has been offered

Win11大小写提示图标怎么关闭?Win11大小写提示图标的关闭方法

Safety margin of mass consumption

Annotation development management third-party beans
随机推荐
26 points that must be paid attention to for stability test
[steering wheel] tool improvement: common shortcut key set of sublime text 4
【C语言】深入理解 整型提升 和 算术转换
[detailed explanation of key and difficult points of document operation]
Influence of middle tap change on ZVS oscillation circuit
[steering wheel] use the 60 + shortcut keys of idea to share with you, in order to improve efficiency (live template & postfix completion)
Chapter 3 business function development (delete clues)
[pure theory] Yolo v4: optimal speed and accuracy of object detection
el-table 表头合并前四列,合并成一个单元格
AMD64(x86_64)架构abi文档:
Usage of fuser and lsof
After clicking play, the variables in editorwindow will be destroyed inexplicably
Wechat official account mutual aid, open white groups, and small white newspaper groups to keep warm
Shardingsphere data slicing
Application of shift distance and hypothesis
重装Win7系统如何进行?
How to effectively prevent others from wearing the homepage snapshot of the website
FPGA_Vivado软件初次使用流程_超详细
hello world驱动(二)-初级版
Masscode is an excellent open source code fragment manager