TIM2 TIM3两个定时器中断 无法配置

2019-07-21 04:28发布

TIM2、TIM3两个定时器一起配置中断,无法实现。
但配置TIM2的NVIC则不会出错,但加上TIM3的NVIC则会出错。
TIM2配置
[mw_shl_code=c,true]void TIM2_Config(void) { TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; printf(" TIM2_CONFIG_IN! "); RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2,ENABLE); TIM_DeInit(TIM2); TIM_TimeBaseStructure.TIM_Period = 7199; TIM_TimeBaseStructure.TIM_Prescaler = 39; TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1; TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; TIM_TimeBaseInit(TIM2,&TIM_TimeBaseStructure); TIM_ClearFlag(TIM2, TIM_FLAG_Update); TIM_ITConfig(TIM2,TIM_IT_Update|TIM_IT_Trigger,ENABLE);// TIM_Cmd(TIM2, ENABLE); printf(" TIM2_CONFIG_OK! "); } void TIM2_NVIC(void) { NVIC_InitTypeDef NVIC_InitStructure; printf(" TIM2_NVIC_IN! "); NVIC_InitStructure.NVIC_IRQChannel=TIM2_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=1; NVIC_InitStructure.NVIC_IRQChannelSubPriority=1; NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE; NVIC_Init(&NVIC_InitStructure); }[/mw_shl_code] TIM3配置 [mw_shl_code=c,true]void TIM3_NVIC(void) { NVIC_InitTypeDef NVIC_InitStructure; NVIC_SetVectorTable(NVIC_VectTab_FLASH,0x0); NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); NVIC_InitStructure.NVIC_IRQChannel=TIM3_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=0; NVIC_InitStructure.NVIC_IRQChannelSubPriority=0; NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE; NVIC_Init(&NVIC_InitStructure); } void TIM3_GPIO_Config(void) { GPIO_InitTypeDef GPIO_InitStructure; //?????¨?±?÷3???±?? RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3,ENABLE); //????PINA,PINB???±?? RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE); RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6|GPIO_Pin_7; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOA,&GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0; GPIO_Init(GPIOB,&GPIO_InitStructure); printf(" TIM3 GPIO OK "); } void TIM3_Mode_Config(void) { TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; TIM_OCInitTypeDef TIM_OCInitStructure; printf(" TIM3_MODE_IN! "); TIM_TimeBaseStructure.TIM_Period = 35999; TIM_TimeBaseStructure.TIM_Prescaler = 39; TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1; TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; TIM_TimeBaseInit(TIM3,&TIM_TimeBaseStructure); //????TIM3?????? TIM_ClearFlag(TIM3, TIM_FLAG_Update); TIM_ITConfig(TIM3,TIM_IT_Update|TIM_IT_Trigger,ENABLE); TIM_Cmd(TIM3, ENABLE); TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1; TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; TIM_OCInitStructure.TIM_Pulse = servox_pulse; TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High; TIM_OC1Init(TIM3, &TIM_OCInitStructure); TIM_OC1PreloadConfig(TIM3, TIM_OCPreload_Enable); TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; TIM_OCInitStructure.TIM_Pulse = servoy_pulse; TIM_OC2Init(TIM3, &TIM_OCInitStructure); TIM_OC2PreloadConfig(TIM3, TIM_OCPreload_Enable); TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; TIM_OCInitStructure.TIM_Pulse = servoz_pulse; TIM_OC3Init(TIM3, &TIM_OCInitStructure); TIM_OC3PreloadConfig(TIM3, TIM_OCPreload_Enable); // TIM_ARRPreloadConfig(TIM3, ENABLE); /* TIM3 enable counter */ printf(" TIM3 MODE OK "); }[/mw_shl_code] 麻烦各位帮我看一下,谢谢!
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
该问题目前已经被作者或者管理员关闭, 无法添加新回复
9条回答
iseafish
1楼-- · 2019-07-21 19:35
回复【2楼】jiutianshenjian:
---------------------------------
去掉Printf,没有解决问题哦。
Croatoan
2楼-- · 2019-07-21 21:05
使用F407也 出现过这种问题,貌似是优先级问题?
Croatoan
3楼-- · 2019-07-22 00:38
回复【8楼】iseafish:
--------------------------------求分享错误程序,我当时重新写了一个绕过去了。。还不知道哪里错了

一周热门 更多>