diff --git a/Core/Inc/segment.h b/Core/Inc/segment.h index c155915..7d29236 100644 --- a/Core/Inc/segment.h +++ b/Core/Inc/segment.h @@ -1,7 +1,6 @@ #ifndef SEGMENT_H #define SEGMENT_H -#include "ltc68041.h" #include "bmsConfig.h" #include "datastructs.h" @@ -24,16 +23,6 @@ void segment_retrieve_data(acc_data_t *bmsdata); */ void segment_disable_balancing(cell_asic chips[NUM_CHIPS]); -/** - * @brief Enables/disables balancing for a specific cell - * - * @param chip_num - * @param cell_num - * @param balance_enable - */ -void cell_enable_balancing(uint8_t chip_num, uint8_t cell_num, - bool balance_enable); - /** * @brief Set the cell balancing configuration and send it to the segments. * diff --git a/Core/Src/segment.c b/Core/Src/segment.c index 5aa692d..c899c17 100644 --- a/Core/Src/segment.c +++ b/Core/Src/segment.c @@ -614,7 +614,8 @@ void segment_retrieve_data(acc_data_t *bmsdata) bool segment_is_balancing(cell_asic chips[NUM_CHIPS]) { for (int chip = 0; chip < NUM_CHIPS; chip++) { - if (chips[chip].tx_cfga.mute_st != MUTE_ACTIVATED_DISCHARGE_DISABLED) { + if (chips[chip].tx_cfga.mute_st != + MUTE_ACTIVATED_DISCHARGE_DISABLED) { return true; } } @@ -625,6 +626,9 @@ void segment_disable_balancing(cell_asic chips[NUM_CHIPS]) { // Initializes all array elements to zero bool discharge_config[NUM_CHIPS][NUM_CELLS_PER_CHIP] = { 0 }; + for (int chip = 0; chip < NUM_CHIPS; chip++) { + chips[chip].tx_cfga.mute_st = MUTE_ACTIVATED_DISCHARGE_DISABLED; + } segment_configure_balancing(chips, discharge_config); } @@ -642,6 +646,13 @@ void segment_configure_balancing( for (int cell = 0; cell < NUM_CELLS_PER_CHIP; cell++) { set_cell_discharge(&chips[chip], cell, discharge_config[chip][cell]); + + // Enable balancing for a chip if a cell is to be discharged + if (chips[chip].tx_cfga.mute_st == + MUTE_ACTIVATED_DISCHARGE_DISABLED && + discharge_config[chip][cell]) { + chips[chip].tx_cfga.mute_st = DISCHARGE_ENABLED; + } } } write_config_regs(chips); diff --git a/Makefile b/Makefile index 25fba47..1cad36b 100644 --- a/Makefile +++ b/Makefile @@ -48,7 +48,6 @@ Core/Src/stm32f4xx_it.c \ Core/Src/stm32f4xx_hal_msp.c \ Drivers/Embedded-Base/platforms/stm32f405/src/can.c \ Drivers/Embedded-Base/general/src/m24c32.c \ -Drivers/Embedded-Base/general/src/ltc68041.c \ Drivers/Embedded-Base/general/src/sht30.c \ Drivers/Embedded-Base/middleware/src/timer.c \ Drivers/Embedded-Base/middleware/src/ringbuffer.c \