当前位置:网站首页>STM32 external interrupt experiment
STM32 external interrupt experiment
2022-07-03 09:41:00 【two thousand and twenty-one point zero nine】
One 、 Reference material

Two 、 Overview of external interrupts


interrupt 1-4 There is a separate interrupt service function .
interrupt 5-9 Share an interrupt service function .
interrupt 10-15 Share an interrupt service function .

The interrupt service function is in startup_stm32f10x_hs.s Find .

3、 ... and 、 Common library functions for external interrupts


Four 、 General configuration steps for external interrupts

1、 initialization IO The mouth is the input
because KEY0、KEY1、KEY2、KEY3 Ground so use pull-up input , Release the key to high level , Press the key for low level .
So trigger with falling edge .
KEY_UP contrary , Connected to high level , Use the drop-down to enter . Release the key to low level , Press the key to high level ,
So trigger with rising edge .

RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOE,ENABLE);
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IPU;
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_2|GPIO_Pin_3|GPIO_Pin_4;
//GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_Init(GPIOE,&GPIO_InitStructure);
GPIO_SetBits(GPIOE,GPIO_Pin_2|GPIO_Pin_3|GPIO_Pin_4);
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IPD;
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_0;
//GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_Init(GPIOA,&GPIO_InitStructure);
GPIO_ResetBits(GPIOA,GPIO_Pin_0); 2、 Turn on IO Port multiplex clock
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE); // Can make AFIO The clock , This is the premise of calling external interrupts
3、 Set up IO Mapping relationship between port and interrupt line
GPIO_EXTILineConfig(GPIO_PortSourceGPIOE,GPIO_PinSource4); // hold PE4 and EXTI4 It maps
4、 Initialize online interrupt , Set trigger conditions
EXTI_InitTypeDef EXTI_InitStruct;
EXTI_InitStruct.EXTI_Line = EXTI_Line4;
EXTI_InitStruct.EXTI_LineCmd = ENABLE;
EXTI_InitStruct.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStruct.EXTI_Trigger = EXTI_Trigger_Falling;
EXTI_Init(&EXTI_InitStruct);5、 Configure interrupt grouping , And can interrupt
among ,EXTI4_IRQn from stm32f10x.h Inside looking for .
NVIC_InitTypeDef NVIC_InitStruct;
NVIC_InitStruct.NVIC_IRQChannel = EXTI4_IRQn;
NVIC_InitStruct.NVIC_IRQChannelCmd = ENABLE;
NVIC_InitStruct.NVIC_IRQChannelPreemptionPriority = 2;
NVIC_InitStruct.NVIC_IRQChannelSubPriority = 2;
NVIC_Init(&NVIC_InitStruct);6、 Write interrupt service function 、 Clears the interrupt flag bit
Interrupt service function EXTI4_IRQHandler It's defined , stay startup_stm32f10x_hs.s Find .
void EXTI4_IRQHandler(void)
{
delay_ms(10);
if(KEY3==0)
{
LED0=!LED0;
LED1=!LED1;
}
EXTI_ClearITPendingBit(EXTI_Line4);
}7、 stay exti.c Integrated inside
#include "stm32f10x.h"
#include "delay.h"
#include "key.h"
#include "led.h"
#include "beep.h"
#include "exti.h"
void exti_Init(void)
{
EXTI_InitTypeDef EXTI_InitStruct;
NVIC_InitTypeDef NVIC_InitStruct;
void key_init(); //GPIO Initialize as input , and key_init() equally
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE); // Can make AFIO The clock , This is the premise of calling external interrupts
GPIO_EXTILineConfig(GPIO_PortSourceGPIOE,GPIO_PinSource4); // hold PE4 and EXTI4 It maps
EXTI_InitStruct.EXTI_Line = EXTI_Line4;
EXTI_InitStruct.EXTI_LineCmd = ENABLE;
EXTI_InitStruct.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStruct.EXTI_Trigger = EXTI_Trigger_Falling;
EXTI_Init(&EXTI_InitStruct);
NVIC_InitStruct.NVIC_IRQChannel = EXTI4_IRQn;
NVIC_InitStruct.NVIC_IRQChannelCmd = ENABLE;
NVIC_InitStruct.NVIC_IRQChannelPreemptionPriority = 2;
NVIC_InitStruct.NVIC_IRQChannelSubPriority = 2;
NVIC_Init(&NVIC_InitStruct);
}
void EXTI4_IRQHandler(void)
{
delay_ms(10);
if(KEY3==0)
{
LED0=!LED0;
LED1=!LED1;
}
EXTI_ClearITPendingBit(EXTI_Line4);
}
8、exti.h
#ifndef __EXTI__H
#define __EXTI__H
#include "sys.h"
void exti_Init(void);
#endif
9、main.c
#include "stm32f10x.h"
#include "delay.h"
#include "exti.h"
#include "led.h"
#include "beep.h"
#include "key.h"
#include "usart.h"
int main(void)
{
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
delay_init();
led_init();
beep_init();
key_init();
exti_Init();
uart_init(115200);
LED0 = 0;
while(1)
{
printf("OK\r\n");
delay_ms(10);
}
}
边栏推荐
- 2021-09-26
- Make the most basic root file system of Jetson nano and mount NFS file system on the server
- Nodemcu-esp8266 development (vscode+platformio+arduino framework): Part 5 --blinker_ MIOT_ MULTI_ Outside (lighting technology app + Xiaoai classmate control socket multiple jacks)
- Installation and uninstallation of pyenv
- 从0开始使用pnpm构建一个Monorepo方式管理的demo
- Development of fire evacuation system
- Solve the problem of disordered code in vscode development, output Chinese and open source code
- Leetcode daily question (1362. closest divisors)
- UCI and data multiplexing are transmitted on Pusch - placement of data and UCI positions (Part III)
- Leetcode daily question (968. binary tree cameras)
猜你喜欢
![顺利毕业[3]-博客系统 更新中。。。](/img/91/72cdea3eb3f61315595330d2c9016d.png)
顺利毕业[3]-博客系统 更新中。。。

Nr--- Pusch I: sorting out the agreement process

Difference of EOF

IDEA远程断点调试jar包项目

Electronic product design

Global KYC service provider advance AI in vivo detection products have passed ISO international safety certification, and the product capability has reached a new level
![【顺利毕业】[1]-游览 [学生管理信息系统]](/img/91/72cdea3eb3f61315595330d2c9016d.png)
【顺利毕业】[1]-游览 [学生管理信息系统]
![Successful graduation [2] - student health management system function development...](/img/91/72cdea3eb3f61315595330d2c9016d.png)
Successful graduation [2] - student health management system function development...
![[CSDN]C1訓練題解析_第三部分_JS基礎](/img/b2/68d53ad09688f7fc922ac65e104f15.png)
[CSDN]C1訓練題解析_第三部分_JS基礎

SSB Introduction (PbCH and DMRs need to be supplemented)
随机推荐
小王叔叔的博客目录【持续更新中】
LeetCode每日一题(745. Prefix and Suffix Search)
Jestson Nano自定义根文件系统创建(支持NVIDIA图形库的最小根文件系统)
DSP data calculation error
【22毕业季】我是毕业生yo~
Leetcode daily question (2232. minimize result by addressing parents to expression)
Getting started with shell programming
Leetcode daily question (1856. maximum subarray min product)
PolyWorks script development learning notes (I) - script development environment
UCI and data multiplexing are transmitted on Pusch (Part VI) -- LDPC coding
Flask+supervisor installation realizes background process resident
UCI and data multiplexing are transmitted on Pusch (Part V) -- polar coding
Please tell me how to set vscode
Leetcode daily question (516. long palindromic subsequence)
【順利畢業】[1]-遊覽 [學生管理信息系統]
Alibaba cloud notes for the first time
Desktop icon recognition based on OpenCV
UCI and data multiplexing are transmitted on Pusch (Part 4) --small block lengths
专利查询网站
LeetCode每日一题(985. Sum of Even Numbers After Queries)