Fix BQ initialization

This commit is contained in:
jazzpi 2022-06-23 12:40:35 +02:00
parent 9f69121203
commit 8f0e661e18
4 changed files with 20 additions and 7 deletions

View File

@ -71,7 +71,7 @@ IncludeCategories:
- Regex: '^[<"]stm' - Regex: '^[<"]stm'
Priority: 2 Priority: 2
SortPriority: 0 SortPriority: 0
- Regex: "^<std" - Regex: "^<(std|string)"
Priority: 4 Priority: 4
SortPriority: 0 SortPriority: 0
- Regex: ".*" - Regex: ".*"

View File

@ -61,6 +61,7 @@ void afe_update_Checksum();
void afe_config_measurement_channels(); void afe_config_measurement_channels();
void afe_config_communication(); void afe_config_communication();
void afe_config_power();
void afe_config_balancing(); void afe_config_balancing();
void afe_balance_channels(uint16_t channelstobalance); void afe_balance_channels(uint16_t channelstobalance);

View File

@ -199,4 +199,6 @@
#define OV_FAULT_SUM (1 << 14) #define OV_FAULT_SUM (1 << 14)
#define UV_FAULT_SUM (1 << 15) #define UV_FAULT_SUM (1 << 15)
#define DEVCONFIG_REG_DISABLE (1 << 5)
#endif /* INC_BQ_REGISTER_DEFINITIONS_H_ */ #endif /* INC_BQ_REGISTER_DEFINITIONS_H_ */

View File

@ -12,6 +12,9 @@
#include "stm32f4xx_hal.h" #include "stm32f4xx_hal.h"
#include <stdint.h>
#include <string.h>
uint16_t cell_voltages[N_CELLS]; uint16_t cell_voltages[N_CELLS];
BQ_Status bq_status; BQ_Status bq_status;
@ -36,11 +39,7 @@ void afe_init(UART_HandleTypeDef* uarthandle) {
// Initialise underlying BQ Communication Functions // Initialise underlying BQ Communication Functions
init_BQCom(uarthandle); init_BQCom(uarthandle);
// Turn the AFE on off on to cycle a full reset // *Don't* power cycle the AFE to comply with 9.1.2
afe_wakeup();
HAL_Delay(10);
afe_shutdown();
HAL_Delay(100);
afe_wakeup(); afe_wakeup();
HAL_Delay(10); HAL_Delay(10);
@ -51,6 +50,9 @@ void afe_init(UART_HandleTypeDef* uarthandle) {
afe_config_gpios(); afe_config_gpios();
afe_activate_LED(); afe_activate_LED();
// Clear FAULT_SYS[SYS_RESET] before writing REG_DISABLE
afe_clear_all_faults();
afe_config_power();
afe_init_fault_thresholds(); afe_init_fault_thresholds();
@ -60,7 +62,7 @@ void afe_init(UART_HandleTypeDef* uarthandle) {
afe_clear_all_faults(); afe_clear_all_faults();
HAL_Delay(10); HAL_Delay(100);
afe_check_faults(); afe_check_faults();
} }
@ -147,6 +149,7 @@ void afe_check_faults() {
} }
void afe_clear_all_faults() { void afe_clear_all_faults() {
memset(&bq_error, 0, sizeof(bq_error));
BQ_Write_Register(FAULT_SUM, FAULT_SUM_SIZE, 0xFFC0); // Clear all Faults BQ_Write_Register(FAULT_SUM, FAULT_SUM_SIZE, 0xFFC0); // Clear all Faults
bq_status = BQ_STDBY; bq_status = BQ_STDBY;
HAL_Delay(1); HAL_Delay(1);
@ -191,6 +194,13 @@ void afe_config_communication() {
void afe_config_gpios() { BQ_Write_Register(GPIO_DIR, GPIO_DIR_SIZE, 0x01); } void afe_config_gpios() { BQ_Write_Register(GPIO_DIR, GPIO_DIR_SIZE, 0x01); }
void afe_config_power() {
uint32_t devconfig;
BQ_Read_Register(DEVCONFIG, DEVCONFIG_SIZE, &devconfig);
devconfig |= DEVCONFIG_REG_DISABLE;
BQ_Write_Register(DEVCONFIG, DEVCONFIG_SIZE, devconfig);
}
void afe_activate_LED() { BQ_Write_Register(GPIO_OUT, GPIO_OUT_SIZE, 0x01); } void afe_activate_LED() { BQ_Write_Register(GPIO_OUT, GPIO_OUT_SIZE, 0x01); }
void afe_config_balancing() { void afe_config_balancing() {