changeset 276:8e9c502c0b06 IPC_Sync_Improvment_3

Rework pressure/ temperature data aquisition The data data provided by the I2C data had been used for calculation independend if transmission was successfull or not => state evaluation added In the previous version data with resolution 0.5mBar and temperature was requested per cycle inparallel. This has been replaced by a requested resolution of 1mBar and an alternating aquisition (pressure / temp update every 200ms instead every 100ms) => reducing busy wait time and power consumption
author ideenmodellierer
date Sun, 28 Apr 2019 10:06:27 +0200
parents 189387bf23a8
children 580822b5d3d1
files Small_CPU/Inc/pressure.h Small_CPU/Src/pressure.c
diffstat 2 files changed, 59 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/Small_CPU/Inc/pressure.h	Sun Apr 28 09:54:43 2019 +0200
+++ b/Small_CPU/Inc/pressure.h	Sun Apr 28 10:06:27 2019 +0200
@@ -6,11 +6,12 @@
 
 uint8_t init_pressure(void);
 uint8_t pressure_update(void);
+void pressure_update_alternating(void);
 
 uint8_t is_init_pressure_done(void);
 
-void  pressure_sensor_get_pressure_raw(void);
-void  pressure_sensor_get_temperature_raw(void);
+HAL_StatusTypeDef  pressure_sensor_get_pressure_raw(void);
+HAL_StatusTypeDef  pressure_sensor_get_temperature_raw(void);
 void pressure_calculation(void);
 
 float get_temperature(void);
--- a/Small_CPU/Src/pressure.c	Sun Apr 28 09:54:43 2019 +0200
+++ b/Small_CPU/Src/pressure.c	Sun Apr 28 10:06:27 2019 +0200
@@ -306,6 +306,28 @@
 	return (uint8_t)statusReturn;
 }
 
+/* Switch between pressure and temperature measurement with every successful read operation */
+void pressure_update_alternating(void)
+{
+	static uint8_t getTemperature= 0;
+
+	if(getTemperature)
+	{
+		if(pressure_sensor_get_temperature_raw() == HAL_OK)
+		{
+			getTemperature = 0;
+		}
+	}
+	else
+	{
+		if(pressure_sensor_get_pressure_raw() == HAL_OK)
+		{
+			getTemperature = 1;
+		}
+	}
+	pressure_calculation();
+	return;
+}
 
 static uint32_t pressure_sensor_get_one_value(uint8_t cmd, HAL_StatusTypeDef *statusReturn)
 {
@@ -333,12 +355,23 @@
 
 static HAL_StatusTypeDef pressure_sensor_get_data(void)
 {
+	uint32_t requestedValue = 0;
 	HAL_StatusTypeDef statusReturn1 = HAL_TIMEOUT;
 	HAL_StatusTypeDef statusReturn2 = HAL_TIMEOUT;
 	
-	D2 = pressure_sensor_get_one_value(CMD_ADC_D2 + CMD_ADC_4096, &statusReturn1);
-	D1 = pressure_sensor_get_one_value(CMD_ADC_D1 + CMD_ADC_4096, &statusReturn2);
+
 
+	requestedValue = pressure_sensor_get_one_value(CMD_ADC_D2 + CMD_ADC_1024, &statusReturn2);
+	if (statusReturn2 == HAL_OK)
+	{
+		D2 = requestedValue;
+	}
+
+	requestedValue = pressure_sensor_get_one_value(CMD_ADC_D1 + CMD_ADC_1024, &statusReturn1);
+	if (statusReturn1 == HAL_OK)
+	{
+		D1 = requestedValue;
+	}
 	if(statusReturn2 > statusReturn1) // if anything is not HAL_OK (0x00) or worse
 		return statusReturn2;
 	else
@@ -346,15 +379,32 @@
 }
 
 
-void  pressure_sensor_get_pressure_raw(void)
+HAL_StatusTypeDef  pressure_sensor_get_pressure_raw(void)
 {
-	D1 = pressure_sensor_get_one_value(CMD_ADC_D1 + CMD_ADC_4096, 0);
+	uint32_t requestedValue = 0;
+	HAL_StatusTypeDef statusReturn = HAL_TIMEOUT;
+
+	requestedValue = pressure_sensor_get_one_value(CMD_ADC_D1 + CMD_ADC_1024, &statusReturn);
+	if (statusReturn == HAL_OK)
+	{
+		D1 = requestedValue;
+	}
+
+	return statusReturn;
 }
 
 
-void  pressure_sensor_get_temperature_raw(void)
+HAL_StatusTypeDef  pressure_sensor_get_temperature_raw(void)
 {
-	D2 = pressure_sensor_get_one_value(CMD_ADC_D2 + CMD_ADC_4096, 0);
+	uint32_t requestedValue = 0;
+	HAL_StatusTypeDef statusReturn = HAL_TIMEOUT;
+
+	requestedValue = pressure_sensor_get_one_value(CMD_ADC_D2 + CMD_ADC_1024, &statusReturn);
+	if (statusReturn == HAL_OK)
+	{
+		D2 = requestedValue;
+	}
+	return statusReturn;
 }