Skip to main content
WalterE
Associate
May 31, 2019
Question

USART HAL Tx Mirror on Rx

  • May 31, 2019
  • 0 replies
  • 709 views

Hi!

I have a hardware setup with an RS485 in which all Tx Data is mirrored to Rx (no delay).

This simple example should echo all incoming chars coming from Rx back to Tx

If i do not use the delay in the callback before flushing DR the hardware mirrored Tx Data will not get flushed. - Sending one char to the Rx will end up in an endless loop of sending and receiving the same char.

So my question is:

Does HAL_UART_Transmit return before TC bit is set?

Any other explaination?

regards,

Walter

int main(void)
{
 ...
 HAL_UART_Receive_IT(&huart1, &buffer, 1);
}
 
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
{
 HAL_UART_Transmit(&huart1, &buffer, 1,0xff);
 HAL_Delay(10);
 /* If i do not use this delay there is a possibilty, that the UART data register will be filled up by 
 the mirrored Tx data after __HAL_UART_FLUSH_DRREGISTER 
 Open Questions regarding to this phenomenon:
 Does HAL_UART_Transmit return before TC bit is set? 
 */
 __HAL_UART_FLUSH_DRREGISTER(&huart1);
 HAL_UART_Receive_IT(&huart1, &buffer, 1);
}

This topic has been closed for replies.