changeset 886:d398ecc7d103 Evo_2_23

Improve communication stability: In case e.g. the bluetooth module has just been started some 'noice' characters may be in the receive buffer causing an error in the modul responds function. In case the legth of the response is unexpected then the buffer will be evaluated till it is empty or an matching answer is found.
author Ideenmodellierer
date Sun, 01 Sep 2024 21:38:06 +0200
parents 8d3f3a635397
children 17f02ac9da67
files Discovery/Src/tComm.c
diffstat 1 files changed, 4 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/Discovery/Src/tComm.c	Sun Sep 01 21:35:50 2024 +0200
+++ b/Discovery/Src/tComm.c	Sun Sep 01 21:38:06 2024 +0200
@@ -2038,9 +2038,11 @@
 		{
 			do
 			{
-				answer = HAL_UART_Receive(&UartHandle, (uint8_t*)&aRxBuffer[indexBuf], 1, 10);
+				answer = HAL_ERROR;
 				if (indexBuf < UART_CMD_BUF_SIZE)
 				{
+					answer = HAL_UART_Receive(&UartHandle, (uint8_t*)&aRxBuffer[indexBuf], 1, 10);
+
 					if(answerOkay[indexRef] == aRxBuffer[indexBuf])
 					{
 						indexRef++;
@@ -2054,7 +2056,7 @@
 					}
 					indexBuf++;
 				}
-			}while(answer == HAL_OK);
+			}while((answer == HAL_OK) && (indexRef != sizeAnswer));
 			if(indexRef != sizeAnswer)
 			{
 				result = HAL_ERROR;