当前位置:网站首页>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);
}
边栏推荐
- Mathematical knowledge: step Nim game game game theory
- High-Resolution Network (篇一):原理刨析
- After reading this article, I will teach you to play with the penetration test target vulnhub - drivetingblues-9
- Makefile中wildcard、patsubst、notdir的含义
- C application interface development foundation - form control (4) - selection control
- Summary of interval knowledge
- 數學知識:臺階-Nim遊戲—博弈論
- MySQL - database query - basic query
- MySQL foundation 05 DML language
- [FPGA tutorial case 5] ROM design and Implementation Based on vivado core
猜你喜欢

Why is it not recommended to use BeanUtils in production?

简易分析fgui依赖关系工具

【数据挖掘】任务1:距离计算

【数据挖掘】任务4:20Newsgroups聚类

Database SQL language 02 connection query

How is the mask effect achieved in the LPL ban/pick selection stage?

一比特苦逼程序員的找工作經曆

Introduction to flask tutorial

C application interface development foundation - form control (2) - MDI form

MySQL foundation 04 MySQL architecture
随机推荐
强化学习 Q-learning 实例详解
Mathematical Knowledge: Steps - Nim Games - Game Theory
[technology development-23]: application of DSP in future converged networks
Now that the teenager has returned, the world's fireworks are the most soothing and ordinary people return to work~
[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
C application interface development foundation - form control (4) - selection control
电信客户流失预测挑战赛
一比特苦逼程序員的找工作經曆
Mathematical knowledge: divisible number inclusion exclusion principle
VIM 9.0 is officially released! The execution speed of the new script can be increased by up to 100 times
wirehark数据分析与取证A.pacapng
2022 coal mine gas drainage examination question bank and coal mine gas drainage examination questions and analysis
[FPGA tutorial case 5] ROM design and Implementation Based on vivado core
Arduino DY-SV17F自动语音播报
LeetCode 987. Vertical order transverse of a binary tree - Binary Tree Series Question 7
Pytest learning notes (12) -allure feature · @allure Step () and allure attach
Uniapp component -uni notice bar notice bar
MySQL foundation 07-dcl
GDB 在嵌入式中的相关概念
Makefile中wildcard、patsubst、notdir的含义