changeset 861:ad96f99ebc78 Evo_2_23 tip

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 3e499569baf3
children
files Small_CPU/Inc/uart.h Small_CPU/Src/externalInterface.c Small_CPU/Src/uart.c
diffstat 3 files changed, 35 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/Small_CPU/Inc/uart.h	Tue May 07 21:20:56 2024 +0200
+++ b/Small_CPU/Inc/uart.h	Tue May 07 21:25:25 2024 +0200
@@ -48,6 +48,7 @@
 void UART_ReadData(uint8_t sensorType);
 void UART_FlushRxBuffer(void);
 void UART_ChangeBaudrate(uint32_t newBaudrate);
+uint8_t UART_isComActive(uint8_t sensorId);
 
 void StringToInt(char *pstr, uint32_t *puInt32);
 void StringToUInt64(char *pstr, uint64_t *puint64);
--- 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;
--- a/Small_CPU/Src/uart.c	Tue May 07 21:20:56 2024 +0200
+++ b/Small_CPU/Src/uart.c	Tue May 07 21:25:25 2024 +0200
@@ -260,6 +260,17 @@
 	}
 }
 
+uint8_t UART_isComActive(uint8_t sensorId)
+{
+	uint8_t active = 1;
 
+	uint8_t ComState = externalInterface_GetSensorState(sensorId + EXT_INTERFACE_MUX_OFFSET);
+
+	if((ComState == UART_COMMON_INIT) || (ComState == UART_COMMON_IDLE) || (ComState == UART_COMMON_ERROR))
+	{
+		active = 0;
+	}
+	return active;
+}
 
 /************************ (C) COPYRIGHT heinrichs weikamp *****END OF FILE****/