简体   繁体   中英

STM32 Usart1 doesn't work with TIM1 at the same time

I came across a problem while programming my stm32f103rbt6.

I'm using TIM1 (PB14, PB15) to generate PWM signal (works great) and USART1 (PA9, PA10) for bluetooth communication. The thing is, that I can't make PWM and USART1 TX work at the same time. Everything works perfect until I make this config:

TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
TIM_OCInitStructure.TIM_OutputNState = TIM_OutputNState_Enable;
TIM_OCInitStructure.TIM_Pulse = 0;
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
TIM_OC2Init(TIM1, &TIM_OCInitStructure);
TIM_OC2PreloadConfig(TIM1, TIM_OCPreload_Enable);

USART1 TX stops working after that. I'll appreciate any help!

Never use ST's structures without complete initialization of its fields!

In your case, there is enabled TIM1_CH2 output on PA9 pin, because you didn't specify TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Disable .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM