问题如题啊,TIM3库代码,用在STM32F103C8上,TIM2,TIM3都好用,改为TIM4就出问题了,进入不了中断,求解呢?
代码如下:
void TIM3_NVIC_Configuration(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0); NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
void TIM3_Configuration(unsigned char timedata)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3 , ENABLE);
TIM_DeInit(TIM3);
TIM_TimeBaseStructure.TIM_Period=10000/timedata;//(10000-timedata);//5*timedata; /* 自动重装载寄存器周期的值(计数值)介于0x0000到0xffff之间 */
/* 累计 TIM_Period个频率后产生一个更新或者中断 */
TIM_TimeBaseStructure.TIM_Prescaler= (72 - 1); /* 时钟预分频数 72M/72 介于0x0000到0xffff之间 */
TIM_TimeBaseStructure.TIM_ClockDivision=TIM_CKD_DIV1; /* 采样分频 */
TIM_TimeBaseStructure.TIM_CounterMode=TIM_CounterMode_Up; /* 向上计数模式 */
TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure);
TIM_ClearFlag(TIM3, TIM_FLAG_Update); /* 清除溢出中断标志 */
TIM_ITConfig(TIM3,TIM_IT_Update,ENABLE);
TIM_Cmd(TIM3, ENABLE); /* 开启时钟 */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3 , DISABLE); /*先关闭等待使用*/
}
中断函数:
void TIM3_IRQHandler(void)
{ if ( TIM_GetITStatus(TIM3 , TIM_IT_Update) != RESET )
{
TIM_ClearITPendingBit(TIM3 , TIM_FLAG_Update);
tim3_factor++;
GPIO_ResetBits(GPIOB,GPIO_Pin_0 |GPIO_Pin_1);
}
if(tim3_factor==100) tim3_factor=0; }
Main中:
TIM3_NVIC_Configuration();
TIM3_Configuration(50);
START_TIME3;
TIM2,TIM3都好用,改为TIM4就出问题了,TIM4不工作,求解~
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
---------------------------------
那可以仿真看下寄存器状态了.
一周热门 更多>