|
|
@@ -53,6 +53,7 @@ void pi_i2c_mcu(){
|
|
|
uint8_t receivedCommand= DL_I2C_receiveTargetData(I2C_0_INST);
|
|
|
//printf("Received Command: 0x%02X\n", receivedCommand);
|
|
|
if(receivedCommand == CMD_GET_BATTERY_STATUS){
|
|
|
+ //DL_I2C_flushTargetTXFIFO(I2C_0_INST);
|
|
|
//Example: i2cget -y 1 0x20 0x01 i 4
|
|
|
uint8_t status_buffer[NUM_SLOTS];
|
|
|
//GET battery state from battery.c file
|
|
|
@@ -60,16 +61,22 @@ void pi_i2c_mcu(){
|
|
|
status_buffer[slot] = battery_data[slot].battery_state;
|
|
|
}
|
|
|
DL_I2C_fillTargetTXFIFO(I2C_0_INST, status_buffer, NUM_SLOTS);
|
|
|
- while(DL_I2C_transmitTargetDataCheck(I2C_0_INST, 0x00)!= false);
|
|
|
+ uint32_t timeout= 32000;
|
|
|
+ while((DL_I2C_getTargetStatus(I2C_0_INST) & DL_I2C_TARGET_STATUS_BUS_BUSY) && timeout--);
|
|
|
+ if(timeout==0){
|
|
|
+ printf("Tx transmit not completed");
|
|
|
+ }
|
|
|
+ while(!(DL_I2C_isTargetTXFIFOEmpty(I2C_0_INST)));
|
|
|
+ //while(DL_I2C_transmitTargetDataCheck(I2C_0_INST, 0x00)!= false);
|
|
|
}
|
|
|
//bitmasked GET command:
|
|
|
else if((receivedCommand & 0x0F)== 0x02){
|
|
|
- //I2Ctools command: i2cget -y 1 0x20 0xn2 i 8
|
|
|
+ //I2Ctools command: cccccccccccccccccc
|
|
|
//Get Battery Measurement data for slot_id: Voltage, Current, Temperture, Cycle Number and Cycle State
|
|
|
// on two of the testings have received:
|
|
|
//0x00 0xff 0xff 0xff 0xff 0xff 0xff 0xff
|
|
|
//0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
|
|
|
-
|
|
|
+ DL_I2C_flushTargetTXFIFO(I2C_0_INST);
|
|
|
uint8_t requestedSlot = (receivedCommand & 0xF0)>>4;
|
|
|
//printf("Requested slot:%d\n", requestedSlot);
|
|
|
BatteryData battery_measure;
|
|
|
@@ -86,8 +93,14 @@ void pi_i2c_mcu(){
|
|
|
battery_measure.cycle_state= battery->battery_charging_state;
|
|
|
|
|
|
DL_I2C_fillTargetTXFIFO(I2C_0_INST, (uint8_t *)&battery_measure, sizeof(BatteryData));
|
|
|
- printf("Battery Measurement Sent. \n");
|
|
|
- DL_I2C_flushTargetTXFIFO(I2C_0_INST);
|
|
|
+ uint32_t timeout= 32000;
|
|
|
+ while((DL_I2C_getTargetStatus(I2C_0_INST) & DL_I2C_TARGET_STATUS_BUS_BUSY) && timeout--);
|
|
|
+ if(timeout==0){
|
|
|
+ printf("Tx transmit not completed");
|
|
|
+ }
|
|
|
+ //while(!(DL_I2C_isTargetTXFIFOEmpty(I2C_0_INST)));
|
|
|
+ //printf("Battery Measurement Sent. \n");
|
|
|
+ //DL_I2C_flushTargetTXFIFO(I2C_0_INST);
|
|
|
|
|
|
}
|
|
|
|