diff Small_CPU/Src/externalInterface.c @ 861:ad96f99ebc78 Evo_2_23

Synchronize ADC and UART activities: depending on the cable configuration the UART sensor operation may have an impact to the ADC measurement (peaks). To avoid this the ADC measurements are now only started in case no UART communication is pending.
author Ideenmodellierer
date Tue, 07 May 2024 21:25:25 +0200
parents c3dd461ca3f9
children 4832981f9af8
line wrap: on
line diff
--- a/Small_CPU/Src/externalInterface.c	Tue May 07 21:20:56 2024 +0200
+++ b/Small_CPU/Src/externalInterface.c	Tue May 07 21:25:25 2024 +0200
@@ -68,6 +68,7 @@
 static uint8_t recBuf[ADC_ANSWER_LENGTH];
 static uint8_t timeoutCnt = 0;
 static uint8_t externalInterfacePresent = 0;
+static uint8_t delayAdcConversion = 0;
 
 float externalChannel_mV[MAX_ADC_CHANNEL];
 static uint8_t  externalV33_On = 0;
@@ -104,6 +105,7 @@
 	activeChannel = 0;
 	timeoutCnt = 0;
 	externalInterfacePresent = 0;
+	delayAdcConversion = 0;
 	if(externalInterface_StartConversion(activeChannel) == HAL_OK)
 	{
 		externalInterfacePresent = 1;
@@ -171,7 +173,15 @@
 
 	if(externalADC_On)
 	{
-		if(I2C_Master_Receive(DEVICE_EXTERNAL_ADC, recBuf, ADC_ANSWER_LENGTH) == HAL_OK)
+		if(delayAdcConversion)
+		{
+			if(UART_isComActive(activeUartChannel) == 0)
+			{
+				externalInterface_StartConversion(activeChannel);
+				delayAdcConversion = 0;
+			}
+		}
+		else if(I2C_Master_Receive(DEVICE_EXTERNAL_ADC, recBuf, ADC_ANSWER_LENGTH) == HAL_OK)
 		{
 			if((recBuf[ANSWER_CONFBYTE_INDEX] & ADC_START_CONVERSION) == 0)		/* !ready set => received data contains new value */
 			{
@@ -195,25 +205,23 @@
 				}
 
 				activeChannel = nextChannel;
-				externalInterface_StartConversion(activeChannel);
-				timeoutCnt = 0;
-			}
-			else
-			{
-				if(timeoutCnt++ >= ADC_TIMEOUT)
+				if(UART_isComActive(activeUartChannel) == 0)
 				{
 					externalInterface_StartConversion(activeChannel);
-					timeoutCnt = 0;
 				}
-			}
-		}
-		else		/* take also i2c bus disturb into account */
-		{
-			if(timeoutCnt++ >= ADC_TIMEOUT)
-			{
-				externalInterface_StartConversion(activeChannel);
+				else
+				{
+					delayAdcConversion = 1;
+				}
 				timeoutCnt = 0;
 			}
+
+		}
+		if(timeoutCnt++ >= ADC_TIMEOUT)
+		{
+			externalInterface_StartConversion(activeChannel);
+			delayAdcConversion = 0;
+			timeoutCnt = 0;
 		}
 	}
 	return retval;