diff Discovery/Src/tComm.c @ 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 fe955104901c
children 1b05a84f6d0f
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;