当前位置:网站首页>STM32 - Application of external interrupt induction lamp
STM32 - Application of external interrupt induction lamp
2022-07-03 01:36:00 【Spade fish】
STM32—— Application of external interruption induction lamp
List of articles
Description of project :
Environmental Overview :
Windows10 pro
MDK—Lite 5.25
step :
Configuration related files

Premise : Configure related structures
GPIO_InitTypeDef shake_init;
EXTI_InitTypeDef exti_init;
NVIC_InitTypeDef nvic_init;
To configure IO mouth 、 External interrupt clock 、 Multiplexed clock
// Configure external interrupt clock
// Reuse
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);
GPIO_EXTILineConfig(GPIO_PortSourceGPIOA, GPIO_PinSource1);
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);


1、 Initializes the used to interrupt GPIO mouth
shake_init.GPIO_Mode = GPIO_Mode_IPD;
shake_init.GPIO_Pin = GPIO_Pin_1;
shake_init.GPIO_Speed= GPIO_Speed_10MHz;
GPIO_Init(GPIOA,&shake_init);
This is to initialize the sensor IO mouth
2、 initialization EXTI External interrupt
// The interrupt line is consistent with the pin port
exti_init.EXTI_Line = EXTI_Line1;
exti_init.EXTI_LineCmd = ENABLE;
exti_init.EXTI_Mode = EXTI_Mode_Interrupt;
exti_init.EXTI_Trigger = EXTI_Trigger_Falling;
EXTI_Init(&exti_init);


3、 To configure NVIC Interrupt controller
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);

The parameters inside , How can we find it ?

As shown in the figure :

nvic_init.NVIC_IRQChannel = EXTI1_IRQn;
nvic_init.NVIC_IRQChannelSubPriority = 1;
nvic_init.NVIC_IRQChannelPreemptionPriority = 1;
nvic_init.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&nvic_init);
4、 Write interrupt service function
void EXTI1_IRQHandler(void)
{
if(EXTI_GetITStatus(EXTI_Line1) != RESET)// Determine whether an interruption has occurred
{
GPIO_ResetBits(GPIOA, GPIO_Pin_3);
delayTime(1000);
GPIO_SetBits(GPIOA, GPIO_Pin_3);
}
EXTI_ClearFlag( EXTI_Line1);
}

Determine whether an interruption has occurred



Code :
exti.c Code :
#include "exti.h"
#include "stm32f10x.h"
void Exti_Init(void){
// Configuration structure
GPIO_InitTypeDef shake_init;
EXTI_InitTypeDef exti_init;
NVIC_InitTypeDef nvic_init;
// Configure external interrupt clock
// Reuse
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);
GPIO_EXTILineConfig(GPIO_PortSourceGPIOA, GPIO_PinSource1);
//1、 Initializes the used to interrupt GPIO mouth
shake_init.GPIO_Mode = GPIO_Mode_IPD;
shake_init.GPIO_Pin = GPIO_Pin_1;
shake_init.GPIO_Speed= GPIO_Speed_10MHz;
GPIO_Init(GPIOA,&shake_init);
//2、 initialization EXTI External interrupt
// The interrupt line is consistent with the pin port
exti_init.EXTI_Line = EXTI_Line1;
exti_init.EXTI_LineCmd = ENABLE;
exti_init.EXTI_Mode = EXTI_Mode_Interrupt;
exti_init.EXTI_Trigger = EXTI_Trigger_Falling;
EXTI_Init(&exti_init);
//3、 To configure NVIC Interrupt controller
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
nvic_init.NVIC_IRQChannel = EXTI1_IRQn;
nvic_init.NVIC_IRQChannelSubPriority = 1;
nvic_init.NVIC_IRQChannelPreemptionPriority = 1;
nvic_init.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&nvic_init);
//4、 Write interrupt service function
}
exti.h Code :
#include "stm32f10x.h"
void Exti_Init(void);
main.c Code :
#include "stm32f10x.h"
#include "led.h"
#include "Relay.h"
#include "Shake.h"
#include "exti.h"
int main(void)
{
LED_Init();// The lamp
Relay_Init();// Relay
Shake_Init();// Vibration sensors
Exti_Init();
GPIO_SetBits(GPIOA, GPIO_Pin_3);// It's pins 3j Relay high level —— Turn off the lights
while(1){
}
}
void EXTI1_IRQHandler(void)
{
if(EXTI_GetITStatus(EXTI_Line1) != RESET)// Determine whether an interruption has occurred
{
GPIO_ResetBits(GPIOA, GPIO_Pin_3);
delayTime(1000);
GPIO_SetBits(GPIOA, GPIO_Pin_3);
}
EXTI_ClearFlag( EXTI_Line1);
}
边栏推荐
- 力扣 204. 计数质数
- 【数据挖掘】任务5:K-means/DBSCAN聚类:双层正方形
- Concise analysis of redis source code 11 - Main IO threads and redis 6.0 multi IO threads
- 数学知识:Nim游戏—博弈论
- [self management] time, energy and habit management
- Force buckle 204 Count prime
- 软考信息系统项目管理师_历年真题_2019下半年错题集_上午综合知识题---软考高级之信息系统项目管理师053
- [error record] the shutter component reports an error (no directionality widget found. | richtext widgets require a directionality)
- 看完这篇 教你玩转渗透测试靶机Vulnhub——DriftingBlues-9
- Scheme and practice of cold and hot separation of massive data
猜你喜欢

CF1617B Madoka and the Elegant Gift、CF1654C Alice and the Cake、 CF1696C Fishingprince Plays With Arr

【QT】自定义控件的封装

leetcode刷题_两数之和 II - 输入有序数组

传输层 TCP主要特点和TCP连接

串口抓包/截断工具的安装及使用详解

How is the mask effect achieved in the LPL ban/pick selection stage?
![[my advanced journey of OpenGL learning] collation of Euler angle, rotation order, rotation matrix, quaternion and other knowledge](/img/ed/23331d939c9338760e426d368bfd5f.png)
[my advanced journey of OpenGL learning] collation of Euler angle, rotation order, rotation matrix, quaternion and other knowledge

High resolution network (Part 1): Principle Analysis

Pytest learning notes (12) -allure feature · @allure Step () and allure attach
![[understanding of opportunity -36]: Guiguzi - flying clamp chapter - prevention against killing and bait](/img/c6/9aee30cb935b203c7c62b12c822085.jpg)
[understanding of opportunity -36]: Guiguzi - flying clamp chapter - prevention against killing and bait
随机推荐
[keil5 debugging] debug is stuck in reset_ Handler solution
LDC Build Shared Library
[shutter] animation animation (basic process of shutter animation | create animation controller | create animation | set value listener | set state listener | use animation values in layout | animatio
[error record] the shutter component reports an error (no directionality widget found. | richtext widgets require a directionality)
String splicing function of MySQL
uniapp组件-uni-notice-bar通告栏
Mathematical knowledge: divisible number inclusion exclusion principle
Uniapp component -uni notice bar notice bar
C#应用程序界面开发基础——窗体控制(4)——选择类控件
【系统分析师之路】第五章 复盘软件工程(开发模型开发方法)
[fh-gfsk] fh-gfsk signal analysis and blind demodulation research
[data mining] task 5: k-means/dbscan clustering: double square
JUC thread scheduling
QTableWidget懒加载剩内存,不卡!
MySQL - database query - condition query
C application interface development foundation - form control (4) - selection control
GDB 在嵌入式中的相关概念
C#应用程序界面开发基础——窗体控制(1)——Form窗体
VIM 9.0 is officially released! The execution speed of the new script can be increased by up to 100 times
The difference between tail -f, tail -f and tail