|
@@ -124,9 +124,13 @@ static bool adc_configure(uint8_t slot_id, ADC_Params *params) {
|
|
|
printf("Config Byte: 0x%02X\n", controllerTxPackage.packet[0]);
|
|
printf("Config Byte: 0x%02X\n", controllerTxPackage.packet[0]);
|
|
|
#endif
|
|
#endif
|
|
|
// Wait for I2C Bus to be Free**
|
|
// Wait for I2C Bus to be Free**
|
|
|
- while (DL_I2C_getControllerStatus(I2C_controller_INST) &
|
|
|
|
|
- DL_I2C_CONTROLLER_STATUS_BUSY_BUS)
|
|
|
|
|
|
|
+ uint32_t n_cycles = 0;
|
|
|
|
|
+ while ((DL_I2C_getControllerStatus(I2C_controller_INST) &
|
|
|
|
|
+ DL_I2C_CONTROLLER_STATUS_BUSY_BUS) && n_cycles++ < MAX_I2C_WAIT_RX)
|
|
|
;
|
|
;
|
|
|
|
|
+ if (n_cycles == MAX_I2C_WAIT_RX) {
|
|
|
|
|
+ printf("Error in reading from I2C Bus: Bus is not getting ready on config byte\n");
|
|
|
|
|
+ }
|
|
|
if(controllerTxPackage.packet[0] == 0xFF){
|
|
if(controllerTxPackage.packet[0] == 0xFF){
|
|
|
// this clause can only happen if the internal memory management is messed up?!
|
|
// this clause can only happen if the internal memory management is messed up?!
|
|
|
// the config function should take care that this is never the case
|
|
// the config function should take care that this is never the case
|
|
@@ -140,9 +144,9 @@ static bool adc_configure(uint8_t slot_id, ADC_Params *params) {
|
|
|
controllerTxPackage.len = 1;
|
|
controllerTxPackage.len = 1;
|
|
|
controllerTxPackage.count = 0;
|
|
controllerTxPackage.count = 0;
|
|
|
controllerTxPackage.complete = false;
|
|
controllerTxPackage.complete = false;
|
|
|
- i2c_hal.write(ADC_TARGET_BASE_ADDRESS);
|
|
|
|
|
|
|
+ i2c_hal.write(battery_slots[slot_id].adc_addr);
|
|
|
|
|
|
|
|
- uint32_t n_cycles = 0;
|
|
|
|
|
|
|
+ n_cycles = 0;
|
|
|
while(!controllerTxPackage.complete && n_cycles++ < MAX_I2C_WAIT_RX);
|
|
while(!controllerTxPackage.complete && n_cycles++ < MAX_I2C_WAIT_RX);
|
|
|
if (n_cycles == MAX_I2C_WAIT_RX) {
|
|
if (n_cycles == MAX_I2C_WAIT_RX) {
|
|
|
#ifdef DEBUG_ADC
|
|
#ifdef DEBUG_ADC
|
|
@@ -166,7 +170,7 @@ Conversion mode, writing this bit to “1” initiates a new conversion.
|
|
|
*/
|
|
*/
|
|
|
|
|
|
|
|
static bool adc_is_ready(uint8_t slot_id, ADC_Params *params) {
|
|
static bool adc_is_ready(uint8_t slot_id, ADC_Params *params) {
|
|
|
- uint8_t adc_address = ADC_TARGET_BASE_ADDRESS + slot_id;
|
|
|
|
|
|
|
+ uint8_t adc_address = battery_slots[slot_id].adc_addr;
|
|
|
controllerRxPackage.len = 3;
|
|
controllerRxPackage.len = 3;
|
|
|
controllerRxPackage.count = 0;
|
|
controllerRxPackage.count = 0;
|
|
|
controllerRxPackage.complete = false;
|
|
controllerRxPackage.complete = false;
|
|
@@ -194,8 +198,15 @@ static int16_t read_adc_raw_data(uint8_t slot_id, ADC_Params *params) {
|
|
|
controllerRxPackage.count = 0;
|
|
controllerRxPackage.count = 0;
|
|
|
controllerRxPackage.complete = false;
|
|
controllerRxPackage.complete = false;
|
|
|
|
|
|
|
|
- i2c_hal.read(ADC_TARGET_BASE_ADDRESS + slot_id);
|
|
|
|
|
- while(!controllerRxPackage.complete);
|
|
|
|
|
|
|
+ i2c_hal.read(battery_slots[slot_id].adc_addr);
|
|
|
|
|
+ uint32_t n_cycles = 0;
|
|
|
|
|
+ while(!controllerRxPackage.complete && n_cycles++ < MAX_I2C_WAIT_RX);
|
|
|
|
|
+ if (n_cycles == MAX_I2C_WAIT_RX) {
|
|
|
|
|
+#ifdef DEBUG_ADC
|
|
|
|
|
+ printf("[ADC] No Response to the ADC!\n");
|
|
|
|
|
+#endif
|
|
|
|
|
+ return 0xffff;
|
|
|
|
|
+ }
|
|
|
uint8_t msb = controllerRxPackage.packet[0];
|
|
uint8_t msb = controllerRxPackage.packet[0];
|
|
|
uint8_t lsb = controllerRxPackage.packet[1];
|
|
uint8_t lsb = controllerRxPackage.packet[1];
|
|
|
uint8_t config_adc_byte = controllerRxPackage.packet[2];
|
|
uint8_t config_adc_byte = controllerRxPackage.packet[2];
|