annotate Small_CPU/Src/batteryGasGauge.c @ 558:66aef216828b

Changed operation mode of RecoverSampleIndex: In previous implementation the check was only done for the first 16 sector to be able to display status using a string. This may not be done by an OSTC companion function externally => changed function to handle all 192 sector used for log samples. The lastSampleIdx will now be stored immediatly (dive was necessary in previous version)
author Ideenmodellierer
date Thu, 12 Nov 2020 20:06:04 +0100
parents aa286a4926c2
children 1b995079c045
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3 * @file batteryGasGauge.c
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
4 * @author heinrichs weikamp gmbh
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
5 * @version V0.0.1
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
6 * @date 09-Dec-2014
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
7 * @brief LTC2942 Battery Gas Gauge
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
8 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
9 @verbatim
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
10 ==============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
11 ##### stm32f4xx_hal_i2c.c modification #####
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
12 ==============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
13 The LTC2942 requires an repeated start condition without stop condition
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
14 for data reception.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
15
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
16 @endverbatim
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
17 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
18 * @attention
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
19 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
20 * <h2><center>&copy; COPYRIGHT(c) 2014 heinrichs weikamp</center></h2>
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
21 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
22 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
23 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
24 /* Includes ------------------------------------------------------------------*/
330
2defc8cd93ce Added check of configuration.
ideenmodellierer
parents: 242
diff changeset
25 #include <string.h> /* memset */
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
26 #include "batteryGasGauge.h"
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
27 #include "baseCPU2.h"
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
28 #include "stm32f4xx_hal.h"
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
29 #include "i2c.h"
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
30
408
2fc08a0d1ec3 Bugfix invalid voltage / temperatur after coldstart:
ideenmodellierer
parents: 330
diff changeset
31 static float battery_f_voltage = 6.0; /* max assumed voltage */
228
f9ba924d188e Bugfix: set battery percentage correctly after RTE update
Jan Mulder <jlmulder@xs4all.nl>
parents: 38
diff changeset
32 static float battery_f_charge_percent = 0;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
33
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
34 #define BGG_BATTERY_OFFSET (26123) //; 65536-(3,35Ah/0,085mAh)
228
f9ba924d188e Bugfix: set battery percentage correctly after RTE update
Jan Mulder <jlmulder@xs4all.nl>
parents: 38
diff changeset
35 #define BGG_BATTERY_DIVIDER (394) //; 3,35Ah/0,085mAh/100 [%]
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
36
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
37 float get_voltage(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
38 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
39 #ifdef OSTC_ON_DISCOVERY_HARDWARE
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
40 return 3.0f;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
41 #endif
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
42
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
43 return battery_f_voltage;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
44 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
45
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
46
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
47 float get_charge(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
48 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
49 #ifdef OSTC_ON_DISCOVERY_HARDWARE
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
50 return 100.0f;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
51 #endif
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
52
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
53 return battery_f_charge_percent;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
54 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
55
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
56
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
57 void init_battery_gas_gauge(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
58 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
59 #ifdef OSTC_ON_DISCOVERY_HARDWARE
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
60 return;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
61 #endif
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
62
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
63 uint8_t buffer[2];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
64 buffer[0] = 0x01;
228
f9ba924d188e Bugfix: set battery percentage correctly after RTE update
Jan Mulder <jlmulder@xs4all.nl>
parents: 38
diff changeset
65
f9ba924d188e Bugfix: set battery percentage correctly after RTE update
Jan Mulder <jlmulder@xs4all.nl>
parents: 38
diff changeset
66 // F8 = 11111000:
433
aa286a4926c2 Detect startup after power off:
ideenmodellierer
parents: 408
diff changeset
67 // ADC auto mode (11)
228
f9ba924d188e Bugfix: set battery percentage correctly after RTE update
Jan Mulder <jlmulder@xs4all.nl>
parents: 38
diff changeset
68 // Prescale M = 128 (111)
f9ba924d188e Bugfix: set battery percentage correctly after RTE update
Jan Mulder <jlmulder@xs4all.nl>
parents: 38
diff changeset
69 // AL/CC pin disable (0)
f9ba924d188e Bugfix: set battery percentage correctly after RTE update
Jan Mulder <jlmulder@xs4all.nl>
parents: 38
diff changeset
70 // Shutdown (0)
f9ba924d188e Bugfix: set battery percentage correctly after RTE update
Jan Mulder <jlmulder@xs4all.nl>
parents: 38
diff changeset
71 buffer[1] = 0xF8;
f9ba924d188e Bugfix: set battery percentage correctly after RTE update
Jan Mulder <jlmulder@xs4all.nl>
parents: 38
diff changeset
72 I2C_Master_Transmit(DEVICE_BATTERYGAUGE, buffer, 2);
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
73 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
74
330
2defc8cd93ce Added check of configuration.
ideenmodellierer
parents: 242
diff changeset
75 uint8_t battery_gas_gauge_CheckConfigOK(void)
2defc8cd93ce Added check of configuration.
ideenmodellierer
parents: 242
diff changeset
76 {
2defc8cd93ce Added check of configuration.
ideenmodellierer
parents: 242
diff changeset
77 #ifdef OSTC_ON_DISCOVERY_HARDWARE
2defc8cd93ce Added check of configuration.
ideenmodellierer
parents: 242
diff changeset
78 return;
2defc8cd93ce Added check of configuration.
ideenmodellierer
parents: 242
diff changeset
79 #endif
2defc8cd93ce Added check of configuration.
ideenmodellierer
parents: 242
diff changeset
80
2defc8cd93ce Added check of configuration.
ideenmodellierer
parents: 242
diff changeset
81 uint8_t retval = 0;
2defc8cd93ce Added check of configuration.
ideenmodellierer
parents: 242
diff changeset
82 uint8_t bufferReceive[10];
2defc8cd93ce Added check of configuration.
ideenmodellierer
parents: 242
diff changeset
83
2defc8cd93ce Added check of configuration.
ideenmodellierer
parents: 242
diff changeset
84 memset(bufferReceive,0,sizeof(bufferReceive));
2defc8cd93ce Added check of configuration.
ideenmodellierer
parents: 242
diff changeset
85
2defc8cd93ce Added check of configuration.
ideenmodellierer
parents: 242
diff changeset
86 I2C_Master_Receive(DEVICE_BATTERYGAUGE, bufferReceive, 10);
2defc8cd93ce Added check of configuration.
ideenmodellierer
parents: 242
diff changeset
87 if(bufferReceive[1] == 0xf8)
2defc8cd93ce Added check of configuration.
ideenmodellierer
parents: 242
diff changeset
88 {
2defc8cd93ce Added check of configuration.
ideenmodellierer
parents: 242
diff changeset
89 retval = 1;
2defc8cd93ce Added check of configuration.
ideenmodellierer
parents: 242
diff changeset
90 }
2defc8cd93ce Added check of configuration.
ideenmodellierer
parents: 242
diff changeset
91 return retval;
2defc8cd93ce Added check of configuration.
ideenmodellierer
parents: 242
diff changeset
92 }
2defc8cd93ce Added check of configuration.
ideenmodellierer
parents: 242
diff changeset
93
242
b23de15e2861 Comply to datasheet when resetting battery gauge registers
Jan Mulder <jlmulder@xs4all.nl>
parents: 228
diff changeset
94 static void disable_adc(void)
b23de15e2861 Comply to datasheet when resetting battery gauge registers
Jan Mulder <jlmulder@xs4all.nl>
parents: 228
diff changeset
95 {
b23de15e2861 Comply to datasheet when resetting battery gauge registers
Jan Mulder <jlmulder@xs4all.nl>
parents: 228
diff changeset
96 uint8_t buffer[2];
b23de15e2861 Comply to datasheet when resetting battery gauge registers
Jan Mulder <jlmulder@xs4all.nl>
parents: 228
diff changeset
97 buffer[0] = 0x01;
b23de15e2861 Comply to datasheet when resetting battery gauge registers
Jan Mulder <jlmulder@xs4all.nl>
parents: 228
diff changeset
98
b23de15e2861 Comply to datasheet when resetting battery gauge registers
Jan Mulder <jlmulder@xs4all.nl>
parents: 228
diff changeset
99 // according to the datasheet of the LTC2942, the adc shall
b23de15e2861 Comply to datasheet when resetting battery gauge registers
Jan Mulder <jlmulder@xs4all.nl>
parents: 228
diff changeset
100 // be disabled when writing to the gauge registers
b23de15e2861 Comply to datasheet when resetting battery gauge registers
Jan Mulder <jlmulder@xs4all.nl>
parents: 228
diff changeset
101
b23de15e2861 Comply to datasheet when resetting battery gauge registers
Jan Mulder <jlmulder@xs4all.nl>
parents: 228
diff changeset
102 // 0xF9 = 11111001:
b23de15e2861 Comply to datasheet when resetting battery gauge registers
Jan Mulder <jlmulder@xs4all.nl>
parents: 228
diff changeset
103 // see init_battery_gas_gauge()
b23de15e2861 Comply to datasheet when resetting battery gauge registers
Jan Mulder <jlmulder@xs4all.nl>
parents: 228
diff changeset
104 // Shutdown (1)
b23de15e2861 Comply to datasheet when resetting battery gauge registers
Jan Mulder <jlmulder@xs4all.nl>
parents: 228
diff changeset
105 buffer[1] = 0xF9;
b23de15e2861 Comply to datasheet when resetting battery gauge registers
Jan Mulder <jlmulder@xs4all.nl>
parents: 228
diff changeset
106 I2C_Master_Transmit(DEVICE_BATTERYGAUGE, buffer, 2);
b23de15e2861 Comply to datasheet when resetting battery gauge registers
Jan Mulder <jlmulder@xs4all.nl>
parents: 228
diff changeset
107 }
b23de15e2861 Comply to datasheet when resetting battery gauge registers
Jan Mulder <jlmulder@xs4all.nl>
parents: 228
diff changeset
108
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
109
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
110 void battery_gas_gauge_get_data(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
111 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
112 #ifdef OSTC_ON_DISCOVERY_HARDWARE
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
113 return;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
114 #endif
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
115
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
116 float battery_f_voltage_local;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
117 float battery_f_charge_percent_local;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
118
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
119 uint8_t bufferReceive[10];
408
2fc08a0d1ec3 Bugfix invalid voltage / temperatur after coldstart:
ideenmodellierer
parents: 330
diff changeset
120
2fc08a0d1ec3 Bugfix invalid voltage / temperatur after coldstart:
ideenmodellierer
parents: 330
diff changeset
121 if(I2C_Master_Receive(DEVICE_BATTERYGAUGE, bufferReceive, 10) == HAL_OK)
2fc08a0d1ec3 Bugfix invalid voltage / temperatur after coldstart:
ideenmodellierer
parents: 330
diff changeset
122 {
2fc08a0d1ec3 Bugfix invalid voltage / temperatur after coldstart:
ideenmodellierer
parents: 330
diff changeset
123 battery_f_voltage_local = (float)(bufferReceive[8] * 256);
2fc08a0d1ec3 Bugfix invalid voltage / temperatur after coldstart:
ideenmodellierer
parents: 330
diff changeset
124 battery_f_voltage_local += (float)(bufferReceive[9]);
2fc08a0d1ec3 Bugfix invalid voltage / temperatur after coldstart:
ideenmodellierer
parents: 330
diff changeset
125 battery_f_voltage_local *= (float)6 / (float)0xFFFF;
2fc08a0d1ec3 Bugfix invalid voltage / temperatur after coldstart:
ideenmodellierer
parents: 330
diff changeset
126
2fc08a0d1ec3 Bugfix invalid voltage / temperatur after coldstart:
ideenmodellierer
parents: 330
diff changeset
127 // max/full: 0.085 mAh * 1 * 65535 = 5570 mAh
2fc08a0d1ec3 Bugfix invalid voltage / temperatur after coldstart:
ideenmodellierer
parents: 330
diff changeset
128 battery_f_charge_percent_local = (float)(bufferReceive[2] * 256);
2fc08a0d1ec3 Bugfix invalid voltage / temperatur after coldstart:
ideenmodellierer
parents: 330
diff changeset
129 battery_f_charge_percent_local += (float)(bufferReceive[3]);
433
aa286a4926c2 Detect startup after power off:
ideenmodellierer
parents: 408
diff changeset
130 battery_f_charge_percent_local -= BGG_BATTERY_OFFSET; /* Because of the prescalar 128 the counter assumes a max value of 5570mAh => normalize to 3350mAh*/
aa286a4926c2 Detect startup after power off:
ideenmodellierer
parents: 408
diff changeset
131 battery_f_charge_percent_local /= BGG_BATTERY_DIVIDER; /* transform to percentage */
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
132
408
2fc08a0d1ec3 Bugfix invalid voltage / temperatur after coldstart:
ideenmodellierer
parents: 330
diff changeset
133 if(battery_f_charge_percent_local < 0)
2fc08a0d1ec3 Bugfix invalid voltage / temperatur after coldstart:
ideenmodellierer
parents: 330
diff changeset
134 battery_f_charge_percent_local = 0;
2fc08a0d1ec3 Bugfix invalid voltage / temperatur after coldstart:
ideenmodellierer
parents: 330
diff changeset
135
2fc08a0d1ec3 Bugfix invalid voltage / temperatur after coldstart:
ideenmodellierer
parents: 330
diff changeset
136 battery_f_voltage = battery_f_voltage_local;
2fc08a0d1ec3 Bugfix invalid voltage / temperatur after coldstart:
ideenmodellierer
parents: 330
diff changeset
137 battery_f_charge_percent = battery_f_charge_percent_local;
2fc08a0d1ec3 Bugfix invalid voltage / temperatur after coldstart:
ideenmodellierer
parents: 330
diff changeset
138 }
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
139 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
140
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
141
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
142 void battery_gas_gauge_set_charge_full(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
143 {
242
b23de15e2861 Comply to datasheet when resetting battery gauge registers
Jan Mulder <jlmulder@xs4all.nl>
parents: 228
diff changeset
144 disable_adc();
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
145 #ifdef OSTC_ON_DISCOVERY_HARDWARE
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
146 return;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
147 #endif
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
148
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
149 uint8_t bufferSend[3];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
150 bufferSend[0] = 0x02;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
151 bufferSend[1] = 0xFF;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
152 bufferSend[2] = 0xFF;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
153 I2C_Master_Transmit( DEVICE_BATTERYGAUGE, bufferSend, 3);
242
b23de15e2861 Comply to datasheet when resetting battery gauge registers
Jan Mulder <jlmulder@xs4all.nl>
parents: 228
diff changeset
154 init_battery_gas_gauge();
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
155 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
156
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
157
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
158 void battery_gas_gauge_set(float percentage)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
159 {
242
b23de15e2861 Comply to datasheet when resetting battery gauge registers
Jan Mulder <jlmulder@xs4all.nl>
parents: 228
diff changeset
160
b23de15e2861 Comply to datasheet when resetting battery gauge registers
Jan Mulder <jlmulder@xs4all.nl>
parents: 228
diff changeset
161 disable_adc();
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
162 #ifdef OSTC_ON_DISCOVERY_HARDWARE
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
163 return;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
164 #endif
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
165
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
166 uint16_t mAhSend;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
167
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
168 if(percentage >= 100)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
169 mAhSend = 0xFFFF;
228
f9ba924d188e Bugfix: set battery percentage correctly after RTE update
Jan Mulder <jlmulder@xs4all.nl>
parents: 38
diff changeset
170 else {
f9ba924d188e Bugfix: set battery percentage correctly after RTE update
Jan Mulder <jlmulder@xs4all.nl>
parents: 38
diff changeset
171 mAhSend = (percentage * BGG_BATTERY_DIVIDER) + BGG_BATTERY_OFFSET;
f9ba924d188e Bugfix: set battery percentage correctly after RTE update
Jan Mulder <jlmulder@xs4all.nl>
parents: 38
diff changeset
172 }
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
173
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
174 uint8_t bufferSend[3];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
175 bufferSend[0] = 0x02;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
176 bufferSend[1] = (uint8_t)(mAhSend / 256);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
177 bufferSend[2] = (uint8_t)(mAhSend & 0xFF);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
178 I2C_Master_Transmit( DEVICE_BATTERYGAUGE, bufferSend, 3);
242
b23de15e2861 Comply to datasheet when resetting battery gauge registers
Jan Mulder <jlmulder@xs4all.nl>
parents: 228
diff changeset
179 init_battery_gas_gauge();
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
180 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
181
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
182
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
183 /************************ (C) COPYRIGHT heinrichs weikamp *****END OF FILE****/