请求支援 : 在同一工程中,设置F407通用定时器2(TIM2)和定时器3(TIM3)中断,在主函数初始化定时器时,定时器2可以通过初始化,可是初始化定时器3时在( NVIC_Init(&NVIC_InitStructure); 就不能运行下去了...... 有点迷茫为什么觉得定时器设置好像没有错,为什么程序就不能运行下去???
//通用定时器2中断初始化
void TIM2_Int_Init(void)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2,ENABLE); ///使能TIM2时钟
TIM_TimeBaseInitStructure.TIM_Period = 8400-1; //自动重装载值
TIM_TimeBaseInitStructure.TIM_Prescaler=10-1; //定时器分频
TIM_TimeBaseInitStructure.TIM_CounterMode=TIM_CounterMode_Up; //向上计数模式
TIM_TimeBaseInitStructure.TIM_ClockDivision=TIM_CKD_DIV1;
TIM_TimeBaseInit(TIM2,&TIM_TimeBaseInitStructure);//初始化TIM2
TIM_ITConfig(TIM2,TIM_IT_Update,ENABLE); //允许定时器2更新中断
TIM_Cmd(TIM2,ENABLE); //使能定时器2
//中断优先级NVIC设置
NVIC_InitStructure.NVIC_IRQChannel=TIM2_IRQn; //定时器2中断
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=0; //抢占优先级0
NVIC_InitStructure.NVIC_IRQChannelSubPriority=3; //子优先级3
NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE;
NVIC_Init(&NVIC_InitStructure);
printf("time2 Init OK
");
}
//通用定时器3中断初始化
void TIM3_Int_Init(void)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3,ENABLE); ///使能TIM3时钟
TIM_TimeBaseInitStructure.TIM_Period = 8400-1; //自动重装载值
TIM_TimeBaseInitStructure.TIM_Prescaler=10-1; //定时器分频
TIM_TimeBaseInitStructure.TIM_CounterMode=TIM_CounterMode_Up; //向上计数模式
TIM_TimeBaseInitStructure.TIM_ClockDivision=TIM_CKD_DIV1; //设置时钟分割:TDTS = Tck_tim
TIM_TimeBaseInit(TIM3,&TIM_TimeBaseInitStructure);//初始化TIM3
TIM_ITConfig(TIM3,TIM_IT_Update,ENABLE); //允许定时器3更新中断
TIM_Cmd(TIM3,ENABLE); //使能定时器3
//中断优先级NVIC设置
NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn; //TIM3中断
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; //优占优先级0级
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2; //从优先级2级
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQ通道被使能
// 初始化定时器程序只能运行到这里
NVIC_Init(&NVIC_InitStructure); //初始化NVIC寄存器
printf("time3 Init OK
");
}
我的是F103的板子,我的也是这种情况,我仿真跟踪的时候,单步调试第二个也可以初始化,但是一旦用step out就卡住。
一周热门 更多>