Bladeren bron

dynamic addressing tested only for Slot 0 for Set Current

namrota ghosh 7 maanden geleden
bovenliggende
commit
b5a90c4cc0
3 gewijzigde bestanden met toevoegingen van 8 en 8 verwijderingen
  1. 5 5
      src/cc_cv_charging.c
  2. 2 2
      src/controller/controller.c
  3. 1 1
      src/controller/controller.h

+ 5 - 5
src/cc_cv_charging.c

@@ -159,7 +159,7 @@ void CC_CV_ControlCharging(uint8_t slot_id, int16_t charge_current) {
     case STATE_PRE_CHARGE:
 
       DL_GPIO_setPins(GPIO_Battery_Charging_PORT, GPIO_Battery_Charging_PIN_PB7_PIN);
-      controller_SetCurrent(TARGET_BASE_ADDRESS, slot_id, charge_current);
+      controller_SetCurrent(slot_id, charge_current);
       if (true) {
         printf("PRE CHARGING: Slot %d at %d mA.\n", slot_id, charge_current);
       }
@@ -169,7 +169,7 @@ void CC_CV_ControlCharging(uint8_t slot_id, int16_t charge_current) {
     // reaches to (MAXIMUM_VOLTAGE-BATTERY_THRESHOLD)= 4150 mVolts
     case STATE_CC_CHARGING:
       DL_GPIO_setPins(GPIO_Battery_Charging_PORT, GPIO_Battery_Charging_PIN_PB7_PIN);
-      controller_SetCurrent(TARGET_BASE_ADDRESS, slot_id, charge_current);
+      controller_SetCurrent(slot_id, charge_current);
       printf("CC CHARGING: Slot %d, Current: %d mA, Voltage: %d mV.\n", slot_id, batt_current, batt_voltage);
       break;
   
@@ -184,7 +184,7 @@ void CC_CV_ControlCharging(uint8_t slot_id, int16_t charge_current) {
           charging_state= STATE_ERROR;
           break;
         }
-        controller_SetCurrent(TARGET_BASE_ADDRESS, slot_id, charge_current);
+        controller_SetCurrent(slot_id, charge_current);
       }else {
         charging_state = STATE_FINAL_DISCHARGE;
         dac_initialized= false;
@@ -196,7 +196,7 @@ void CC_CV_ControlCharging(uint8_t slot_id, int16_t charge_current) {
       DL_GPIO_setPins(GPIO_Battery_Charging_PORT, GPIO_Battery_Charging_PIN_PB7_PIN);
       DL_GPIO_setPins(GPIO_Battery_Discharging_PORT, GPIO_Battery_Discharging_PIN_PB6_PIN);
       //controller_EvaluateBatterySlotState(slot_id, BatteryMeasurement *measurement);
-      controller_SetCurrent(TARGET_BASE_ADDRESS, slot_id, charge_current);
+      controller_SetCurrent(slot_id, charge_current);
       printf("DISCHARGING: Slot %d at %d mA.\n", slot_id, batt_current);
 
       //Safety Check
@@ -211,7 +211,7 @@ void CC_CV_ControlCharging(uint8_t slot_id, int16_t charge_current) {
       battery_data[slot_id].battery_state= STATE_MEASUREMENT_DONE;
       DL_GPIO_clearPins(GPIO_Battery_Charging_PORT, GPIO_Battery_Charging_PIN_PB7_PIN);
       DL_GPIO_clearPins(GPIO_Battery_Discharging_PORT, GPIO_Battery_Discharging_PIN_PB6_PIN);
-      controller_SetCurrent(TARGET_BASE_ADDRESS, slot_id, 0);
+      controller_SetCurrent(slot_id, 0);
       charging_state = STATE_IDLE;
       break;
   

+ 2 - 2
src/controller/controller.c

@@ -12,7 +12,7 @@
 Format: command + ((slot_id) + data (optional))
 */
 //Send command to set charge and discharge current to the target
-void controller_SetCurrent(uint8_t const TARGET_ADDRESS, uint8_t slot_id, int16_t current_mA){
+void controller_SetCurrent(uint8_t slot_id, int16_t current_mA){
     
     uint8_t target_address= TARGET_BASE_ADDRESS + ((slot_id & 0b00000100) >> 2);
     printf("Target Address 0x%02X \n", target_address);
@@ -36,7 +36,7 @@ void controller_SetCurrent(uint8_t const TARGET_ADDRESS, uint8_t slot_id, int16_
     // Add delays
     delay_cycles(1000);
     //start the transfer
-    DL_I2C_startControllerTransfer(I2C_1_INST, TARGET_ADDRESS, DL_I2C_CONTROLLER_DIRECTION_TX, 3);
+    DL_I2C_startControllerTransfer(I2C_1_INST, target_address, DL_I2C_CONTROLLER_DIRECTION_TX, 3);
     
     timeout= 32000;
     while((DL_I2C_getControllerStatus(I2C_1_INST) & DL_I2C_CONTROLLER_STATUS_BUSY) && timeout--);

+ 1 - 1
src/controller/controller.h

@@ -18,7 +18,7 @@ typedef enum{
 }mcu_I2C_command;
 
 uint8_t detect_target_address();
-void controller_SetCurrent(uint8_t const TARGET_ADDRESS, uint8_t slot_id, int16_t current_mA);
+void controller_SetCurrent(uint8_t slot_id, int16_t current_mA);
 void controller_EvaluateBatterySlotState(uint8_t slot_id, BatteryMeasurement *measurement);
 bool getBatteryMeasurement(uint8_t slot_id);
 #endif