cancel
Showing results for 
Search instead for 
Did you mean: 

STM8S001J3 UART remap

Sang hyeon Jeong
Associate II
Posted on January 05, 2018 at 10:14

Hi

STM8S001J3 There is a problem with UART communication.

If PIN8 is used without remapping tx, it works well.

If tx is remapped and used as PIN5, the following code will not work.

void UART1_init(void)

{

    CLK->CKDIVR = 0x00;

    

CLK->PCKENR1 |= 0x20;

    

// enable clock for USART

    

UART1->BRR2 = 0x0B;

    

    // BaudRate 115200

    

UART1->BRR1 = 0x08;

    UART1->CR2 = 0x2C;

         

// RIEN = ENABLE, TEN = ENABLE, REN = ENABLE

}

void main(void)

{

    UART1_init();

    enableInterrupts(); 

    while(1);

}

INTERRUPT_HANDLER(UART1_RX_IRQHandler, 18)

{

    if(UART1->SR & 0x20)

    {

        char temp = UART1->DR;

        while(!(UART1->SR & 0x80));

        UART1->DR = temp;

    }

}

#stm8s
7 REPLIES 7
Thomas G
Associate II
Posted on January 07, 2018 at 22:27

I didn't test your code, but if it works with PD5 (pin 8) then it should also work with PA3 (pin 5). However, I wouldn't use your code without remapping the pin, or at least adding a 1s delay before the port initialization (throwing away perfectly good chips can be frustrating).

Did you maybe forget to set the option bits (OPT2 bits 0:1 to 0x11)?

I tested the use case with the

https://github.com/TG9541/stm8ef/releases/download/2.2.20/stm8ef-bin.zip

For me the remapping to PA3 (pin 5) works as described in the datasheet.

Using the eForth console and e4thcom setting the option bytes works like this:

#require OPT!

\res MCU: STM8S103

\res export OPT2

3 OPT2 OPT!
Posted on January 08, 2018 at 01:39

Thank you for your reply.

The option bit was set using STVP.

AFR1 and AFR0 have been activated.

If remapping like this, RX interrupt does not work either.
Posted on January 08, 2018 at 06:49

Frankly, I didn't test interrupts at all. I used a 2-wire (half-duplex), that is RX and TX through PA3, with polling.

I did some tests with RX on PD5 and TX on PA3 which for some reason didn't receive data (TX worked). I can run more tests later on, if required (my chip is marked '8S001 YK719').

Remark: based on the assumption that STM8S001J3 and STM8S003F3 are *very* similar, the AFR0=AFR1=1 setting in OPT2 is the only functional difference between the chips I could spot in the datasheet, and in the erratas. As far as I can tell, setting AFR1 and AFR0 has no effect in the STM8S003F3.

Emilio P.G. Ficara
Associate II
Posted on April 11, 2018 at 09:35

I can confirm the troubles with remapping. I also tried to get data from the UART data register using polling, not interrupt, and the behaviour is the same. The receive complete bit is never set. The baud rate is OK, 'cause the UART_TX works correctly. I also tried using the Pin 1 (PD6 / PA1) as general input while UART was enabled for RX and TX and it worked! So, my opinion is that the remapping of UART_TX also remaps (I don't know which way) the UART_RX pin. With such obstacle I can't use the micro for my purposes. I'm planning to remaster the PCB or to create a software UART using Pin 1 with negative edge interrupt and a timer for baud rate, but is a dirty solution. If someone has the proof of good working UART after remapping, please put the solution here! Many thanks.

Igor Cesko
ST Employee
Posted on June 29, 2018 at 10:13

 I confirm this mistake in documentation - it will be corrected in new datasheet (very soon). If the UART_TX is remapped to pin 5 then the 

UART_RX function on pin 1 becomes unavailable(in fact is UART_RX remapped to internal not connected pin). Then the UART can be used only in sinle-wire half duplex mode (or in Smartcard mode) - where only the UART_TX signal is used. This is not ideal but also usable configuration - but needs some adjustment on the host side (either hardware: OR-ing Tx and Rx signals, and software: receive the sent data).

Posted on June 29, 2018 at 22:33

The unconnected GPIO port would be PF4, right?

When revising the datasheet, it would be nice if the bandgap reference at Ain7 and the timer synchronization feature (T5, T6) could find a mention as well.

Posted on July 01, 2018 at 18:21

Thank you Igor. The info was very useful. I tried to use the remapped pin in single wire mode and it worked. I published an article on my website

http://ficara.altervista.org/?p=4047

 , including schematics and full project folder, freely available for download. Hope that this can help other people that is planning to use the STM8S001JL3 microcontroller.