当前位置:网站首页>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);
}
}
边栏推荐
- Quickly use markdown to edit articles
- Leetcode daily question (1024. video sticking)
- LeetCode每日一题(516. Longest Palindromic Subsequence)
- Leetcode daily question (985. sum of even numbers after queries)
- Nr-prach:prach format and time-frequency domain
- LeetCode每日一题(2232. Minimize Result by Adding Parentheses to Expression)
- Development of fire evacuation system
- Leetcode daily question (2109. adding spaces to a string)
- Flink CDC practice (including practical steps and screenshots)
- LeetCode每日一题(2090. K Radius Subarray Averages)
猜你喜欢

How does the nr-prach receiver detect the relationship between prembleid and Ta

UCI and data multiplexing are transmitted on Pusch (Part V) -- polar coding

Electronic product design

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

JMX、MBean、MXBean、MBeanServer 入门
![【顺利毕业】[1]-游览 [学生管理信息系统]](/img/91/72cdea3eb3f61315595330d2c9016d.png)
【顺利毕业】[1]-游览 [学生管理信息系统]

Leetcode daily question (931. minimum falling path sum)
![顺利毕业[2]-学生健康管理系统 功能开发中。。。](/img/91/72cdea3eb3f61315595330d2c9016d.png)
顺利毕业[2]-学生健康管理系统 功能开发中。。。

MySQL data manipulation language DML common commands

LeetCode每日一题(1162. As Far from Land as Possible)
随机推荐
Alibaba cloud notes for the first time
Leetcode daily question (2232. minimize result by addressing parents to expression)
Desktop icon recognition based on OpenCV
软件测试工程师是做什么的 通过技术测试软件程序中是否有漏洞
Leetcode daily question (2212. maximum points in an archery competition)
Jestson nano downloads updated kernel and DTB from TFTP server
Getting started with shell programming
Development of fire evacuation system
Epoll read / write mode in LT and et modes
Arduino handles JSON data, arduinojson assistant
CEF下载,编译工程
[combinatorics] Introduction to Combinatorics (context of combinatorics | skills of combinatorics | thought of combinatorics 1: one-to-one correspondence)
[CSDN] C1 training problem analysis_ Part IV_ Advanced web
UCI and data multiplexing are transmitted on Pusch (Part V) -- polar coding
307. Range Sum Query - Mutable
PolyWorks script development learning notes (I) - script development environment
Send mail using WP mail SMTP plug-in
LeetCode每日一题(931. Minimum Falling Path Sum)
Apply for domain name binding IP to open port 80 record
LeetCode每日一题(2115. Find All Possible Recipes from Given Supplies)