Skip to main content
Graduate II
March 14, 2024
Solved

UART data receive acknowledgement

  • March 14, 2024
  • 2 replies
  • 2421 views

Two devices A & B are communicating on UART. A sends data stream to B. B sends one byte data back to A to acknowldge that data has been received. 

I want to implement if A doesn't receive acknowledgement from B then it display Error message on LCD.

Please suggest best logic in A to implement this.

As far I think I should start the UART_Receive_IT API for one byte . and complete callback sets the flag for acknowlegement. Incase flag is not set within one second or so after sending data then A display Error message on LCD. Should I start HAL_Delay(1000) after sending data and then check for flag set or not?

If anyother best way, kindly suggest. 

I am still relatively new to coding word..so trying to find best ways.. ;)

    This topic has been closed for replies.
    Best answer by Andrew Neil

    The blocking HAL_UART_Receive() API takes a timeout:

    AndrewNeil_0-1710437312958.png

    the non-blocking HAL_UART_Receive_IT() doesn't:

    AndrewNeil_1-1710437344915.png

     

    Using HAL_Delay() effectively makes your code blocking - so there seems no point in using the non-blocking API?

     

    2 replies

    Graduate II
    March 14, 2024

    >>Should I start HAL_Delay(1000) after sending data and then check for flag set or not?

    No, you'd do better taking a TickCount, say HAL_GetTick(), and use that to determine if enough time has expired without getting a callback with the acknowledgment byte 

    If it responds more quickly you can proceed to do other things.

    Super User
    March 14, 2024

    The blocking HAL_UART_Receive() API takes a timeout:

    AndrewNeil_0-1710437312958.png

    the non-blocking HAL_UART_Receive_IT() doesn't:

    AndrewNeil_1-1710437344915.png

     

    Using HAL_Delay() effectively makes your code blocking - so there seems no point in using the non-blocking API?

     

    Nico3Author
    Graduate II
    March 14, 2024

    Cool,

    So after sending data , i run the blocking HAL_UART_Receive()with timeout of say 1 second and then check the HAL_StatusTypeDef return. 

     

    Super User
    March 14, 2024

    Yes.

    And, of course, check the received character (if any) - to make sure it's the correct acknowledgement.