changeset 242:b23de15e2861 div-fixes-5

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 <jlmulder@xs4all.nl>
author Jan Mulder <jlmulder@xs4all.nl>
date Mon, 08 Apr 2019 12:02:07 +0200
parents 2b9775f71e30
children b7b481df4f22
files Small_CPU/Src/batteryGasGauge.c
diffstat 1 files changed, 20 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- 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();
 }