【中断优先级】STM32中断优先级没用,请问是怎么回事???

2019-07-14 23:01发布

  1. void NVIC_Configuration(void)
  2. {
  3.     NVIC_InitTypeDef NVIC_InitStructure;

  4.     NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);//设置优先级分组形式1,即抢占级占一位,优先级占3位

  5.     /* Enable the USART1 Interrupt */
  6.     NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQChannel;
  7.     NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
  8.     NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  9.     NVIC_Init(&NVIC_InitStructure);


  10.     /* Enable the USART2 Interrupt*/
  11.     NVIC_InitStructure.NVIC_IRQChannel=USART2_IRQChannel;
  12.     NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=1;
  13.     NVIC_InitStructure.NVIC_IRQChannelSubPriority=0;
  14.     NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE;
  15.     NVIC_Init(&NVIC_InitStructure);

  16.     /* Enable the USART3 Interrupt*/
  17.     NVIC_InitStructure.NVIC_IRQChannel=USART3_IRQChannel;
  18.     NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=1;
  19.     NVIC_InitStructure.NVIC_IRQChannelSubPriority=1;
  20.     NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE;
  21.     NVIC_Init(&NVIC_InitStructure);


  22.     RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2 /*| RCC_APB1Periph_TIM3*/,ENABLE);
  23.     NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQChannel;
  24.     NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 3;
  25.     NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3;
  26.     NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  27.     NVIC_Init(&NVIC_InitStructure);
  28. }
复制代码
如上就是我NIVC的配置,我的定时中断执行时间比较长,我希望在我定时中断的时候,我的串口中断不影响,照常执行,也就是优先级高点。但是我这么做,运行的效果是我的串口接收不能打断定时,只有定时过了之后,才能继续接收。

友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
2条回答
youhduc
2019-07-15 19:09
优先级当然有用,抢占优先级数值越小,优先级越高。抢占优先级相同时,不能相互打断

你的程序设置抢占为一位(0或者1)
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);//设置优先级分组形式1,即抢占级占一位,优先级占3位
定时器中断抢占配置3,占两位
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 3;




你可以试试将抢占优先级与子优先级都设置为2位,具体怎么分组你查一下,我忘记了


定时中断抢占优先级设置为3,串口为0或1或2  




一周热门 更多>