changeset 330:2defc8cd93ce I2C_Improvment

Added check of configuration. In case of a problem in I2C communication the initialization of the battery gauge may have failed. To detect this a check of configuration of I2C reinitialization have been added
author ideenmodellierer
date Wed, 17 Jul 2019 22:43:16 +0200
parents da5b91b1e20e
children b4c578caaafb
files Small_CPU/Inc/batteryGasGauge.h Small_CPU/Src/batteryGasGauge.c
diffstat 2 files changed, 23 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/Small_CPU/Inc/batteryGasGauge.h	Wed Jul 17 22:42:55 2019 +0200
+++ b/Small_CPU/Inc/batteryGasGauge.h	Wed Jul 17 22:43:16 2019 +0200
@@ -29,6 +29,8 @@
 
 /* Includes ------------------------------------------------------------------*/
 
+#include <stdint.h>
+
 void init_battery_gas_gauge(void);
 
 float get_voltage(void);
@@ -37,6 +39,7 @@
 void battery_gas_gauge_get_data(void);
 void battery_gas_gauge_set_charge_full(void);
 void battery_gas_gauge_set(float percentage);
+uint8_t battery_gas_gauge_CheckConfigOK(void);
 
 #ifdef __cplusplus
 }
--- a/Small_CPU/Src/batteryGasGauge.c	Wed Jul 17 22:42:55 2019 +0200
+++ b/Small_CPU/Src/batteryGasGauge.c	Wed Jul 17 22:43:16 2019 +0200
@@ -22,6 +22,7 @@
   ******************************************************************************
   */ 
 /* Includes ------------------------------------------------------------------*/
+#include <string.h>	/* memset */
 #include "batteryGasGauge.h"
 #include "baseCPU2.h"
 #include "stm32f4xx_hal.h"
@@ -71,6 +72,25 @@
 	I2C_Master_Transmit(DEVICE_BATTERYGAUGE, buffer, 2);
 }
 
+uint8_t battery_gas_gauge_CheckConfigOK(void)
+{
+	#ifdef OSTC_ON_DISCOVERY_HARDWARE
+		return;
+	#endif
+
+	uint8_t retval = 0;
+	uint8_t bufferReceive[10];
+
+	memset(bufferReceive,0,sizeof(bufferReceive));
+
+	I2C_Master_Receive(DEVICE_BATTERYGAUGE, bufferReceive, 10);
+	if(bufferReceive[1] == 0xf8)
+	{
+		retval = 1;
+	}
+	return retval;
+}
+
 static void disable_adc(void)
 {
 	uint8_t buffer[2];