From a88f663afc3fbecc807a7452f4ebc5b7352e278d Mon Sep 17 00:00:00 2001 From: kbracher Date: Sun, 23 Mar 2025 15:44:19 +0100 Subject: [PATCH] give bms time to settle before erroring immediately --- AMS_Master_Code/Core/Src/main.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/AMS_Master_Code/Core/Src/main.c b/AMS_Master_Code/Core/Src/main.c index edbb2ad..467ae95 100644 --- a/AMS_Master_Code/Core/Src/main.c +++ b/AMS_Master_Code/Core/Src/main.c @@ -114,14 +114,22 @@ int main(void) /* Infinite loop */ /* USER CODE BEGIN WHILE */ int count = 0; + int error_count = 0; while (1) { + if (error_count > 10) { + debug_log(LOG_LEVEL_ERROR, "Too many errors, restarting BMS..."); + status = AMS_Init(&hspi1); + if (status.status != ADBMS_NO_ERROR) { + debug_log(LOG_LEVEL_ERROR, "Failed to initialize BMS, AMS_Init returned %u (%s) on BMS %d", status.status, ADBMS_Status_ToString(status.status), status.bms_id); + HAL_Delay(2000); + continue; + } + } status = AMS_Idle_Loop(); if (status.status != ADBMS_NO_ERROR) { debug_log(LOG_LEVEL_ERROR, "AMS_Idle_Loop returned %u (%s) on BMS %d", status.status, ADBMS_Status_ToString(status.status), status.bms_id); - HAL_Delay(2000); - AMS_Init(&hspi1); - continue; + error_count++; } if (count % 4 == 0) { for (size_t i = 0; i < N_BMS; i++) {