Understanding of stm32 interrupt nesting NVIC

Publisher:huanhuiLatest update time:2017-09-17 Source: eefocusKeywords:stm32 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

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.


Keywords:stm32 Reference address:Understanding of stm32 interrupt nesting NVIC

Previous article:STM32 multiplexing clock is turned on
Next article:Stm32RS232 serial port communication——interrupt receiving and sending data

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号