当前位置:网站首页>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);
}
边栏推荐
- C application interface development foundation - form control (1) - form form
- 电信客户流失预测挑战赛
- LeetCode 987. Vertical order transverse of a binary tree - Binary Tree Series Question 7
- 简易分析fgui依赖关系工具
- MySQL --- 数据库查询 - 条件查询
- [day 29] given an integer, please find its factor number
- JDBC courses
- [principles of multithreading and high concurrency: 2. Solutions to cache consistency]
- [shutter] animation animation (the core class of shutter animation | animation | curvedanimation | animationcontroller | tween)
- C application interface development foundation - form control (3) - file control
猜你喜欢

【C语言】指针与数组笔试题详解
![[技术发展-23]:DSP在未来融合网络中的应用](/img/2e/f39543a18a8f58b1d341ce72cc4427.png)
[技术发展-23]:DSP在未来融合网络中的应用

Arduino dy-sv17f automatic voice broadcast

What is tone. Diao's story

leetcode 2097 — 合法重新排列数对

【面试题】1369- 什么时候不能使用箭头函数?

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

MySQL foundation 04 MySQL architecture

MySQL --- 数据库查询 - 条件查询

串口抓包/截断工具的安装及使用详解
随机推荐
测试右移:线上质量监控 ELK 实战
如今少年已归来,人间烟火气最抚凡人心 复工了~
Androd gradle's substitution of its use module dependency
MySQL - database query - basic query
MySQL foundation 04 MySQL architecture
After reading this article, I will teach you to play with the penetration test target vulnhub - drivetingblues-9
MySQL foundation 07-dcl
Thinkphp+redis realizes simple lottery
Do not log in or log in to solve the problem that the Oracle database account is locked.
Leetcode skimming questions_ Sum of two numbers II - enter an ordered array
ThinkPHP+Redis实现简单抽奖
SwiftUI 组件大全之使用 SceneKit 和 SwiftUI 构建交互式 3D 饼图(教程含源码)
Kivy tutorial how to create drop-down lists in Kivy
对非ts/js文件模块进行类型扩充
[Cao gongzatan] after working in goose factory for a year in 2021, some of my insights
Type expansion of non ts/js file modules
MySQL foundation 05 DML language
Three core issues of concurrent programming - "deep understanding of high concurrent programming"
Concise analysis of redis source code 11 - Main IO threads and redis 6.0 multi IO threads
【数据挖掘】任务2:医学数据库MIMIC-III数据处理