From c3fbbab4850ccb2d4e65dfdacd9386a3c787e81c Mon Sep 17 00:00:00 2001 From: Elliot Williams Date: Wed, 18 Dec 2019 15:42:51 +0100 Subject: [PATCH] a periodic usart reset works much better tying the usart buffer clear to the 25*5 ms system tick makes sense --- Src/main.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Src/main.c b/Src/main.c index 8c53302..7ae3098 100644 --- a/Src/main.c +++ b/Src/main.c @@ -225,8 +225,11 @@ int main(void) { cmd1 = CLAMP((int16_t)command.steer, -1000, 1000); cmd2 = CLAMP((int16_t)command.speed, -1000, 1000); } else { // restart DMA to hopefully get back in sync - HAL_UART_DMAStop(&huart2); - HAL_UART_Receive_DMA(&huart2, (uint8_t *)&command, sizeof(command)); + // Try a periodic reset + if (main_loop_counter % 25 == 0) { + HAL_UART_DMAStop(&huart2); + HAL_UART_Receive_DMA(&huart2, (uint8_t *)&command, sizeof(command)); + } } timeout = 0; #endif