当前位置:网站首页>STM32 external interrupt (register version)
STM32 external interrupt (register version)
2022-07-24 06:58:00 【The road is difficult at night】
Initialize your key input port PA0,PA15,PC5.
eg.PA0-15 by EXTI0 External interrupt input source
because IO When setting the port PC5 and PA15 Set to pull up input ,PA0 Enter for drop-down , So the trigger condition is PC5 and PA15 When the potential changes from high to low ( Falling edge trigger ) Trigger interrupt ,PA0 On the contrary .
Ex_NVIC_Config(u8 GPIOx,u8 BITx,u8 TRIM) The three parameters are :GPIOA-G, Bits that need to be enabled , The trigger condition
RTIR: Rising edge trigger FTIR: Falling edge trigger
secondly , You need to set the problem of interrupt grouping
Preemption priority and response priority :
1. The smaller the serial number , The higher the priority .
2. Interrupt groups with high preemption priority can interrupt interrupt interrupt groups with low preemption priority , But when two preemption priorities arrive at the same time , The interrupt group with high response priority will be executed first , But when they don't arrive at the same time , Even later, when the high response priority arrives , You cannot interrupt the currently executing lower interrupt Group , Preemption priority and response priority can be divided into five groups , In each group 16 Distribution method in . For example, group 2, Preemption attribute and response attribute ,, Preemption and response are 11:11, So there are four options for preemption and response (0-3).

MY_NVIC_Init(u8 NVIC_PreemptionPriority,u8 NVIC_SubPriority,u8 NVIC_Channel,u8 NVIC_Group)
Respectively means : Value of preemption priority , Value of response priority ,io Interrupt service function corresponding to port , Group .
// Set trigger conditions
Ex_NVIC_Config(GPIO_A,0,RTIR); // Rising edge trigger wake_up The potential triggers the output change from low to high It was originally a pull-down resistor
Ex_NVIC_Config(GPIO_C,5,FTIR); // Falling edge trigger key0 The potential triggers the output change from high to low It was originally a pull-up resistor
Ex_NVIC_Config(GPIO_A,15,FTIR); // Falling edge trigger key1 The potential triggers the output change from high to low It was originally a pull-up resistor
// Set interrupt grouping
MY_NVIC_Init(2,2,EXTI0_IRQn,2); // preemption 2, Sub priority 2, Group 2
MY_NVIC_Init(2,1,EXTI9_5_IRQn,2); // preemption 2, Sub priority 1, Group 2
MY_NVIC_Init(2,0,EXTI15_10_IRQn,2); // preemption 2, Sub priority 0, Group 2 exti.c( After the interrupt is used, the interrupt flag bit needs to be cleared )
// External interrupt 0 Service program
void EXTI0_IRQHandler(void)
{
delay_ms(10); // Desquamation
if(WK_UP==1) //WK_UP Key
{
LED0=!LED0;
LED1=!LED1;
}
EXTI->PR=1<<0; // eliminate LINE0 Interrupt flag bit on
}
// External interrupt 9~5 Service program
void EXTI9_5_IRQHandler(void)
{
delay_ms(10); // Desquamation
if(KEY0==0) // Key 0
{
LED0=!LED0;
}
EXTI->PR=1<<5; // eliminate LINE5 Interrupt flag bit on
}
// External interrupt 15~10 Service program
void EXTI15_10_IRQHandler(void)
{
delay_ms(10); // Desquamation
if(KEY1==0) // Key 1
{
LED1=!LED1;
}
EXTI->PR=1<<15; // eliminate LINE15 Interrupt flag bit on
}
// External interrupt initializer
// initialization PA0,PC5,PA15 Enter... For the interrupt .
void EXTI_Init(void)
{
KEY_Init();
Ex_NVIC_Config(GPIO_A,0,RTIR); // Rising edge trigger wake_up The potential triggers the output change from low to high It was originally a pull-down resistor
Ex_NVIC_Config(GPIO_C,5,FTIR); // Falling edge trigger key0 The potential triggers the output change from high to low It was originally a pull-up resistor
Ex_NVIC_Config(GPIO_A,15,FTIR); // Falling edge trigger key1 The potential triggers the output change from high to low It was originally a pull-up resistor
MY_NVIC_Init(2,2,EXTI0_IRQn,2); // preemption 2, Sub priority 2, Group 2
MY_NVIC_Init(2,1,EXTI9_5_IRQn,2); // preemption 2, Sub priority 1, Group 2
MY_NVIC_Init(2,0,EXTI15_10_IRQn,2); // preemption 2, Sub priority 0, Group 2
}int main()
int main(void)
{
Stm32_Clock_Init(9);// System clock settings
delay_init(72); // Delay initialization
uart_init(72,9600); // Serial initialization
LED_Init(); // Initialization and LED Connected hardware interface
EXTI_Init(); // External interrupt initialization
while(1)
{
printf("lalala\r\n");
delay_ms(1000);
}
}边栏推荐
- An AI plays 41 games, and the comprehensive performance score of Google's latest multi game decision transformer is twice that of dqn
- HashSet转数组
- Never lose yourself!
- String question
- (static, dynamic, file) three versions of address book
- [lvgl (important)] style attribute API function and its parameters
- owasp top10 渗透测试
- Jenkins CI CD
- Prediction of advertising investment and sales based on regression analysis -- K neighborhood, decision tree, random forest, linear regression, ridge regression
- 基于回归分析的广告投入销售额预测——K邻近,决策树,随机森林,线性回归,岭回归
猜你喜欢

Detailed analysis of the process (life cycle) of class loading

Introduction, architecture and principle of kubernetes

mysql获取自增行标(区别mysql版本)

Penetration learning - SQL injection - shooting range - installation and bypass experiment of safety dog (it will be updated later)

Ge port: sgmii mode and SerDes mode
![[lvgl (6)] display Chinese settings and make Chinese font](/img/a4/1b0d0b7a5789ecc8f9a2a8cd93d92e.png)
[lvgl (6)] display Chinese settings and make Chinese font

在线问题反馈模块实战(十二):实现图片删除功能

JSONObject按照key的A——Z顺序排序

Sealos packages and deploys kubesphere container platform

MapReduce (I)
随机推荐
metaRTC5.0实现君正的纯C的webrtc版IPC
String question
[lvgl (important)] style attribute API function and its parameters
[jquery custom plug-in] 1 custom cache plug-in -jquerycache
Requirements already satisfied: and read timed out. problem solving methods appear during the installation of snownlp package
项目问题积累
Love yourself first, then others.
Redis基本类型-哈希Hash
xavier_normal_ 初始化测试
Getting started with redis
Nodejs enables multi process and inter process communication
渗透学习-SQL注入篇-靶场篇-安全狗的安装与绕过实验(后续还会更新)
你就是你,没有人可以取代
【杂论:离散化】
Record the pits encountered in the deserialization of phpserializer tool class
Special effects - cobweb background effects
Redis数据类型-String(字符串类型)
kubernetes 的Deployment(部署),Service概念,动态扩缩容
【学习笔记】Web页面渲染的流程
JSONObject按照key的A——Z顺序排序