当前位置:网站首页>STM32 single chip microcomputer - external interrupt

STM32 single chip microcomputer - external interrupt

2022-07-05 08:15:00 chen_ bx

One 、ARM Cortex-M3 Interrupt system

1、 Definition
interrupt , It means interrupting what you're doing , Deal with emergencies immediately .
Real life examples : When playing games on mobile phones , Call suddenly . In programming, we often encounter the request of receiving data in real time , Use interrupt service functions , Examples are as follows :
 Insert picture description here

As many as 140 individual GPIO(STM32F405xx/07xx and STM32F415xx/17xx) Connect to 16 External interrupts / Event line .
for example :PA0 Occupied EXTI0, other PB0~PI0 It can't be used .
 Insert picture description here
 Insert picture description here

Two 、 Code thinking

1.8051 Single chip microcomputer
Trigger mode of external interrupt : Low level trigger 、 Falling edge trigger IT0=1
Allow external interrupt pin to apply for interrupt request EX0=1
Priority configuration
Interrupt service function

2.STM32
port A Hardware clock enable
SYSCFG Hardware clock enable
Operating mode of pin configuration
Connect the pin to the external interrupt

Interrupt trigger mode : Level trigger 、 edge-triggered
Allow external interrupt pin to apply for interrupt request
Priority configuration
Interrupt service function

notes :
Interrupt service function Can't be called , Format You can't write , This is its unique form of existence . Different hardware platforms , The writing method is different .

The function interface

1. Select which interrupt to use for the pin

/** * @brief Selects the GPIO pin used as EXTI Line. * @param EXTI_PortSourceGPIOx : selects the GPIO port to be used as source for * EXTI lines where x can be (A..K) for STM32F42xxx/43xxx devices, (A..I) * for STM32F405xx/407xx and STM32F415xx/417xx devices or (A, B, C, D and H) * for STM32401xx devices. * * @param EXTI_PinSourcex: specifies the EXTI line to be configured. * This parameter can be EXTI_PinSourcex where x can be (0..15, except * for EXTI_PortSourceGPIOI x can be (0..11) for STM32F405xx/407xx * and STM32F405xx/407xx devices and for EXTI_PortSourceGPIOK x can * be (0..7) for STM32F42xxx/43xxx devices. * * @retval None */
void SYSCFG_EXTILineConfig(uint8_t EXTI_PortSourceGPIOx, uint8_t EXTI_PinSourcex)

2. Configure external interrupts

/** * @brief Initializes the EXTI peripheral according to the specified * parameters in the EXTI_InitStruct. * @param EXTI_InitStruct: pointer to a EXTI_InitTypeDef structure * that contains the configuration information for the EXTI peripheral. * @retval None */
void EXTI_Init(EXTI_InitTypeDef* EXTI_InitStruct)

3. Interrupt priority configuration

/** * @brief Initializes the NVIC peripheral according to the specified * parameters in the NVIC_InitStruct. * @note To configure interrupts priority correctly, the NVIC_PriorityGroupConfig() * function should be called before. * @param NVIC_InitStruct: pointer to a NVIC_InitTypeDef structure that contains * the configuration information for the specified NVIC peripheral. * @retval None */
void NVIC_Init(NVIC_InitTypeDef* NVIC_InitStruct)

4. Get external interrupt status

/** * @brief Checks whether the specified EXTI line is asserted or not. * @param EXTI_Line: specifies the EXTI line to check. * This parameter can be EXTI_Linex where x can be(0..22) * @retval The new state of EXTI_Line (SET or RESET). */
ITStatus EXTI_GetITStatus(uint32_t EXTI_Line)

5. Clear the external interrupt flag bit

/** * @brief Clears the EXTI's line pending bits. * @param EXTI_Line: specifies the EXTI lines to clear. * This parameter can be any combination of EXTI_Linex where x can be (0..22) * @retval None */
void EXTI_ClearITPendingBit(uint32_t EXTI_Line)

Interrupt priority

A meaning of interrupt priority : Multiple interrupts trigger at the same time , But not at the same time , So in order , Priority should be given to important interrupts according to the actual operating environment .

1. summary

STM32 Group interrupt priorities , common 5 Group , Group 0~4, These groups are used to specify the current M3 How many preemption priorities and response priorities are supported . meanwhile , Set a preemptive priority and a response priority for each interrupt . The function prototype is as follows :

/** * @brief Configures the priority grouping: pre-emption priority and subpriority. * @param NVIC_PriorityGroup: specifies the priority grouping bits length. * @arg NVIC_PriorityGroup_0: 0 bits for pre-emption priority // Preemption priority is not supported  * 4 bits for subpriority // Support 16 Response priority  * @arg NVIC_PriorityGroup_1: 1 bits for pre-emption priority // Support 2 Preemption priority  * 3 bits for subpriority // Support 8 Response priority  * @arg NVIC_PriorityGroup_2: 2 bits for pre-emption priority // Support 4 Preemption priority  * 2 bits for subpriority // Support 4 Response priority  * @arg NVIC_PriorityGroup_3: 3 bits for pre-emption priority // Support 8 Preemption priority  * 1 bits for subpriority // Support 2 Response priority  * @arg NVIC_PriorityGroup_4: 4 bits for pre-emption priority // Support 16 Preemption priority  * 0 bits for subpriority // Response priority is not supported  * @retval None */

2. The difference between preemption priority and response priority

1) High preemption priority is an interrupt that can interrupt the ongoing low preemption priority . If the preemption priority is the same , There will be no preemption process .
 Insert picture description here

2) Preempt interrupts of the same priority , A high response priority cannot interrupt a low response priority interrupt .
 Insert picture description here

3) Preempt interrupts of the same priority , When two interrupts occur at the same time , Which response has the highest priority , Which comes first .
 Insert picture description here

4) Interrupt with the same preemptive priority and the same response priority , If it happens at the same time , It will be executed according to the priority fixed in the hardware , Here's the picture . The vector table of interconnected products 、 Other types of finished products can be found stm32 Chinese Reference Manual

 Insert picture description here
 Insert picture description here

 Insert picture description here
 Insert picture description here

 Insert picture description here

5) Whether it's preemptive priority or response priority , The lower the priority value , It means the higher the priority .

原网站

版权声明
本文为[chen_ bx]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202140545026809.html