|
stm32的定时器,只想用它的计数功能,可是不知道怎么搞的,中断标志老是清不掉,仿真的时候一直在进中断!
造成程序根本就没法走
这是中断设置
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQChannel;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
这是初始化
void tim2_init(void)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_Cmd(TIM2, DISABLE);
TIM_TimeBaseStructure.TIM_Period = 1;
TIM_TimeBaseStructure.TIM_Prescaler = 31;
TIM_TimeBaseStructure.TIM_ClockDivision = 0;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure);
TIM_PrescalerConfig(TIM2, 31, TIM_PSCReloadMode_Immediate);
TIM_ClearFlag(TIM2, TIM_FLAG_Update);
TIM_Cmd(TIM2, ENABLE);
TIM_ITConfig(TIM2, TIM_IT_Update, ENABLE);
}
这是中断服务
void TIM2_IRQHandler(void)
{
Tim2Value++;
TIM_ClearITPendingBit(TIM2, TIM_IT_Update);
}
谁能看看有什么问题?????
|
|