void Timbase(void)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
// Enable TIM3 global interrupt with Preemption Priority 0 and SubPriority as 2/
NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQChannel;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
///时器的基本设置
TIM_TimeBaseStructure.TIM_Prescaler = 29;//时钟预分频数 例如 :时
///钟频率=72/(时钟预分频+1)
TIM_TimeBaseStructure.TIM_Period = 57; // 自动重装载寄存器周期的值(定时
//时间) 累计 0xFFFF个频率后产生个更新或者中断(也是说定时时间到)
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; //定时器
//模式 向上计数
TIM_TimeBaseStructure.TIM_ClockDivision = 0; //时间分割值
TIM_TimeBaseStructure.TIM_RepetitionCounter = 0;
TIM_PrescalerConfig(TIM3, 7, TIM_PSCReloadMode_Immediate);
TIM_ClearFlag(TIM3, TIM_FLAG_Update);
TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure);//初始化定时器2
TIM_ITConfig(TIM3, TIM_IT_Update, ENABLE); //打开中断 溢出中断
TIM_Cmd(TIM3, ENABLE);//打开定时器
}
/*******************************************************************************
* Function Name : TIM3_IRQHandler
* Description : This function handles TIM3 global interrupt request.
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void TIM3_IRQHandler(void)
{
//
if (TIM_GetITStatus(TIM3, TIM_FLAG_Update) != RESET)
{
TIM_ClearFlag(TIM3, TIM_FLAG_Update);
hCCDmaBuffCh1[0] = 100;
hCCDmaBuffCh2[0] = 100;
hCCDmaBuffCh3[0] = 100;
PingPang = 1;
}
// TIM_ClearITPendingBit(TIM3, TIM_FLAG_Update);
}
运行的时候,程序老跑飞,请各位高手看一下,中断向量设置是不是对的。 |