同志们,我想请教一下定时器使用的问题,我用定时器6作为计时,当计时到时间时就产生一个标志位,我用这个标志位作为发送数据的标志,可是我配置好之后,发现定时器6根本就没有用,标志位在一直不断的置位,从而我的发送数据也一直不断的在发送,配置如下,还请高手指示
void TIM6_NVIC_Configuration(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
NVIC_InitStructure.NVIC_IRQChannel = TIM6_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 5;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
void TIM6_Configuration(void)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM6 , ENABLE);
TIM_TimeBaseStructure.TIM_Period=499;
TIM_TimeBaseStructure.TIM_Prescaler= 71;
TIM_TimeBaseStructure.TIM_ClockDivision=TIM_CKD_DIV1;
TIM_TimeBaseStructure.TIM_CounterMode=TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM6, &TIM_TimeBaseStructure);
TIM_ClearFlag(TIM6, TIM_FLAG_Update);
TIM_ITConfig(TIM6,TIM_IT_Update,ENABLE);
TIM_Cmd(TIM6, ENABLE);
}
void TIM6_IRQHandler(void)
{
if (TIM_GetITStatus(TIM6, TIM_IT_Update) != RESET)
{
TIM_ClearITPendingBit(TIM6, TIM_IT_Update);
TIM_ClearFlag(TIM6, TIM_FLAG_Update);
time6_flag=1;
}
}
以上是定时器6的配置,可是就是不能用,还请大神指教 |