STM32f103c8t6的tiM1的开启不了定时中断,以下是我的代码。希望各位大佬能指出其中的错误。
- int n=0;
- void TIM1_Init(void)
- {
- RCC_APB2PeriphclockCmd(RCC_APB2Periph_TIM1,ENABLE);//使能APB2时钟
- TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStructure;
- TIM_TimeBaseInitStructure.TIM_ClockDivision=TIM_CKD_DIV1;//时钟分频,设置定时器时钟 CK_INT 频率与数字滤波器采样时钟频率分频比
- TIM_TimeBaseInitStructure.TIM_CounterMode=TIM_CounterMode_Up;//向上计数模式
- TIM_TimeBaseInitStructure.TIM_Period=100-1;//重装载值
- TIM_TimeBaseInitStructure.TIM_Prescaler=7200-1;//预分频
- TIM_TimeBaseInitStructure.TIM_RepetitionCounter=0x00;//重复计数器
- TIM_TimeBaseInit(TIM1,&TIM_TimeBaseInitStructure);
- TIM_CleaRFlag(TIM1,TIM_FLAG_Update);
- TIM_ITConfig( TIM1, TIM_IT_Update| TIM_IT_trigger, ENABLE );
- NVIC_InitTypeDef NVIC_InitStructure;
- NVIC_InitStructure.NVIC_IRQChannel=TIM1_UP_IRQn;//TIM1中断
- NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=1; //先占优先级0级
- NVIC_InitStructure.NVIC_IRQChannelSubPriority=1; //从优先级3级
- NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE; //IRQ通道被使能
- NVIC_Init(&NVIC_InitStructure);
- TIM_Cmd(TIM1,ENABLE);//使能定时器
- }
- void TIM1_UP_IRQHandle(void)
- {
- if(TIM_GetITStatus(TIM1,TIM_IT_Update))
- {
- n++;
- }
- TIM_ClearITPendingBit(TIM1,TIM_IT_Update);//清除中断标志位
- }
复制代码
我将n扩展到主文件,用oled屏幕显示,但是n一直等于0,定时器1的计数器的值也等64。
|