当前位置:网站首页>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 .
边栏推荐
- Factors affecting the quality of slip rings in production
- Beijing Winter Olympics opening ceremony display equipment record 3
- Basic information commands and functions of kernel development
- 动力电池UL2580测试项目包括哪些
- Some thoughts on extracting perspectives from ealfa and Ebeta
- Synchronization of QT multithreading
- Hardware 3 -- function of voltage follower
- My-basic application 1: introduction to my-basic parser
- Charge pump boost principle - this article will give you a simple understanding
- Talk about the function of magnetic beads in circuits
猜你喜欢
QEMU STM32 vscode debugging environment configuration
Development tools -- gcc compiler usage
Shape template matching based on Halcon learning [v] find_ cocoa_ packages_ max_ deformation. Hdev routine
C WinForm [change the position of the form after running] - Practical Exercise 4
Introduction of air gap, etc
Charge pump boost principle - this article will give you a simple understanding
C language # and #
MySQL之MHA高可用集群
Semiconductor devices (III) FET
【论文阅读】2022年最新迁移学习综述笔注(Transferability in Deep Learning: A Survey)
随机推荐
Beijing Winter Olympics opening ceremony display equipment record 3
Record the opening ceremony of Beijing Winter Olympics with display equipment
Record the visual shock of the Winter Olympics and the introduction of the screen 2
如何进行导电滑环选型
Live555 RTSP audio and video streaming summary (II) modify RTSP server streaming URL address
Management and use of DokuWiki (supplementary)
[trio basic from introduction to mastery tutorial XIV] trio realizes unit axis multi-color code capture
Classic application of MOS transistor circuit design (2) - switch circuit design
[cloud native | learn kubernetes from scratch] III. kubernetes cluster management tool kubectl
Improve lighting C program
DokuWiki deployment notes
The firmware of the connected j-link does not support the following memory access
Define in and define out
Live555 push RTSP audio and video stream summary (III) flower screen problem caused by pushing H264 real-time stream
Imx6ull bare metal development learning 2- use C language to light LED indicator
Summary of SIM card circuit knowledge
Gradle composite construction
PMSM dead time compensation
Explain task scheduling based on Cortex-M3 in detail (Part 1)
matlab timeserise