STM32F103中断优先级配置问题

2019-08-22 14:28发布

我在使用定时器5产生定时中断时发现先设置中断优先级再初始化定时器,定时器不能工作,具体代码如下如果直接在定时器5初始化函数加中断优先级配置则工作正常,请给位大佬帮忙看看。
//中断优先级设置

void NVIC_Configuration(void)
{
        NVIC_InitTypeDef NVIC_InitStructure;
       
        NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
       


       

        NVIC_InitStructure.NVIC_IRQChannel = TIM8_UP_IRQn;  //TIM3ÖD¶Ï
        NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority =0;  //ÏèÕ¼óÅÏ輶2¼¶
        NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;  //′óóÅÏ輶0¼¶
        NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQí¨μà±»ê1Äü
        NVIC_Init(&NVIC_InitStructure);  //¸ù¾YNVIC_InitStructÖDÖ¸¶¨μÄ2Îêy3õê¼
       
         NVIC_InitStructure.NVIC_IRQChannel = USART3_IRQn;
        NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority =0;                //ÏèÕ¼óÅÏ輶        2
        NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;                                //′óóÅÏ輶                0
        NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;                       
        NVIC_Init(&NVIC_InitStructure);

       
        NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
       





       
       
        NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQn;  //TIM3ÖD¶Ï
        NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority =0;  //ÏèÕ¼óÅÏ輶2¼¶
        NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;  //′óóÅÏ輶0¼¶
        NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQí¨μà±»ê1Äü
        NVIC_Init(&NVIC_InitStructure);

       
               
        NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn;  //TIM3ÖD¶Ï
        NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority =1;  //ÏèÕ¼óÅÏ輶2¼¶
        NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;  //′óóÅÏ輶0¼¶
        NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQí¨μà±»ê1Äü
        NVIC_Init(&NVIC_InitStructure);
               
        NVIC_InitStructure.NVIC_IRQChannel = TIM4_IRQn;  //TIM3ÖD¶Ï
        NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority =2;  //ÏèÕ¼óÅÏ輶2¼¶
        NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;  //′óóÅÏ輶0¼¶
        NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQí¨μà±»ê1Äü
        NVIC_Init(&NVIC_InitStructure);
               


       

        NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);
       
        NVIC_InitStructure.NVIC_IRQChannel = TIM5_IRQn;  //TIM3ÖD¶Ï
        NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority =1;  //ÏèÕ¼óÅÏ輶2¼¶
        NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;  //′óóÅÏ輶0¼¶
        NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQí¨μà±»ê1Äü
        NVIC_Init(&NVIC_InitStructure);
       
       
       
        NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;                                               
        NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;                //ÏèÕ¼óÅÏ輶        
        NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;                        //′óóÅÏ輶          0
        NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
        NVIC_Init(&NVIC_InitStructure);
       



        NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4);
       
        NVIC_InitStructure.NVIC_IRQChannel = TIM6_IRQn;            
        NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;                  //ÏèÕ¼óÅÏ輶        1
        NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;                         //′óóÅÏ輶                0
        NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;                           
        NVIC_Init(&NVIC_InitStructure);   
         

        NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQn;
        NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2;                //ÏèÕ¼óÅÏ輶        2
        NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;                                //′óóÅÏ輶                0
        NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;                       
        NVIC_Init(&NVIC_InitStructure);
//        NVIC_SetPriority(SysTick_IRQn,NVIC_EncodePriority(NVIC_GetPriorityGrouping(),0,0));
}


//定时器5初始化
void TIM5_Configuration(void)
{
       
        TIM_TimeBaseInitTypeDef  TIM_TimeBaseStructure;
  TIM_SetCounter( TIM5, 0x0000);
  TIM_ClearFlag(TIM5, TIM_FLAG_Update);      
  TIM_ClearITPendingBit(TIM5, TIM_FLAG_Update); //??TIM2???????????
  TIM_ARRPreloadConfig(TIM5, ENABLE);         
  TIM_ITConfig(TIM5, TIM_IT_Update, ENABLE); //??TIM2???   

  TIM_TimeBaseStructure.TIM_Period = 5000;      //????????2000,??????0xffff
  TIM_TimeBaseStructure.TIM_Prescaler =7199;     //??72
  TIM_TimeBaseStructure.TIM_ClockDivision = 0;     // ????
  TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;  //????????
  TIM_TimeBaseInit(TIM5, &TIM_TimeBaseStructure);
  TIM_Cmd(TIM5, ENABLE);       //TIM2 enable counter
       

}



友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
该问题目前已经被作者或者管理员关闭, 无法添加新回复
4条回答
szczyb1314
1楼-- · 2019-08-22 19:12
程序中可以多次改变中断优先级分组吗?设置了好几次不通的中断优先级分组
ysjysc
2楼-- · 2019-08-22 20:12
 精彩回答 2  元偷偷看……
cjk1995
3楼-- · 2019-08-22 22:45
ysjysc 发表于 2017-4-11 11:28
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);  这个分组设置一次就好了  就是说优先级分配的格式啊 ...

不是的,我这个设置的分组是不一样的,还有就是我如果在初始化函数里面加上中断分组设置运行起来也是没问题的
cjk1995
4楼-- · 2019-08-22 23:20
szczyb1314 发表于 2017-4-11 11:09
程序中可以多次改变中断优先级分组吗?设置了好几次不通的中断优先级分组

仅设置一次也不对的,定时器还是跑不起来,而且设置分组不是以最后一次为准吗。这不是主要的问题,我是想问下是是否还需要进行其他的配置呢

一周热门 更多>