|
@@ -95,7 +95,7 @@ bool getBatteryMeasurement(uint8_t slot_id){
|
|
|
//Dynamic addressing:
|
|
//Dynamic addressing:
|
|
|
|
|
|
|
|
uint8_t target_address= TARGET_BASE_ADDRESS + ((slot_id & 0b00000100) >> 2);
|
|
uint8_t target_address= TARGET_BASE_ADDRESS + ((slot_id & 0b00000100) >> 2);
|
|
|
- printf("Target Address 0x%02X \n", target_address);
|
|
|
|
|
|
|
+ //printf("Target Address 0x%02X \n", target_address);
|
|
|
|
|
|
|
|
//Enable the Interrupt:
|
|
//Enable the Interrupt:
|
|
|
DL_I2C_enableInterrupt(I2C_1_INST, DL_I2C_INTERRUPT_CONTROLLER_TXFIFO_TRIGGER);
|
|
DL_I2C_enableInterrupt(I2C_1_INST, DL_I2C_INTERRUPT_CONTROLLER_TXFIFO_TRIGGER);
|
|
@@ -146,17 +146,15 @@ bool getBatteryMeasurement(uint8_t slot_id){
|
|
|
rxPacket.rxCount= 0;
|
|
rxPacket.rxCount= 0;
|
|
|
rxPacket.rxLen= 8;
|
|
rxPacket.rxLen= 8;
|
|
|
rxPacket.rxComplete= false;
|
|
rxPacket.rxComplete= false;
|
|
|
- timeout= 32000;
|
|
|
|
|
|
|
+ timeout= 3200000;
|
|
|
|
|
|
|
|
//Make RX Buffer ready to receive the data
|
|
//Make RX Buffer ready to receive the data
|
|
|
- DL_I2C_flushControllerRXFIFO(I2C_1_INST);
|
|
|
|
|
|
|
+ //DL_I2C_flushControllerRXFIFO(I2C_1_INST);
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ while (DL_I2C_getControllerStatus(I2C_1_INST) & DL_I2C_CONTROLLER_STATUS_BUSY)
|
|
|
|
|
+ ;
|
|
|
|
|
|
|
|
- DL_I2C_enableInterrupt(I2C_1_INST, DL_I2C_INTERRUPT_CONTROLLER_RXFIFO_TRIGGER);
|
|
|
|
|
-
|
|
|
|
|
- while(!(rxPacket.rxComplete) && timeout--);
|
|
|
|
|
- if(timeout==0){
|
|
|
|
|
- printf("Rx transmit not completed");
|
|
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
//while (DL_I2C_getControllerStatus(I2C_INST) & DL_I2C_CONTROLLER_STATUS_BUSY_BUS);
|
|
//while (DL_I2C_getControllerStatus(I2C_INST) & DL_I2C_CONTROLLER_STATUS_BUSY_BUS);
|
|
|
|
|
|
|
@@ -165,24 +163,26 @@ bool getBatteryMeasurement(uint8_t slot_id){
|
|
|
DL_I2C_CONTROLLER_STOP_ENABLE,
|
|
DL_I2C_CONTROLLER_STOP_ENABLE,
|
|
|
DL_I2C_CONTROLLER_ACK_ENABLE);
|
|
DL_I2C_CONTROLLER_ACK_ENABLE);
|
|
|
|
|
|
|
|
- while (DL_I2C_getControllerStatus(I2C_1_INST) & DL_I2C_CONTROLLER_STATUS_BUSY)
|
|
|
|
|
- ;
|
|
|
|
|
|
|
+ while(rxPacket.rxCount < 8 && timeout--);
|
|
|
|
|
+ if(timeout==0){
|
|
|
|
|
+ printf("Rx transmit not completed");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ DL_I2C_enableInterrupt(I2C_1_INST, DL_I2C_INTERRUPT_CONTROLLER_RXFIFO_TRIGGER);
|
|
|
|
|
|
|
|
measurement.voltage= rxPacket.rxBuffer[0] | (rxPacket.rxBuffer[1] << 8);
|
|
measurement.voltage= rxPacket.rxBuffer[0] | (rxPacket.rxBuffer[1] << 8);
|
|
|
measurement.current= rxPacket.rxBuffer[2]|(rxPacket.rxBuffer[3] << 8);
|
|
measurement.current= rxPacket.rxBuffer[2]|(rxPacket.rxBuffer[3] << 8);
|
|
|
measurement.temperature = rxPacket.rxBuffer[4] | (rxPacket.rxBuffer[5] << 8);
|
|
measurement.temperature = rxPacket.rxBuffer[4] | (rxPacket.rxBuffer[5] << 8);
|
|
|
measurement.slot_state = (SlotState)(rxPacket.rxBuffer[6]);
|
|
measurement.slot_state = (SlotState)(rxPacket.rxBuffer[6]);
|
|
|
-
|
|
|
|
|
|
|
+ DL_I2C_flushControllerRXFIFO(I2C_1_INST);
|
|
|
//Storing the measurements in Battery structure:
|
|
//Storing the measurements in Battery structure:
|
|
|
battery_data[slot_id].battery_measurement= measurement;
|
|
battery_data[slot_id].battery_measurement= measurement;
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
//DEBUG
|
|
//DEBUG
|
|
|
//printf("[I2C] Successfully read %d bytes from target 0x%02X\n", rxPacket.rxCount, TARGET_BASE_ADDRESS);
|
|
//printf("[I2C] Successfully read %d bytes from target 0x%02X\n", rxPacket.rxCount, TARGET_BASE_ADDRESS);
|
|
|
printf("Voltage: %u\n", battery_data[slot_id].battery_measurement.voltage);
|
|
printf("Voltage: %u\n", battery_data[slot_id].battery_measurement.voltage);
|
|
|
printf("Current: %u\n", battery_data[slot_id].battery_measurement.current);
|
|
printf("Current: %u\n", battery_data[slot_id].battery_measurement.current);
|
|
|
printf("Temp: %u\n",battery_data[slot_id].battery_measurement.temperature);
|
|
printf("Temp: %u\n",battery_data[slot_id].battery_measurement.temperature);
|
|
|
printf("Slot state: %u\n",battery_data[slot_id].battery_measurement.slot_state);
|
|
printf("Slot state: %u\n",battery_data[slot_id].battery_measurement.slot_state);
|
|
|
-
|
|
|
|
|
- DL_I2C_flushControllerRXFIFO(I2C_1_INST);
|
|
|
|
|
return true;
|
|
return true;
|
|
|
}
|
|
}
|