STM32F103 固件库3.5 现在想用高级定时器TIM1只做普通定时,但我怎么配置,这个TIM1都不可以定时?谁能给份能用的历程?同时看看我的问题吧,谢过! 贴出相关程序:
//10s
void TIM1_Configuration()
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1, ENABLE);
TIM_DeInit(TIM1);
/*计数重载值为23999;预分频值为(29999 + 1 = 30000);时钟分割0;向上计数模式*/
TIM_TimeBaseStructure.TIM_Period = 23999; //设置计数周期 0x0000~0xFFFF 65535
TIM_TimeBaseStructure.TIM_Prescaler = 29999; //设置作为TIMx时钟频率除数的预分频值 0x0000~0xFFFF
TIM_TimeBaseStructure.TIM_ClockDivision = 0; //设置时钟分割
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; //选择“向上计数”模式
TIM_TimeBaseInit(TIM1, &TIM_TimeBaseStructure);
TIM_ClearFlag(TIM1, TIM_FLAG_Update);
/*使能TIM中断*/
TIM_ITConfig(TIM1,TIM_IT_Update, ENABLE);
}
/* Enable the TIM1 Interrupt*/ //高级定时器TIM1
NVIC_InitStructure.NVIC_IRQChannel = TIM1_UP_IRQn ; //TIM1刷新中断 TIM中断种类较多
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 4;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
void TIM1_IRQHandler(void) //换成TIM1_UP_IRQHandler()不行
{
if(TIM_GetITStatus(TIM1, TIM_IT_Update) != RESET)
{
TIM_ClearITPendingBit(TIM1,TIM_IT_Update);
printf("TIM1\r\n");
tim1_nums++;
//freq = (XTCS.positionfreq[0] << 8) | XTCS.positionfreq[1];
if(tim1_nums == freq)
{
printf("tim1\r\n");
tim1_nums = 0;
}
TIM_ClearFlag(TIM1,TIM_IT_Update);
}
} |