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 06:07
回复【7楼】Croatoan:
---------------------------------
后来发现不是优先级的问题,而是中断处理函数写错了。
iseafish
2楼-- · 2019-07-21 08:58
回复【9楼】Croatoan:
---------------------------------
正确: void TIM3_IRQHandler(void)   错误:正确: void TIM3_IRQnHandler(void)  
多加了一个n。
jiutianshenjian
3楼-- · 2019-07-21 10:25
去掉printf试一试
正点原子
4楼-- · 2019-07-21 11:38
现象是什么?
iseafish
5楼-- · 2019-07-21 13:02
 精彩回答 2  元偷偷看……
iseafish
6楼-- · 2019-07-21 17:12
回复【3楼】正点原子:
---------------------------------
用JTAG仿真单步执行,配置完后进入while循环,一次中断都没进去,停止Debug后,函数停在startup_stm32f10x_hd.s里面的B    .  指令,我用的芯片是STM32103FZET.

一周热门 更多>