Skip to main content
Visitor II
December 17, 2012
Question

How to correctly configure UART pins in asembler

  • December 17, 2012
  • 1 reply
  • 781 views
Posted on December 17, 2012 at 22:07

I'm willing to init UART in asm and not sure is it required to configure specific IO port pin as  output pin with Px_DDR and only then then I can use UART_TX  or

the pin configures in output type automatically when UART is enabled in UART register?

Example:

There is shared UART1_TX/PA5 pin. After reset it is ''input'' - PA_DDR = $00

I want to use UART1 - prior that do I need this code or not?:

 

     ld     A,♯%00100000 ; makes PA.5 - output

     ld      PA_DDR,A

 

#stm8s-uart-asm
    This topic has been closed for replies.

    1 reply

    Visitor II
    December 19, 2012
    Posted on December 19, 2012 at 10:12

    Hello karlen.

    It's true that UART configures its TX pin as output, but you have to set Px_DDR, Px_CR1, Px_CR2 and Px_ODR too.

    There is a simple reason: the bit of Px_CR1, which is related to UART output, enables the push/pull ouput.

    If you let UART use its TX output pin as it's configured by default, it may not work because it's configured by default as open drain.

    It's also useful to set Px_CR2, since it controls the speed of transitions between high and low logic levels.

    I suggest you to set Px_ODR to the TX idle value too, because the other side of serial link may detect an error.

    I usually configure all pins as soon as possible by using the following instructions:

    MOV PA_ODR,#%00100000

    MOV PA_DDR,#%00100000

    MOV PA_CR1,#%00100000

    MOV PA_CR2,#%00100000

    However, your values may differ, because GPIO port pins are shared between various devices and/or application needs.

    You may also read STM8S family reference manual and your part datasheet to understand how to configure GPIOs according to your application.

    Regards

    EtaPhi