1 Understanding of NVIC
CM3 supports hardware interrupt nesting, which is divided into preemptive priority and sub-priority. The main usage rules are: the preemptive priority with a higher level can interrupt the lower level. When the preemptive priorities of the same level occur at the same time, the one with a higher priority will be interrupted first. If they are the same, they will occur in the order of hardware arrangement. If there is a sub-priority interrupt in progress, when other sub-priorities of the same level occur, they will be suspended first and executed after this interrupt is completed!
Find the priority grouping pattern from the library function:
#define NVIC_PriorityGroup_0 ((uint32_t)0x700) /* 0 bits for pre-emption priority
4 bits for subpriority */
#define NVIC_PriorityGroup_1 ((uint32_t)0x600) /* 1 bits for pre-emption priority
3 bits for subpriority */
#define NVIC_PriorityGroup_2 ((uint32_t)0x500) /* 2 bits for pre-emption priority
2 bits for subpriority */
#define NVIC_PriorityGroup_3 ((uint32_t)0x400) /* 3 bits for pre-emption priority
1 bits for subpriority */
#define NVIC_PriorityGroup_4 ((uint32_t)0x300) /* 4 bits for pre-emption priority
0 bits for subpriority */
From this, we can see that the first group has only one level and 16 sub-priorities. I can understand it this way: if it is assigned to this group, nested interrupts cannot occur. When interrupts occur at the same time, the one with the highest sub-priority occurs first. If an interrupt is executed, the next interrupt can only be executed after the interrupt is executed. The last group is just the opposite. There are 15 levels. If an interrupt is executed, up to 15 interrupts can be nested to execute one interrupt. See the example below:
NVIC_InitTypeDef NVIC_InitStructure; //Define interrupt initialization type structure variable
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1); //Configure priority group 1 2 preemptive priorities and 8 sub-priorities
NVIC_InitStructure.NVIC_IRQChannel = EXTI0_IRQn; //Open external interrupt 0
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; //Configure preemptive priority 0
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; //Sub-priority is configured as 0
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //Enable channel
NVIC_Init(&NVIC_InitStructure); //Initialize the configuration of external interrupt 0
NVIC_InitStructure.NVIC_IRQChannel = EXTI9_5_IRQn; //Open external interrupts 5 to 9
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1; //Configure preemptive priority 1
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1; //Sub-priority is configured as 1
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //Enable channel
NVIC_Init(&NVIC_InitStructure); //Initialize the configuration of external interrupt 0
NVIC_InitStructure.NVIC_IRQChannel = ADC1_2_IRQn; //ADC1中断
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1; //Configure preemptive priority 1
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1; //Sub-priority is configured as 1
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //Enable channel
NVIC_Init(&NVIC_InitStructure); //Initialize the configuration of external interrupt 0
From the above configuration, external interrupt 0 has the highest priority, which can interrupt ADC and external interrupts 5 to 9, that is, they can be nested. When the ADC interrupt and external interrupts 5 to 9 occur at the same time, their preemption priority levels are the same, and their sub-priority levels are also the same. Because the ADC1 hardware is ranked higher, the ADC interrupt occurs first. If any of the two interrupts is being executed, wait until the interrupt is executed before executing the other interrupt.
Previous article:STM32 learning: USART interrupt mode
Next article:STM32 Learning: Event Flag Group
- Popular Resources
- Popular amplifiers
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- Sn-doped CuO nanostructure-based ethanol gas sensor for real-time drunk driving detection in vehicles
- Design considerations for automotive battery wiring harness
- Do you know all the various motors commonly used in automotive electronics?
- What are the functions of the Internet of Vehicles? What are the uses and benefits of the Internet of Vehicles?
- Power Inverter - A critical safety system for electric vehicles
- Analysis of the information security mechanism of AUTOSAR, the automotive embedded software framework
- Brief Analysis of Automotive Ethernet Test Content and Test Methods
- How haptic technology can enhance driving safety
- C language version of the time library function file or timestamp conversion algorithm
- To ensure the stability of electronic equipment, what tests need to be done on the hardware?
- Evaluation Weekly Report 20220801: Canaan K510 AI Development Kit is launched, and a domestic FPGA is expected to be launched this week~
- Why is the safety spacing of the board edge set in Altium Designer 18 invalid?
- Series and parallel circuits of common resistors
- Will the tuition be higher if I pursue graduate studies after I start working?
- Add C66x CSL library and header files to the project in CCS
- [Home smart lighting control and indoor environment monitoring system]--6. Bluetooth BLE host computer development 2
- TWS headset charging case schematic diagram 1
- Design of cell image acquisition system based on DSP and FPGA technology