2017-11-27 02:57 PM
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 modeThe 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
#stm8s003f32017-11-27 03:25 PM
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.
2017-11-28 12:43 AM
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.