|
|
@@ -180,13 +180,13 @@ void controller_EvaluateBatterySlotState(uint8_t slot_id, BatteryMeasurement *me
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-bool getBatteryMeasurement_test(){
|
|
|
+/*bool getBatteryMeasurement_test(){
|
|
|
|
|
|
//DL_I2C_flushControllerTXFIFO(I2C_1_INST);
|
|
|
//Enable the interrupt:
|
|
|
DL_I2C_enableInterrupt(I2C_1_INST, DL_I2C_INTERRUPT_CONTROLLER_TXFIFO_TRIGGER);
|
|
|
|
|
|
- /* Wait for I2C to be Idle */
|
|
|
+ //Wait for I2C to be Idle
|
|
|
uint32_t timeout = 10000;
|
|
|
while (!(DL_I2C_getControllerStatus(I2C_1_INST) & DL_I2C_CONTROLLER_STATUS_IDLE) && timeout--);
|
|
|
if(timeout == 0){
|
|
|
@@ -195,9 +195,9 @@ bool getBatteryMeasurement_test(){
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
- /* Send the packet to the controller.
|
|
|
- * This function will send Start + Stop automatically.
|
|
|
- */
|
|
|
+ //Send the packet to the controller.
|
|
|
+ //This function will send Start + Stop automatically.
|
|
|
+
|
|
|
DL_I2C_startControllerTransferAdvanced(I2C_1_INST,
|
|
|
0x49,
|
|
|
DL_I2C_CONTROLLER_DIRECTION_TX,
|
|
|
@@ -207,28 +207,96 @@ bool getBatteryMeasurement_test(){
|
|
|
DL_I2C_CONTROLLER_ACK_ENABLE);
|
|
|
|
|
|
printf("[I2C] TX Packet Sent:: 0x%02X\n", txPacket.txBuffer[0]);
|
|
|
-
|
|
|
- /* Poll until the Controller writes all bytes */
|
|
|
- //while (!(DL_I2C_getControllerStatus(I2C_1_INST) &
|
|
|
- // DL_I2C_CONTROLLER_STATUS_IDLE));
|
|
|
- while (DL_I2C_getControllerStatus(I2C_1_INST) & DL_I2C_CONTROLLER_STATUS_BUSY);
|
|
|
+
|
|
|
+ while (DL_I2C_getControllerStatus(I2C_1_INST) & DL_I2C_CONTROLLER_STATUS_BUSY)
|
|
|
+ ;
|
|
|
|
|
|
- /* Add delay between transfers */
|
|
|
+ // Add delay between transfers
|
|
|
//delay_cycles(320000);
|
|
|
rxPacket.rxCount= 0;
|
|
|
rxPacket.rxLen= 8;
|
|
|
|
|
|
DL_I2C_flushControllerRXFIFO(I2C_1_INST);
|
|
|
- /* Send a read request to Target */
|
|
|
+
|
|
|
+ DL_I2C_enableInterrupt(I2C_1_INST, DL_I2C_INTERRUPT_CONTROLLER_RXFIFO_TRIGGER);
|
|
|
+
|
|
|
+ // Send a read request to Targe
|
|
|
DL_I2C_startControllerTransferAdvanced(I2C_1_INST, 0x49, DL_I2C_CONTROLLER_DIRECTION_RX, 8, DL_I2C_CONTROLLER_START_ENABLE,
|
|
|
DL_I2C_CONTROLLER_STOP_ENABLE,
|
|
|
DL_I2C_CONTROLLER_ACK_ENABLE);
|
|
|
|
|
|
while (DL_I2C_getControllerStatus(I2C_1_INST) & DL_I2C_CONTROLLER_STATUS_BUSY);
|
|
|
+
|
|
|
|
|
|
- DL_I2C_enableInterrupt(I2C_1_INST, DL_I2C_INTERRUPT_CONTROLLER_RXFIFO_TRIGGER);
|
|
|
|
|
|
printf("Received Bytes[%d]: 0x%02X\n", rxPacket.rxCount, rxPacket.rxBuffer[rxPacket.rxCount]);
|
|
|
|
|
|
+ return true;
|
|
|
+}*/
|
|
|
+
|
|
|
+// Following code worked with ADC as the target with now clocking issues:
|
|
|
+bool getBatteryMeasurement_test(){
|
|
|
+
|
|
|
+ //Enable the interrupt:
|
|
|
+ DL_I2C_enableInterrupt(I2C_INST, DL_I2C_INTERRUPT_CONTROLLER_TXFIFO_TRIGGER);
|
|
|
+ txPacket.txComplete= false;
|
|
|
+ /* Wait for I2C to be Idle */
|
|
|
+ uint32_t timeout = 10000;
|
|
|
+ while (!(DL_I2C_getControllerStatus(I2C_INST) & DL_I2C_CONTROLLER_STATUS_IDLE) && timeout--);
|
|
|
+ if(timeout == 0){
|
|
|
+ printf("Error in reading from I2C Bus: Bus is not getting ready before transmit start\n");
|
|
|
+ DL_I2C_resetControllerTransfer(I2C_INST);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ /* Send the packet to the controller.
|
|
|
+ * This function will send Start + Stop automatically.
|
|
|
+ */
|
|
|
+ DL_I2C_startControllerTransferAdvanced(I2C_INST,
|
|
|
+ 0x49,
|
|
|
+ DL_I2C_CONTROLLER_DIRECTION_TX,
|
|
|
+ 1,
|
|
|
+ DL_I2C_CONTROLLER_START_ENABLE,
|
|
|
+ DL_I2C_CONTROLLER_STOP_ENABLE,
|
|
|
+ DL_I2C_CONTROLLER_ACK_ENABLE);
|
|
|
+
|
|
|
+ printf("[I2C] TX Packet Sent:: 0x%02X\n", txPacket.txBuffer[0]);
|
|
|
+
|
|
|
+ /* Poll until the Controller writes all bytes */
|
|
|
+ timeout= 32000;
|
|
|
+ while(!(txPacket.txComplete) && timeout--);
|
|
|
+ if(timeout == 0){
|
|
|
+ printf("Tx Transmit not completed.\n");
|
|
|
+ DL_I2C_resetControllerTransfer(I2C_INST);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ /* Add delay between transfers */
|
|
|
+ //delay_cycles(32000);
|
|
|
+ rxPacket.rxCount= 0;
|
|
|
+ rxPacket.rxLen= 8;
|
|
|
+ rxPacket.rxComplete= false;
|
|
|
+ timeout= 32000;
|
|
|
+
|
|
|
+ DL_I2C_flushControllerRXFIFO(I2C_INST);
|
|
|
+
|
|
|
+ DL_I2C_enableInterrupt(I2C_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);
|
|
|
+
|
|
|
+ /* Send a read request to Target */
|
|
|
+ DL_I2C_startControllerTransferAdvanced(I2C_INST, 0x49, DL_I2C_CONTROLLER_DIRECTION_RX, 8, DL_I2C_CONTROLLER_START_ENABLE,
|
|
|
+ DL_I2C_CONTROLLER_STOP_ENABLE,
|
|
|
+ DL_I2C_CONTROLLER_ACK_ENABLE);
|
|
|
+
|
|
|
+ while (DL_I2C_getControllerStatus(I2C_INST) & DL_I2C_CONTROLLER_STATUS_BUSY)
|
|
|
+ ;
|
|
|
+
|
|
|
+
|
|
|
return true;
|
|
|
}
|