当前位置:网站首页>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);
}
}边栏推荐
猜你喜欢

PyQt5入门——学生管理系统

tensorflow einsum函数

Detailed explanation of class loader and parental delegation mechanism
![(note sorting is not completed) [graph theory: find the shortest path of single source]](/img/58/e61aea3c4d0a33d3615144763160f7.png)
(note sorting is not completed) [graph theory: find the shortest path of single source]

(静态,动态,文件)三个版本的通讯录

Esp32 ultra detailed learning record: NTP synchronization time

Introduction to pyqt5 - student management system
![[lvgl (4)] event and event bubble of the object](/img/1e/9fe3d34f5f8d8c7298a106dca8d949.png)
[lvgl (4)] event and event bubble of the object

Special effects - when the mouse moves, there will be a custom expression trail

Redis分布式缓存学习笔记
随机推荐
[lvgl] API functions for setting, changing and deleting styles of components
Jenkins CI CD
Don't compare with anyone, just be yourself
tensorflow einsum函数
oss授权单个bucket权限
[C language] operator details (in-depth understanding + sorting and classification)
MySQL gets the self incrementing line mark (different from MySQL version)
HashSet to array
Breadth first search (template use)
Redis基本类型-结合Set
【C语言】操作符详解(深入理解+整理归类)
Can you increase muscle without exercise??? Just get an injection of hibernating black bear serum
Sealos packages and deploys kubesphere container platform
[lvgl (5)] label usage
《大厂面试》之JVM篇21问与答
tensorflow boolean_mask函数
You are you, and no one can replace you
Jsonobject is sorted in A-Z order of key
Jenkins CI CD
【学习笔记】url输入到页面展现中发生了什么?