STM32F107 USART Init --> Rubbish Output

Guest #1760486
Hi,

While configuring my STM32F107's USART, there is a random byte outputted 
on the tx-pin. A modem that is connected to the serial port gets 
confused by this random byte and refuses to work.

Here's the initialization code:
1
      AFIO->MAPR   &= ~(AFIO_MAPR_USART2_REMAP);  /* clear USART2 remap */
2
      RCC->APB2ENR |= RCC_APB2ENR_AFIOEN;         /* enable clock for Alternate Function */
3
      AFIO->MAPR   |= AFIO_MAPR_USART2_REMAP;     /* set   USART2 remap */
4
      RCC->APB2ENR |=  RCC_APB2ENR_IOPDEN;        /* enable clock for GPIOD */
5
      GPIOD->CRL   &= ~(0xFFUL  << 20);           /* Clear PD5, PD6 */
6
      GPIOD->CRL   |=  (0x0BUL  << 20);           /* USART2 Tx (PD5)  alternate output push-pull */
7
      GPIOD->CRL   |=  (0x04UL  << 24);           /* USART2 Rx (PD6)  input floating */

The random byte appears with the configuration for pin PD5 as alternate 
output push-pull.

Any hints or ideas on how to not get this rubbish-byte on 
initialization?

Thanks!

--
Regards
Guest #1762391
So you mean the order of the initialization is wrong? Configuring the 
GPIO pins first and then the alternate function?

Reply

A question of your own? This thread is over 16 years old. Ask it in a thread of its own – more people read along there, and it gets answered more often and sooner.

Start a new thread

A fix, an addition or feedback on this thread? Then reply here.

Formatting
  • [c]C-Code[/c]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]
  • [[Title]] – link to an article
  • Link to another post: right-click its post ID (#8078628), copy the address, paste it into the text

More about formatting

Post long source code as an attachment, not in the text.

Already registered? Log in

Not shown to anyone. We send you a link; your post appears once you confirm it there.

By submitting you create a free account and accept the terms of use.