当前位置:网站首页>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);
}
边栏推荐
- 如今少年已归来,人间烟火气最抚凡人心 复工了~
- Leetcode 2097 - Legal rearrangement of pairs
- Soft exam information system project manager_ Real topic over the years_ Wrong question set in the second half of 2019_ Morning comprehensive knowledge question - Senior Information System Project Man
- MySQL foundation 05 DML language
- 【數據挖掘】任務6:DBSCAN聚類
- Summary of interval knowledge
- Telecom Customer Churn Prediction challenge
- C#应用程序界面开发基础——窗体控制(1)——Form窗体
- 【数据挖掘】任务4:20Newsgroups聚类
- openresty 缓存
猜你喜欢
[机缘参悟-36]:鬼谷子-飞箝篇 - 面对捧杀与诱饵的防范之道
Force buckle 204 Count prime
High resolution network (Part 1): Principle Analysis
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
Database SQL language 01 where condition
Androd gradle's substitution of its use module dependency
[data mining] task 6: DBSCAN clustering
【数据挖掘】任务1:距离计算
【QT】自定义控件的封装
随机推荐
[C language] detailed explanation of pointer and array written test questions
Wireshark data analysis and forensics a.pacapng
看疫情之下服装企业如何顺势而为
[Androd] Gradle 使用技巧之模块依赖替换
C#应用程序界面开发基础——窗体控制(4)——选择类控件
一位苦逼程序员的找工作经历
CF1617B Madoka and the Elegant Gift、CF1654C Alice and the Cake、 CF1696C Fishingprince Plays With Arr
How is the mask effect achieved in the LPL ban/pick selection stage?
传输层 TCP主要特点和TCP连接
What are the trading forms of spot gold and what are the profitable advantages?
Kivy tutorial how to create drop-down lists in Kivy
dotConnect for PostgreSQL数据提供程序
Canvas drawing -- bingdd
Three core issues of concurrent programming - "deep understanding of high concurrent programming"
C语言课程信息管理系统
Mathematical knowledge: Nim game game theory
音程的知识的总结
[untitled]
[principles of multithreading and high concurrency: 2. Solutions to cache consistency]
wirehark数据分析与取证A.pacapng