当前位置:网站首页>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);
}
边栏推荐
- 【数据挖掘】任务6:DBSCAN聚类
- MySQL - database query - basic query
- The thread reuse problem of PageHelper using ThreadLocal, did you use it correctly?
- [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
- 对非ts/js文件模块进行类型扩充
- 不登陆或者登录解决oracle数据库账号被锁定。
- 【数据挖掘】任务2:医学数据库MIMIC-III数据处理
- Arduino DY-SV17F自动语音播报
- Common English Vocabulary
- 数学知识:Nim游戏—博弈论
猜你喜欢
![[机缘参悟-36]:鬼谷子-飞箝篇 - 面对捧杀与诱饵的防范之道](/img/c6/9aee30cb935b203c7c62b12c822085.jpg)
[机缘参悟-36]:鬼谷子-飞箝篇 - 面对捧杀与诱饵的防范之道

leetcode 2097 — 合法重新排列数对

Why is it not recommended to use BeanUtils in production?

Introduction to flask tutorial

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

Three core issues of concurrent programming - "deep understanding of high concurrent programming"

串口抓包/截断工具的安装及使用详解
![[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](/img/70/54eb9359ac91aa43383b240eb036b7.gif)
[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

Detailed explanation of Q-learning examples of reinforcement learning

CF1617B Madoka and the Elegant Gift、CF1654C Alice and the Cake、 CF1696C Fishingprince Plays With Arr
随机推荐
[principles of multithreading and high concurrency: 2. Solutions to cache consistency]
Installation and use of serial port packet capturing / cutting tool
Detailed explanation of Q-learning examples of reinforcement learning
[FPGA tutorial case 5] ROM design and Implementation Based on vivado core
【第29天】给定一个整数,请你求出它的因子数
一比特苦逼程序員的找工作經曆
音程的知识的总结
MySQL foundation 06 DDL
串口抓包/截断工具的安装及使用详解
The difference between tail -f, tail -f and tail
Concise analysis of redis source code 11 - Main IO threads and redis 6.0 multi IO threads
Database SQL language 01 where condition
Makefile中wildcard、patsubst、notdir的含义
MySQL foundation 05 DML language
Learn the five skills you need to master in cloud computing application development
[my advanced journey of OpenGL learning] collation of Euler angle, rotation order, rotation matrix, quaternion and other knowledge
Now that the teenager has returned, the world's fireworks are the most soothing and ordinary people return to work~
Druid database connection pool
How is the mask effect achieved in the LPL ban/pick selection stage?
Introduction to flask tutorial