diff Small_CPU/Src/externalInterface.c @ 704:f1b40364b0af

Added protocol functions for UART DiveO2 sensor: The code has been modified to support the handling of several protocols (including baud rate changes). The data is requested by polling and passed via DMA into a ringbuffer which is then parsed by a cyclic function call in the main loop. At the moment only the O2 values are forwarded but because the sensor send several types of data within a signle message already more is extracted but yet discarded.
author Ideenmodellierer
date Fri, 28 Oct 2022 20:49:21 +0200
parents 52d68cf9994c
children 045ff7800501
line wrap: on
line diff
--- a/Small_CPU/Src/externalInterface.c	Fri Oct 28 20:32:24 2022 +0200
+++ b/Small_CPU/Src/externalInterface.c	Fri Oct 28 20:49:21 2022 +0200
@@ -57,6 +57,7 @@
 float externalChannel_mV[MAX_ADC_CHANNEL];
 static uint8_t  externalV33_On = 0;
 static uint8_t  externalADC_On = 0;
+static uint8_t  externalUART_Protocol = 0;
 static uint16_t externalCO2Value;
 static uint16_t externalCO2SignalStrength;
 static uint16_t  externalCO2Status = 0;
@@ -111,7 +112,14 @@
 				activeChannel++;
 				if(activeChannel == MAX_ADC_CHANNEL)
 				{
-					activeChannel = 0;
+					if(externalUART_Protocol == (EXT_INTERFACE_UART_O2 >> 8))		/* mixed mode digital and analog o2 sensors => channel 0 is reserved for digital sensor */
+					{
+						activeChannel = 1;
+					}
+					else
+					{
+						activeChannel = 0;
+					}
 				}
 				externalInterface_StartConversion(activeChannel);
 				timeoutCnt = 0;
@@ -218,6 +226,11 @@
 	return externalADC_On;
 }
 
+uint8_t externalInterface_GetUARTProtocol()
+{
+	return externalUART_Protocol;
+}
+
 void externalInterface_SwitchPower33(uint8_t state)
 {
 	if(state != externalV33_On)
@@ -226,7 +239,6 @@
 		{
 			HAL_GPIO_WritePin(GPIOC,GPIO_PIN_7,GPIO_PIN_RESET);
 			externalV33_On = 1;
-			MX_USART1_UART_Init();
 		}
 		else
 		{
@@ -234,7 +246,6 @@
 			externalV33_On = 0;
 			externalInterface_SetCO2Value(0);
 			externalInterface_SetCO2SignalStrength(0);
-			MX_USART1_UART_DeInit();
 		}
 	}
 }
@@ -251,6 +262,19 @@
 	}
 }
 
+void externalInterface_SwitchUART(uint8_t protocol)
+{
+	if(protocol < 0x08)
+	{
+		externalUART_Protocol = protocol;
+		MX_USART1_UART_DeInit();
+		if( protocol != 0)
+		{
+			MX_USART1_UART_Init();
+		}
+	}
+}
+
 void externalInterface_SetCO2Value(uint16_t CO2_ppm)
 {
 	externalCO2Value = CO2_ppm;