comparison 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
comparison
equal deleted inserted replaced
329:da5b91b1e20e 330:2defc8cd93ce
20 * <h2><center>&copy; COPYRIGHT(c) 2014 heinrichs weikamp</center></h2> 20 * <h2><center>&copy; COPYRIGHT(c) 2014 heinrichs weikamp</center></h2>
21 * 21 *
22 ****************************************************************************** 22 ******************************************************************************
23 */ 23 */
24 /* Includes ------------------------------------------------------------------*/ 24 /* Includes ------------------------------------------------------------------*/
25 #include <string.h> /* memset */
25 #include "batteryGasGauge.h" 26 #include "batteryGasGauge.h"
26 #include "baseCPU2.h" 27 #include "baseCPU2.h"
27 #include "stm32f4xx_hal.h" 28 #include "stm32f4xx_hal.h"
28 #include "i2c.h" 29 #include "i2c.h"
29 30
67 // Prescale M = 128 (111) 68 // Prescale M = 128 (111)
68 // AL/CC pin disable (0) 69 // AL/CC pin disable (0)
69 // Shutdown (0) 70 // Shutdown (0)
70 buffer[1] = 0xF8; 71 buffer[1] = 0xF8;
71 I2C_Master_Transmit(DEVICE_BATTERYGAUGE, buffer, 2); 72 I2C_Master_Transmit(DEVICE_BATTERYGAUGE, buffer, 2);
73 }
74
75 uint8_t battery_gas_gauge_CheckConfigOK(void)
76 {
77 #ifdef OSTC_ON_DISCOVERY_HARDWARE
78 return;
79 #endif
80
81 uint8_t retval = 0;
82 uint8_t bufferReceive[10];
83
84 memset(bufferReceive,0,sizeof(bufferReceive));
85
86 I2C_Master_Receive(DEVICE_BATTERYGAUGE, bufferReceive, 10);
87 if(bufferReceive[1] == 0xf8)
88 {
89 retval = 1;
90 }
91 return retval;
72 } 92 }
73 93
74 static void disable_adc(void) 94 static void disable_adc(void)
75 { 95 {
76 uint8_t buffer[2]; 96 uint8_t buffer[2];