STM32中断优先级没用,请问是怎么回事?
时间:10-02
整理:3721RD
点击:
- void NVIC_Configuration(void)
- {
- NVIC_InitTypeDef NVIC_InitStructure;
- NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);//设置优先级分组形式1,即抢占级占一位,优先级占3位
- /* Enable the USART1 Interrupt */
- NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQChannel;
- NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
- NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
- NVIC_Init(&NVIC_InitStructure);
- /* Enable the USART2 Interrupt*/
- NVIC_InitStructure.NVIC_IRQChannel=USART2_IRQChannel;
- NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=1;
- NVIC_InitStructure.NVIC_IRQChannelSubPriority=0;
- NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE;
- NVIC_Init(&NVIC_InitStructure);
- /* Enable the USART3 Interrupt*/
- NVIC_InitStructure.NVIC_IRQChannel=USART3_IRQChannel;
- NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=1;
- NVIC_InitStructure.NVIC_IRQChannelSubPriority=1;
- NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE;
- NVIC_Init(&NVIC_InitStructure);
- RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2 /*| RCC_APB1Periph_TIM3*/,ENABLE);
- NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQChannel;
- NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 3;
- NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3;
- NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
- NVIC_Init(&NVIC_InitStructure);
- }
如上就是我NIVC的配置,我的定时中断执行时间比较长,我希望在我定时中断的时候,我的串口中断不影响,照常执行,也就是优先级高点。但是我这么做,运行的效果是我的串口接收不能打断定时,只有定时过了之后,才能继续接收。
有没有人指教一下
还是没人回复~~~~~~~~~~
你是用USATR1来接收的吗,你看看你的配置
优先级当然有用,抢占优先级数值越小,优先级越高。抢占优先级相同时,不能相互打断
你的程序设置抢占为一位(0或者1)
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);//设置优先级分组形式1,即抢占级占一位,优先级占3位
定时器中断抢占配置3,占两位
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 3;
你可以试试将抢占优先级与子优先级都设置为2位,具体怎么分组你查一下,我忘记了
定时中断抢占优先级设置为3,串口为0或1或2