EmbDev.net

Forum: µC & Digital Electronics STM32F107 USART Init --> Rubbish Output


von Marco (Guest)


Rate this post
0 useful
not useful
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:
      AFIO->MAPR   &= ~(AFIO_MAPR_USART2_REMAP);  /* clear USART2 remap */
      RCC->APB2ENR |= RCC_APB2ENR_AFIOEN;         /* enable clock for Alternate Function */
      AFIO->MAPR   |= AFIO_MAPR_USART2_REMAP;     /* set   USART2 remap */
      RCC->APB2ENR |=  RCC_APB2ENR_IOPDEN;        /* enable clock for GPIOD */
      GPIOD->CRL   &= ~(0xFFUL  << 20);           /* Clear PD5, PD6 */
      GPIOD->CRL   |=  (0x0BUL  << 20);           /* USART2 Tx (PD5)  alternate output push-pull */
      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

von A. K. (prx)


Rate this post
0 useful
not useful
If the USART is configured after the pins have been defined as alternate 
function, the intial state of Tx could be undefined.

von Marco (Guest)


Rate this post
0 useful
not useful
So you mean the order of the initialization is wrong? Configuring the 
GPIO pins first and then the alternate function?

Reply

Entering an e-mail address is optional. If you want to receive reply notifications by e-mail, please log in.

Rules — please read before posting

  • Post long source code as attachment, not in the text
  • Posting advertisements is forbidden.

Formatting options

  • [c]C code[/c]
  • [avrasm]AVR assembler code[/avrasm]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]




Bild automatisch verkleinern, falls nötig
Note: the original post is older than 6 months. Please don't ask any new questions in this thread, but start a new one.