当前位置:网站首页>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);
}
}
边栏推荐
- Make the most basic root file system of Jetson nano and mount NFS file system on the server
- 从0开始使用pnpm构建一个Monorepo方式管理的demo
- MySQL Data Definition Language DDL common commands
- [CSDN]C1訓練題解析_第三部分_JS基礎
- LeetCode每日一题(2232. Minimize Result by Adding Parentheses to Expression)
- Successful graduation [3]- blog system update...
- Shell logic case
- Jestson nano custom root file system creation (supports the smallest root file system of NVIDIA Graphics Library)
- 专利查询网站
- Starting from 0, use pnpm to build a demo managed by monorepo
猜你喜欢

Development of fire evacuation system

Development of fire power monitoring system

SSB Introduction (PbCH and DMRs need to be supplemented)

一款开源的Markdown转富文本编辑器的实现原理剖析

Error output redirection

Directory and switching operation in file system

Nr-prach:prach format and time-frequency domain

Definition and use of enum in C language

Nodemcu-esp8266 development board to build Arduino ide development environment
![[CSDN] C1 training problem analysis_ Part III_ JS Foundation](/img/b2/68d53ad09688f7fc922ac65e104f15.png)
[CSDN] C1 training problem analysis_ Part III_ JS Foundation
随机推荐
【男保姆式】教你打开第一个微信小程序
Nr-prach:prach format and time-frequency domain
Successful graduation [2] - student health management system function development...
LeetCode每日一题(1024. Video Stitching)
2021-09-26
PRACH --- originator
CEF下载,编译工程
MYSQL数据库底层基础专栏
Epoll read / write mode in LT and et modes
Usage of pandas to obtain MySQL data
Install local sources using yum
The number of weak characters in the game (1996)
Nodemcu-esp8266 development (vscode+platformio+arduino framework): Part 1 -- establishment of engineering template -template
[combinatorics] Introduction to Combinatorics (context of combinatorics | skills of combinatorics | thought of combinatorics 1: one-to-one correspondence)
Desktop icon recognition based on OpenCV
Jestson Nano 从tftp服务器下载更新kernel和dtb
Convert IP address to int
顺利毕业[2]-学生健康管理系统 功能开发中。。。
numpy. Reshape() and resize() functions
LeetCode每日一题(1856. Maximum Subarray Min-Product)