diff Small_CPU/Src/batteryGasGauge.c @ 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 b23de15e2861
children 2fc08a0d1ec3
line wrap: on
line diff
--- 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];