当前位置:网站首页>STM32 single chip microcomputer - external interrupt
STM32 single chip microcomputer - external interrupt
2022-07-05 08:15:00 【chen_ bx】
External interrupt
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 :
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 .
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 .
2) Preempt interrupts of the same priority , A high response priority cannot interrupt a low response priority interrupt .
3) Preempt interrupts of the same priority , When two interrupts occur at the same time , Which response has the highest priority , Which comes first .
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
5) Whether it's preemptive priority or response priority , The lower the priority value , It means the higher the priority .
边栏推荐
- Summary of SIM card circuit knowledge
- C#,数值计算(Numerical Recipes in C#),线性代数方程的求解,LU分解(LU Decomposition)源程序
- Programming knowledge -- assembly knowledge
- Summary -st2.0 Hall angle estimation
- Detailed explanation of SQL server stored procedures
- Shape template matching based on Halcon learning [viii] PM_ multiple_ models. Hdev routine
- Design a clock frequency division circuit that can be switched arbitrarily
- Beijing Winter Olympics opening ceremony display equipment record 3
- STM32 tutorial triple ADC interleaved sampling
- C WinForm [help interface - send email] - practice five
猜你喜欢
UEFI development learning 3 - create UEFI program
Programming knowledge -- assembly knowledge
Summary of SIM card circuit knowledge
Talk about the function of magnetic beads in circuits
Compilation warning solution sorting in Quartus II
DokuWiki deployment notes
Shape template matching based on Halcon learning [vi] find_ mirror_ dies. Hdev routine
The firmware of the connected j-link does not support the following memory access
Create inf module in AMI code
Design a clock frequency division circuit that can be switched arbitrarily
随机推荐
Shell脚本基本语法
C#,数值计算(Numerical Recipes in C#),线性代数方程的求解,LU分解(LU Decomposition)源程序
Network communication process
Communication standard -- communication protocol
Carrier period, electrical speed, carrier period variation
Detailed explanation of SQL server stored procedures
Matlab2018b problem solving when installing embedded coder support package for stmicroelectronic
UEFI development learning 4 - getting to know variable services
Live555 RTSP audio and video streaming summary (II) modify RTSP server streaming URL address
Compilation warning solution sorting in Quartus II
Several important parameters of LDO circuit design and type selection
Semiconductor devices (III) FET
DCDC circuit - function of bootstrap capacitor
Define in and define out
C language enhancement -- pointer
Semiconductor devices (I) PN junction
OLED 0.96 inch test
Weidongshan Internet of things learning lesson 1
Problem solving: interpreter error: no file or directory
Beijing Winter Olympics opening ceremony display equipment record 3