# HG changeset patch # User Jan Mulder # Date 1554717727 -7200 # Node ID b23de15e286191c8828272e827fd9e0a132fa946 # Parent 2b9775f71e30f7ffcd3cf0666bfdb899b1459e19 Comply to datasheet when resetting battery gauge registers According to the datasheet of the LTC2942, the adc shall be disabled when writing to the gauge registers. Simply provide a function for this and use it. And no, it does not seem to fix anything, but its simply better to follow the datasheet. Signed-off-by: Jan Mulder diff -r 2b9775f71e30 -r b23de15e2861 Small_CPU/Src/batteryGasGauge.c --- a/Small_CPU/Src/batteryGasGauge.c Mon Apr 08 11:18:40 2019 +0200 +++ b/Small_CPU/Src/batteryGasGauge.c Mon Apr 08 12:02:07 2019 +0200 @@ -71,6 +71,21 @@ I2C_Master_Transmit(DEVICE_BATTERYGAUGE, buffer, 2); } +static void disable_adc(void) +{ + uint8_t buffer[2]; + buffer[0] = 0x01; + + // according to the datasheet of the LTC2942, the adc shall + // be disabled when writing to the gauge registers + + // 0xF9 = 11111001: + // see init_battery_gas_gauge() + // Shutdown (1) + buffer[1] = 0xF9; + I2C_Master_Transmit(DEVICE_BATTERYGAUGE, buffer, 2); +} + void battery_gas_gauge_get_data(void) { @@ -104,6 +119,7 @@ void battery_gas_gauge_set_charge_full(void) { + disable_adc(); #ifdef OSTC_ON_DISCOVERY_HARDWARE return; #endif @@ -113,11 +129,14 @@ bufferSend[1] = 0xFF; bufferSend[2] = 0xFF; I2C_Master_Transmit( DEVICE_BATTERYGAUGE, bufferSend, 3); + init_battery_gas_gauge(); } void battery_gas_gauge_set(float percentage) { + + disable_adc(); #ifdef OSTC_ON_DISCOVERY_HARDWARE return; #endif @@ -135,6 +154,7 @@ bufferSend[1] = (uint8_t)(mAhSend / 256); bufferSend[2] = (uint8_t)(mAhSend & 0xFF); I2C_Master_Transmit( DEVICE_BATTERYGAUGE, bufferSend, 3); + init_battery_gas_gauge(); }