Skip to main content
JBond.1
Senior
July 7, 2021
Solved

STM32 CAN BUS missing some transferred messages

  • July 7, 2021
  • 1 reply
  • 1241 views

Hi, I am trying to communicate with other CAN devices on CAN BUS with STM32F103.

I have enabled "void HAL_CAN_RxFifo0MsgPendingCallback(CAN_HandleTypeDef *hcan)" to receive message interrupt as highest priority and in main loop I am checking if I got the message to which I need to respond.

If I have a message to which I need to respond and TxMailboxes have free space, I respond from main loop like so:

if (HAL_CAN_GetTxMailboxesFreeLevel(&hcan) > 0)
{
 if (HAL_CAN_AddTxMessage(&hcan, &TxMsg.Header, data, &TxMailbox) != HAL_OK)
 {
 Error_Handler();
 }
}

The problem I am having is that "HAL_CAN_AddTxMessage" return "HAL_OK", but often (something like 50/50 chance) other devices do not get the message. So message gets lost? Why adding TxMessage could fail? And why don't I get any indication that it failed?

How to correctly send CAN BUS message without loosing it?

This topic has been closed for replies.
Best answer by JBond.1

I have enabled AutoRetransmission feature. It seems to work much better now. Not sure if 100% sending rate, will need to test more.

1 reply

JBond.1
JBond.1AuthorBest answer
Senior
July 7, 2021

I have enabled AutoRetransmission feature. It seems to work much better now. Not sure if 100% sending rate, will need to test more.