2022-03-20 02:09 PM
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?
Solved! Go to Solution.
2023-01-05 11:35 PM
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;
2022-03-20 02:27 PM
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;
}
2023-01-05 11:35 PM
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;