From 6145508e8b5423da20d51dbd258fe0ee110351e5 Mon Sep 17 00:00:00 2001 From: Kilian Bracher Date: Mon, 31 Mar 2025 19:46:47 +0200 Subject: [PATCH] add: better error message when DPEC fails to validate --- .../ADBMS6830B_Driver/Core/Src/ADBMS_Abstraction.c | 3 +-- .../Lib/ADBMS6830B_Driver/Core/Src/ADBMS_LL_Driver.c | 12 ++++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/AMS_Master_Code/Core/Lib/ADBMS6830B_Driver/Core/Src/ADBMS_Abstraction.c b/AMS_Master_Code/Core/Lib/ADBMS6830B_Driver/Core/Src/ADBMS_Abstraction.c index bd3f2f1..52dc513 100644 --- a/AMS_Master_Code/Core/Lib/ADBMS6830B_Driver/Core/Src/ADBMS_Abstraction.c +++ b/AMS_Master_Code/Core/Lib/ADBMS6830B_Driver/Core/Src/ADBMS_Abstraction.c @@ -85,8 +85,7 @@ HAL_StatusTypeDef initAMS(SPI_HandleTypeDef* hspi) { } HAL_StatusTypeDef amsWakeUp() { - uint8_t buffer[CMD_BUFFER_SIZE(CFG_GROUP_A_SIZE)] = {0}; - return readCMD(RDCFGA, buffer, CFG_GROUP_A_SIZE); + return __pollCMD(PLADC, 100); //wake up ADBMS6830, wait for T_wake = 200 us (100 cycles at 500 kHz) } HAL_StatusTypeDef amsCellMeasurement(Cell_Module (*module)[N_BMS]) { diff --git a/AMS_Master_Code/Core/Lib/ADBMS6830B_Driver/Core/Src/ADBMS_LL_Driver.c b/AMS_Master_Code/Core/Lib/ADBMS6830B_Driver/Core/Src/ADBMS_LL_Driver.c index 6f2520b..a35f37b 100644 --- a/AMS_Master_Code/Core/Lib/ADBMS6830B_Driver/Core/Src/ADBMS_LL_Driver.c +++ b/AMS_Master_Code/Core/Lib/ADBMS6830B_Driver/Core/Src/ADBMS_LL_Driver.c @@ -252,6 +252,18 @@ HAL_StatusTypeDef ___readCMD(uint16_t command, uint8_t * buffer, size_t arglen) for (size_t i = 0; i < N_BMS; i++) { size_t offset = BUFFER_BMS_OFFSET(i, arglen); if (checkDataPEC(&buffer[offset], arglen + 2) != 0) { + debug_log(LOG_LEVEL_ERROR, "Invalid data PEC when reading BMS %d", i); + debug_log(LOG_LEVEL_ERROR, "Received: "); + for (size_t j = 0; j < arglen + 2; j++) { + debug_log_cont(LOG_LEVEL_ERROR, "%02X ", buffer[offset + j]); + } + debug_log_cont(LOG_LEVEL_ERROR, " | %02X %02X ", buffer[offset + arglen], buffer[offset + arglen + 1]); //print out the DPEC + debug_log(LOG_LEVEL_ERROR, "^ DATA"); + //print out spaces until start of DPEC + for (size_t j = 0; j < arglen; j++) { + debug_log_cont(LOG_LEVEL_ERROR, (arglen < 2) ? "" : " "); + } + debug_log(LOG_LEVEL_ERROR, " ^ DPEC"); return HAL_ERROR; } }