Explanation of STM32 NVIC configuration

Publisher:轻松自在Latest update time:2019-01-15 Source: eefocusKeywords:STM32 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

When configuring the interrupt priority of each peripheral, most development boards used for learning are used to configure the NVIC group in the initialization file of each peripheral. For example, the NVIC configurations of ADC and Usart are as follows:


In ADC:


void ADC_NVIC_Configuration(void)

{

NVIC_InitTypeDef NVIC_InitStructure;

NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);

NVIC_InitStructure.NVIC_IRQChannel =ADC1_2_IRQn; // Enable ADC_Channel8 interrupt

NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;

NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;

NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

NVIC_Init(&NVIC_InitStructure);   

}


Usart:


void NVIC_Configuration(void)

{

  /* Structure declaration */

  NVIC_InitTypeDef NVIC_InitStructure;

  /* Configure the NVIC Preemption Priority Bits */  

  /* Configure one bit for preemption priority */

  /* The priority group specifies the number of bits used for preemption priority and response priority. Here, it is 0, 4 

  Group 0: Preemption priority occupies 0 bits, response priority occupies 4 bits

  Group 1: Preemption priority occupies 1 bit, response priority occupies 3 bits

  Group 2: Preemption priority occupies 2 bits, response priority occupies 2 bits

  Group 3: Preemption priority occupies 3 bits, response priority occupies 1 bit

  Group 4: Preemption priority occupies 4 bits, response priority occupies 0 bits  

  */       

  NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);    



  NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn; //Set serial port 1 interrupt

  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; //Preemption priority 0

  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; //Subpriority is 0

  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //Enable

  NVIC_Init(&NVIC_InitStructure);

}


But in fact, this configuration is unreasonable, that is, if the interrupt groups configured by the two NVICs are different, if one of the peripherals references a priority value other than that allowed by the last configured interrupt group, a conflict may occur. After discussing with the teacher, he believes that if the previously initialized priority is unreasonable compared to the value set by the later priority group, the previous interrupt may not be responded to, BUT...


When I was experimenting, I found that no matter how I changed the order of these two priority configurations, it seemed to have no effect on the results of my program.


Of course, the teacher's suggestion is to create a systemconfig file in the project to configure the interrupt priority group and clock, that is, the interrupt priority group configuration only appears once


Keywords:STM32 Reference address:Explanation of STM32 NVIC configuration

Previous article:LPC_11C14 platform I2C analysis
Next article:STM32 interrupt setting and interrupt priority setting

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号