当前位置:网站首页>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);
}
}
边栏推荐
- Leetcode daily question (1856. maximum subarray min product)
- Nodemcu-esp8266 development (vscode+platformio+arduino framework): Part 1 -- establishment of engineering template -template
- Difference of EOF
- Convert IP address to int
- 专利查询网站
- Long类型的相等判断
- UCI and data multiplexing are transmitted on Pusch (Part V) -- polar coding
- Leetcode daily question (745. prefix and suffix search)
- unbuntu(debian)下TFTP服务器搭建及测试
- UCI and data multiplexing are transmitted on Pusch - Part I
猜你喜欢

Nodemcu-esp8266 development (vscode+platformio+arduino framework): Part 3 --blinker_ MIOT_ Light (lighting technology app control + Xiaoai classmate control)

The rise and fall of mobile phones in my perspective these 10 years

MySQL data manipulation language DML common commands
![[csdn] C1 analyse des questions de formation Partie III Bar _ JS Foundation](/img/b2/68d53ad09688f7fc922ac65e104f15.png)
[csdn] C1 analyse des questions de formation Partie III Bar _ JS Foundation
![[CSDN] C1 training problem analysis_ Part II_ Web Foundation](/img/91/72cdea3eb3f61315595330d2c9016d.png)
[CSDN] C1 training problem analysis_ Part II_ Web Foundation

端午节快乐!—— canvas写的粽子~~~~~

数字身份验证服务商ADVANCE.AI顺利加入深跨协 推进跨境电商行业可持续性发展

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

Spark cluster installation and deployment

LeetCode每日一题(2090. K Radius Subarray Averages)
随机推荐
Arduino handles JSON data, arduinojson assistant
Make the most basic root file system of Jetson nano and mount NFS file system on the server
CEF下载,编译工程
PRACH --- originator
QT sub window is blocked, and the main window cannot be clicked after the sub window pops up
[CSDN]C1训练题解析_第二部分_Web基础
Electronic product design
LeetCode每日一题(1024. Video Stitching)
Leetcode daily question (968. binary tree cameras)
CATIA automation object architecture - detailed explanation of application objects (III) systemservice
Successful graduation [2] - student health management system function development...
[combinatorics] Introduction to Combinatorics (context of combinatorics | skills of combinatorics | thought of combinatorics 1: one-to-one correspondence)
Nodemcu-esp8266 development (vscode+platformio+arduino framework): Part 1 -- establishment of engineering template -template
MySQL environment variable configuration
解决Editor.md上传图片获取不到图片地址问题
Leetcode daily question (2232. minimize result by addressing parents to expression)
Flink learning notes (10) Flink fault tolerance mechanism
Flink CDC practice (including practical steps and screenshots)
Leetcode daily question (931. minimum falling path sum)
Equality judgment of long type