stm32f407定时器9不运行。。。为什么?
时间:10-02
整理:3721RD
点击:
TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM9,ENABLE); ///
TIM_TimeBaseInitStructure.TIM_Period = arr; //
TIM_TimeBaseInitStructure.TIM_Prescaler=psc; //
TIM_TimeBaseInitStructure.TIM_CounterMode=TIM_CounterMode_Up; //
TIM_TimeBaseInitStructure.TIM_ClockDivision=TIM_CKD_div1;
TIM_TimeBaseInit(TIM9,&TIM_TimeBaseInitStructure);//
TIM_ITConfig(TIM9,TIM_IT_Update,ENABLE); //
TIM_Cmd(TIM9,ENABLE); //ê1?ü?¨ê±4
NVIC_InitStructure.NVIC_IRQChannel=TIM1_BRK_TIM9_IRQn; //
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);//
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=1; //
NVIC_InitStructure.NVIC_IRQChannelSubPriority=2; //
NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE;
NVIC_Init(&NVIC_InitStructure);
NVIC_InitTypeDef NVIC_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM9,ENABLE); ///
TIM_TimeBaseInitStructure.TIM_Period = arr; //
TIM_TimeBaseInitStructure.TIM_Prescaler=psc; //
TIM_TimeBaseInitStructure.TIM_CounterMode=TIM_CounterMode_Up; //
TIM_TimeBaseInitStructure.TIM_ClockDivision=TIM_CKD_div1;
TIM_TimeBaseInit(TIM9,&TIM_TimeBaseInitStructure);//
TIM_ITConfig(TIM9,TIM_IT_Update,ENABLE); //
TIM_Cmd(TIM9,ENABLE); //ê1?ü?¨ê±4
NVIC_InitStructure.NVIC_IRQChannel=TIM1_BRK_TIM9_IRQn; //
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);//
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=1; //
NVIC_InitStructure.NVIC_IRQChannelSubPriority=2; //
NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE;
NVIC_Init(&NVIC_InitStructure);
你使能定时器了吗?
中断优先级组设置没有?还有TIM9的中断服务函数写了没?
使能了啊!TIM_Cmd(TIM9,ENABLE);