Skip to main content
JBond.1
Senior
March 20, 2022
Solved

CAN BUS automatic retransmission order

Hi, I have STM32F4 and I am trying to send list of messages in order with CAN BUS:

// CAN BUS message data list in particular order
// 01FFFFFFFFFFFFFF
// 02FFFFFFFFFFFFFF
// 03FFFFFFFFFFFFFF
// 04FFFFFFFFFFFFFF

I have AutoRetransmission enabled, because sometimes it fails to transmit message.

hcan1.Init.AutoRetransmission = ENABLE;

The issue I am observing is that message list does not arrive in the same order:

// CAN BUS message data list received in bad order
// 01FFFFFFFFFFFFFF
// 04FFFFFFFFFFFFFF // <-- bad order
// 02FFFFFFFFFFFFFF
// 03FFFFFFFFFFFFFF

Is this a bug? How do I keep messages in same order which I want to send?

This topic has been closed for replies.
MEige.1
MEige.1Best answer
Associate II
January 6, 2023

Your solution works but is not very efficient with only one TX mailbox used.

Usually the TX mailboxes are used in ID priority mode but you can switch it to FIFO mode in CAN init.

hcan->Init.TransmitFifoPriority = ENABLE;

2 replies

JBond.1
JBond.1Author
Senior
March 20, 2022

Seems that I need to check if all mailboxes are free before sending, so that sending would be in order!

bool CAN_CanTransferInOrder(void)
{
	return HAL_CAN_GetTxMailboxesFreeLevel(&hcan1) > 2;
}

MEige.1
MEige.1Best answer
Associate II
January 6, 2023

Your solution works but is not very efficient with only one TX mailbox used.

Usually the TX mailboxes are used in ID priority mode but you can switch it to FIFO mode in CAN init.

hcan->Init.TransmitFifoPriority = ENABLE;