Store details for BQ errors

This commit is contained in:
jazzpi
2022-06-12 14:44:37 +02:00
parent 6986e5dd3b
commit e503dbe632
5 changed files with 117 additions and 26 deletions

View File

@ -19,15 +19,32 @@
#define CELL_OV_THRESHOLD 55100 // 4.2V
#define CELL_UV_THRESHOLD 34100 // 2.6V
#define BQ_RDY 1
#define BQ_STDBY 2
#define BQ_OFF 0
#define BQ_INIT_PHASE 3
#define BQ_ERROR 4
extern uint16_t cell_voltages[N_CELLS];
extern uint8_t bq_status;
typedef enum { BQ_OFF, BQ_RDY, BQ_STDBY, BQ_INIT_PHASE, BQ_ERROR } BQ_Status;
extern BQ_Status bq_status;
#define BQ_ERROR_KIND_HAL (1 << 0)
#define BQ_ERROR_KIND_CRC (1 << 1)
#define BQ_ERROR_KIND_FAULT (1 << 2)
#define BQ_ERROR_LOC_MEASURE (1 << 0)
typedef struct {
uint8_t kind;
uint8_t hal_loc;
uint8_t crc_loc;
uint16_t fault_uv;
uint16_t fault_ov;
uint8_t fault_aux_uv;
uint8_t fault_aux_ov;
uint16_t fault_cmp_uv;
uint16_t fault_cmp_ov;
uint16_t fault_comm;
uint8_t fault_sys;
uint16_t fault_dev;
uint8_t fault_gpi;
} BQ_Error_Description;
extern BQ_Error_Description bq_error;
extern uint32_t lastmeasurementtime;
void afe_init(UART_HandleTypeDef* uarthandle);

View File

@ -14,6 +14,8 @@
#define BQUARTTIMEOUT 200
typedef enum { BQ_COMM_OK, BQ_COMM_ERR_HAL, BQ_COMM_ERR_CRC } BQ_Comm_Status;
void init_BQCom(UART_HandleTypeDef* uarthandle);
uint16_t Calculate_CRC(uint8_t* message_buffer, uint16_t bufferlength);
@ -23,7 +25,13 @@ uint32_t BQ_Write_Register(uint8_t registeraddress, uint8_t registersize,
uint32_t data);
uint8_t BQ_Read_Register(uint8_t registeraddress, uint8_t registersize,
uint32_t* data);
uint32_t BQ_ReadMeasurements(uint8_t* buffer, uint8_t bufferlength);
/**
* @brief Reads Voltage Measurements from the BQ76
*
* Result are Written into the Buffer
* Buffer size should be 2xMeasured Voltages
*/
BQ_Comm_Status BQ_ReadMeasurements(uint8_t* buffer, uint8_t bufferlength);
uint8_t Communication_Reset();
uint8_t BQ_UART_Transmit(uint8_t* message_buffer, uint16_t bufferlength);

View File

@ -188,4 +188,15 @@
#define EE_BURN_SIZE 0x01
#define MAGIC2_SIZE 0x04
#define GPI_FAULT_SUM (1 << 6)
#define CHIP_FAULT_SUM (1 << 7)
#define SYS_FAULT_SUM (1 << 8)
#define COMM_FAULT_SUM (1 << 9)
#define CMPOV_FAULT_SUM (1 << 10)
#define CMPUV_FAULT_SUM (1 << 11)
#define AUXOV_FAULT_SUM (1 << 12)
#define AUXUV_FAULT_SUM (1 << 13)
#define OV_FAULT_SUM (1 << 14)
#define UV_FAULT_SUM (1 << 15)
#endif /* INC_BQ_REGISTER_DEFINITIONS_H_ */