1. The NVIC_InitStructure structure is defined in the misc.h file and can be viewed during programming. All NVIC functions are defined in the misc.h file.
2. The interrupt service function entry name is in the startup_stm32f10x_hd.s file.
3. The value of the interrupt structure parameter NVIC_InitStructure.NVIC_IRQChannel is found in the stm32f10x.h file.
4. The name of the interrupt service function must be written according to the name of the interrupt vector table in the startup_stm32f10x_hd.s file. The interrupt service function can be placed in any folder regardless of the storage location.
The NVIC manages interrupt priorities and sets interrupt lines.
NVIC_IRQChannelPreemptionPriority: preemption priority
NVIC_IRQChannelSubPriority: Sub-priority
A high priority interrupt can interrupt a low priority interrupt, which means interrupt nesting.
The smaller the preemptive priority number, the higher the priority. When the preemptive priority numbers are the same, the priority number takes effect.
Interrupts with the same preemptive priority cannot be nested and can only be queued according to the secondary priority number. The secondary priority number is the queue number, and the lower the number, the front.
Just like buying train tickets, the system sets a higher priority (first priority) for students and soldiers than ordinary people. Students and soldiers can seize the system channel and get the right to buy tickets first, but students and soldiers cannot seize each other. Who can buy the ticket first can only be determined based on the queue (based on priority).
First, use the function NVIC_PriorityGroupConfig(NVIC_PriorityGroup_x) to determine how many preemptive priorities and subordinate priorities there are. NVIC_PriorityGroup_x can take the following values.
NVIC_PriorityGroup_0 => Select group 0
NVIC_PriorityGroup_1 => Select Group 1
NVIC_PriorityGroup_2 => Select Group 2
NVIC_PriorityGroup_3 => Select Group 3
NVIC_PriorityGroup_4 => Select Group 4
Example:
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
NVIC_InitStructure.NVIC_IRQChannel = EXTI0_IRQChannel; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; //Specify preemptive priority level 0, which can be 0-1
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //Enable interrupt
NVIC_Init(&NVIC_InitStructure);
NVIC_InitStructure.NVIC_IRQChannel = SPI1_IRQChannel; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1; //Specify preemptive priority level 1, can be 0-1
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; //Specify priority level 0, can be 0-7 NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
NVIC_InitStructure.NVIC_IRQChannel =USART1_IRQChannel; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1; //Specify priority level 1, can be 0-7 NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
EXTI0_IRQChannel has a higher priority than SPI1_IRQChannel and USART1_IRQChannel, so the EXTI0_IRQChannel interrupt can interrupt the executing SPI1_IRQChannel/USART1_IRQChannel interrupt to achieve interrupt nesting.
SPI1_IRQChannel and USART1_IRQChannel have equal preemptive priority and cannot interrupt each other, that is, when executing SPI1_IRQChannel/USART1_IRQChannel interrupt, USART1_IRQChannel/SPI1_IRQChannel interrupt cannot be interrupted. When SPI1_IRQChannel and USART1_IRQChannel interrupts are generated at the same time, they must be queued according to the slave priority. SPI1_IRQChannel has a higher slave priority, so the SPI1_IRQChannel interrupt is executed first.
Previous article:STM32 multiplexing clock is turned on
Next article:Stm32RS232 serial port communication——interrupt receiving and sending data
- Popular Resources
- Popular amplifiers
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
- Huawei's Strategic Department Director Gai Gang: The cumulative installed base of open source Euler operating system exceeds 10 million sets
- Download from the Internet--ARM Getting Started Notes
- Learn ARM development(22)
- Learn ARM development(21)
- Learn ARM development(20)
- Learn ARM development(19)
- Learn ARM development(14)
- Learn ARM development(15)
- Analysis of the application of several common contact parts in high-voltage connectors of new energy vehicles
- Wiring harness durability test and contact voltage drop test method
- TI C2000 Basic Learning
- Interest group training topic: Use MOS tube or + op amp to realize a DC/DC closed-loop voltage regulator
- Simple square wave generator based on 51 single chip microcomputer
- MSP430fr6989 serial port DMA sending experimental routine
- [RISC-V MCU CH32V103 Review] First impression of CH32V103C8T6 chip
- 100 check items for PCB design to ensure you have no problems with your design!
- How to write the corresponding program process according to the timing diagram
- Differences and similarities between detection circuits, filter circuits, frequency selection circuits, threshold comparison circuits, and bandpass circuits
- When designing PCB, how to consider electromagnetic compatibility EMC/EMI, specifically...
- How to measure the PWM generated by msp430f149 with an oscilloscope