cancel
Showing results for 
Search instead for 
Did you mean: 

In UART RS485 transmission the last byte always missing in HTERM (STM8S003F3)

Lei Sun
Associate II
Posted on November 27, 2017 at 23:57

Hi all, I am using currently STM8S003F3 for my work and I want to send an array of bytes to the HTERM on my PC using UART RS485. But I always miss the last byte in the array (I can't see the last byte in HTERM). Here is a shot code snippet:

_UART_TX_ON; //switch to UART485 transmission mode

for ( bn=0; bn<17; bn++) {

   UART1->DR = bSPIRxBuf[bn]; //UART1_SendData8(bSPIRxBuf[bn]);

   while ( (UART1->SR & 0x80) == 0x00); //while (UART1_GetFlagStatus(UART1_FLAG_TXE) == RESET);

}

_UART_RX_ON; //switch to UART485 reception mode

The array bSPIRxBuf[0-16] has already some predefined content. But in Hterm I can only observe 16 bytes, which means the last byte is always not received by HTERM. I don't know why and could not explain. I think that I have waited enough time for each transmit byte before switching to reception mode using the while function. Anyone has some ideas? Many thanks!

Regards,

Bo

#stm8s003f3
2 REPLIES 2
Posted on November 28, 2017 at 00:25

Doesn't TXE flag when the first bit hits the wire? Do you have TC (Transmit Complete) ? That would be a better to test as to when the last bit has left.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on November 28, 2017 at 08:43

I used the TXE flag in the while loop for the check. But I didn't use the TC flag.

Actually this code works fine with RS232, where

_UART_TX_ON

 and

_UART_RX_ON

 are not necessary due to full duplex of RS232.

I've also tried to add a delay function after the for loop and before 

_UART_RX_ON

and this does not help.