|
|
@@ -59,6 +59,7 @@ bool controller_GetBatteryMeasurement(uint8_t slot_id){
|
|
|
txPacket.txLen= 1;
|
|
|
txPacket.txCount= 0;
|
|
|
txPacket.txComplete= false;
|
|
|
+
|
|
|
DL_I2C_fillControllerTXFIFO(I2C_1_INST, &txPacket.txBuffer[0], txPacket.txLen);
|
|
|
|
|
|
// Wait for the bus to be idle
|
|
|
@@ -71,7 +72,7 @@ bool controller_GetBatteryMeasurement(uint8_t slot_id){
|
|
|
}
|
|
|
|
|
|
//Send command bytes to the target
|
|
|
-
|
|
|
+ DL_I2C_enableInterrupt(I2C_1_INST, DL_I2C_INTERRUPT_CONTROLLER_TXFIFO_TRIGGER);
|
|
|
DL_I2C_startControllerTransferAdvanced(I2C_1_INST, target_address, DL_I2C_CONTROLLER_DIRECTION_TX, txPacket.txLen, DL_I2C_CONTROLLER_START_ENABLE, DL_I2C_CONTROLLER_STOP_DISABLE, DL_I2C_CONTROLLER_ACK_ENABLE);
|
|
|
printf("[I2C] TX Packet Sent:: 0x%02X\n", txPacket.txBuffer[0]);
|
|
|
|
|
|
@@ -101,23 +102,23 @@ bool controller_GetBatteryMeasurement(uint8_t slot_id){
|
|
|
rxPacket.rxCount= 0;
|
|
|
rxPacket.rxComplete= false;
|
|
|
|
|
|
- DL_I2C_enableInterrupt(I2C_1_INST, DL_I2C_INTERRUPT_CONTROLLER_RXFIFO_TRIGGER);
|
|
|
+
|
|
|
//BatteryMeasurement size is 8 similar to the target side
|
|
|
+ DL_I2C_enableInterrupt(I2C_1_INST, DL_I2C_INTERRUPT_CONTROLLER_RXFIFO_TRIGGER);
|
|
|
//DL_I2C_startControllerTransferAdvanced(I2C_1_INST, TARGET_ADDRESS, DL_I2C_CONTROLLER_DIRECTION_RX, rxPacket.rxLen, DL_I2C_CONTROLLER_START_ENABLE, DL_I2C_CONTROLLER_STOP_ENABLE, DL_I2C_CONTROLLER_ACK_DISABLE);
|
|
|
DL_I2C_startControllerTransfer(I2C_1_INST, target_address, DL_I2C_CONTROLLER_DIRECTION_RX, rxPacket.rxLen);
|
|
|
|
|
|
-
|
|
|
while((DL_I2C_getControllerStatus(I2C_1_INST) & DL_I2C_CONTROLLER_STATUS_BUSY_BUS) && timeout--);
|
|
|
-
|
|
|
if(timeout == 0 || (DL_I2C_getSCLStatus(I2C_1_INST)== DL_I2C_CONTROLLER_SCL_LOW)){
|
|
|
printf("Bus stuck during Rx transmit or SCL held LOW.\n");
|
|
|
DL_I2C_resetControllerTransfer(I2C_1_INST);
|
|
|
return false;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
+ //while(DL_I2C_getControllerStatus(I2C_1_INST) & DL_I2C_CONTROLLER_STATUS_BUSY_BUS);
|
|
|
+
|
|
|
//DEBUG
|
|
|
- //printf("Rx Count: %d\n", rxPacket.rxCount);
|
|
|
- printf("Total Received Bytes out of total length of [0x%02X]: 0x%02X\n", rxPacket.rxLen, sizeof(rxPacket.rxBuffer[rxPacket.rxCount]));
|
|
|
+ printf("Rx Count: %d\n", rxPacket.rxCount);
|
|
|
printf("Rx Complete: %d\n", rxPacket.rxComplete);
|
|
|
//Check if all the data is received then store the battery limits in BatteryInfo struct:
|
|
|
if(rxPacket.rxCount== (sizeof(BatteryMeasurement))){
|