From c49490d33c28b754d2a7834ab09bab0142a5a911 Mon Sep 17 00:00:00 2001 From: Simo Sihvonen Date: Wed, 27 Jan 2021 15:45:09 +0200 Subject: [PATCH] -Improved the CAN TX retry to be more robust --- Src/CAN_LL.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/Src/CAN_LL.c b/Src/CAN_LL.c index 53e3079..9ecf890 100644 --- a/Src/CAN_LL.c +++ b/Src/CAN_LL.c @@ -451,12 +451,21 @@ void CAN1_TX_IRQHandler(void){ if( !!(CAN1->TSR & (1 << 0)) == 1 ){ //TX mailbox 0 transmit request complete - if( !!(CAN1->TSR & (1 << 1)) == 0 ){ //check if the mailbox message was transmitted successfully and retry is failed - retryAttempts++; - if(retryAttempts < 10){ //only allow a fixed amount of re-transmit attempts, as to not get stuck + if( !!(CAN1->TSR & (1 << 2)) == 1 ){ //check if arbitration was lost during transmit attempt and retry if failed + + CAN1->sTxMailBox[0].TIR |= (1 << 0); //request new TX attempt with old mailbox content, aka retry + return; + + } + + if( !!(CAN1->TSR & (1 << 3)) == 1 ){ //check if bus error happened during last transmit attempt and retry couple times if failed + + if(retryAttempts < 3){ //only allow a fixed amount of re-transmit attempts, as to not get stuck CAN1->sTxMailBox[0].TIR |= (1 << 0); //request new TX attempt with old mailbox content, aka retry + retryAttempts++; return; } + } retryAttempts = 0;