comparison Small_CPU/Src/batteryGasGauge.c @ 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 f9ba924d188e
children 2defc8cd93ce
comparison
equal deleted inserted replaced
241:2b9775f71e30 242:b23de15e2861
69 // Shutdown (0) 69 // Shutdown (0)
70 buffer[1] = 0xF8; 70 buffer[1] = 0xF8;
71 I2C_Master_Transmit(DEVICE_BATTERYGAUGE, buffer, 2); 71 I2C_Master_Transmit(DEVICE_BATTERYGAUGE, buffer, 2);
72 } 72 }
73 73
74 static void disable_adc(void)
75 {
76 uint8_t buffer[2];
77 buffer[0] = 0x01;
78
79 // according to the datasheet of the LTC2942, the adc shall
80 // be disabled when writing to the gauge registers
81
82 // 0xF9 = 11111001:
83 // see init_battery_gas_gauge()
84 // Shutdown (1)
85 buffer[1] = 0xF9;
86 I2C_Master_Transmit(DEVICE_BATTERYGAUGE, buffer, 2);
87 }
88
74 89
75 void battery_gas_gauge_get_data(void) 90 void battery_gas_gauge_get_data(void)
76 { 91 {
77 #ifdef OSTC_ON_DISCOVERY_HARDWARE 92 #ifdef OSTC_ON_DISCOVERY_HARDWARE
78 return; 93 return;
102 } 117 }
103 118
104 119
105 void battery_gas_gauge_set_charge_full(void) 120 void battery_gas_gauge_set_charge_full(void)
106 { 121 {
122 disable_adc();
107 #ifdef OSTC_ON_DISCOVERY_HARDWARE 123 #ifdef OSTC_ON_DISCOVERY_HARDWARE
108 return; 124 return;
109 #endif 125 #endif
110 126
111 uint8_t bufferSend[3]; 127 uint8_t bufferSend[3];
112 bufferSend[0] = 0x02; 128 bufferSend[0] = 0x02;
113 bufferSend[1] = 0xFF; 129 bufferSend[1] = 0xFF;
114 bufferSend[2] = 0xFF; 130 bufferSend[2] = 0xFF;
115 I2C_Master_Transmit( DEVICE_BATTERYGAUGE, bufferSend, 3); 131 I2C_Master_Transmit( DEVICE_BATTERYGAUGE, bufferSend, 3);
132 init_battery_gas_gauge();
116 } 133 }
117 134
118 135
119 void battery_gas_gauge_set(float percentage) 136 void battery_gas_gauge_set(float percentage)
120 { 137 {
138
139 disable_adc();
121 #ifdef OSTC_ON_DISCOVERY_HARDWARE 140 #ifdef OSTC_ON_DISCOVERY_HARDWARE
122 return; 141 return;
123 #endif 142 #endif
124 143
125 uint16_t mAhSend; 144 uint16_t mAhSend;
133 uint8_t bufferSend[3]; 152 uint8_t bufferSend[3];
134 bufferSend[0] = 0x02; 153 bufferSend[0] = 0x02;
135 bufferSend[1] = (uint8_t)(mAhSend / 256); 154 bufferSend[1] = (uint8_t)(mAhSend / 256);
136 bufferSend[2] = (uint8_t)(mAhSend & 0xFF); 155 bufferSend[2] = (uint8_t)(mAhSend & 0xFF);
137 I2C_Master_Transmit( DEVICE_BATTERYGAUGE, bufferSend, 3); 156 I2C_Master_Transmit( DEVICE_BATTERYGAUGE, bufferSend, 3);
157 init_battery_gas_gauge();
138 } 158 }
139 159
140 160
141 /************************ (C) COPYRIGHT heinrichs weikamp *****END OF FILE****/ 161 /************************ (C) COPYRIGHT heinrichs weikamp *****END OF FILE****/