cancel
Showing results for 
Search instead for 
Did you mean: 

UART data receive acknowledgement

Nico3
Senior

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.. ;)

1 ACCEPTED SOLUTION

Accepted Solutions

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?

 

View solution in original post

4 REPLIES 4

>>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.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

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?

 

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. 

 

Yes.

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