不好意思,stm32用了这么长时间,还出这问题,但我调了一上午还是一头雾水。请教一下
我需要用tim2_ch1做一个方波(48K)输出,
1、IO口配置成GPIO_Mode_AF_PP
2、不使能USART2
3、tim2配置如下
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_OCInitTypeDef TIM_OCInitStructure;
TIM_TimeBaseStructure.TIM_Period = TIM2_CYCLE_Val-1;
TIM_TimeBaseStructure.TIM_Prescaler = TIM2_Pre;
TIM_TimeBaseStructure.TIM_ClockDivision = 0x0;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure);
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_Toggle;
TIM_OCInitStructure.TIM_Pulse = 0;
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
TIM_OC1Init(TIM2, &TIM_OCInitStructure);
TIM_OC1PreloadConfig(TIM2, TIM_OCPreload_Disable);
TIM_ITConfig(TIM2, TIM_IT_CC1, ENABLE);
TIM_Cmd(TIM2, ENABLE);
}
如此配置后,ch1对应IO口没有波形输出,我为了测试配置是否正确,将timer通道换乘ch2,没有问题,能够输出正确波形。同时配置ch1 和 ch2,两个对应IO依然无法输出。
不知问题出在哪里? |