cancel
Showing results for 
Search instead for 
Did you mean: 

CAN BUS automatic retransmission order

JBond.1
Senior

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?

1 ACCEPTED SOLUTION

Accepted Solutions
MEige.1
Associate III

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;

View solution in original post

2 REPLIES 2
JBond.1
Senior

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
Associate III

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;