2025-02-28 1:51 AM - last edited on 2025-02-28 2:40 AM by mƎALLEm
Hello everyone,
I'm trying to use the loopback mode on the STM32F4DISCOVERY. I configured the CAN peripheral and i started the transmission by adding data but when i try to verify the reception process i can't find data in the RxHeader.
Solved! Go to Solution.
2025-02-28 5:30 AM - edited 2025-02-28 5:31 AM
Thanks for sharing.
In fact the Rx call back was called but just once as you transmit once a CAN frame.
If you set a breakpoint in the call back before running, the callback is called.
So put the transmit call in the while loop:
while (1)
{
while(HAL_CAN_GetTxMailboxesFreeLevel(&hcan1) == 0);/* Wait till a Tx mailbox is free */
HAL_CAN_AddTxMessage(&hcan1, &TxHeader, TxData, &TxMailbox);
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
}
2025-02-28 2:37 AM - edited 2025-02-28 3:54 AM
Hello,
You missed to call HAL_CAN_ConfigFilter() to set the filtrer configuration:
if (HAL_CAN_ConfigFilter(&hcan1, &FilterConfig) != HAL_OK)
{
/* Filter configuration Error */
Error_Handler();
}
Don't forget to add this line to Set the slave start filter bank:
FilterConfig.SlaveStartFilterBank = 14;
+ Configure your CAN_Rx pin with pull-up resistor.
An example for your reference: https://github.com/STMicroelectronics/STM32CubeF4/tree/master/Projects/STM324xG_EVAL/Examples/CAN/CAN_LoopBack
See also this article: Troubleshooting bxCAN issues in Loop Back mode on STM32 MCUs
Hope that solves your issue.
2025-02-28 4:03 AM
Hello,
I'm using only CAN1. Do i need to set the slave start filter bank ?
2025-02-28 4:52 AM
In you case slave start filter bank needs to be set at least to 1. It's true the default value is 14 but set it anyway.
Did you succeed to receive with the loopback mode?
2025-02-28 4:58 AM
No, i didn't. I still have no value sent to RxData.
2025-02-28 5:05 AM
Please share you project as zip and attach it to the discussion.
2025-02-28 5:12 AM
2025-02-28 5:30 AM - edited 2025-02-28 5:31 AM
Thanks for sharing.
In fact the Rx call back was called but just once as you transmit once a CAN frame.
If you set a breakpoint in the call back before running, the callback is called.
So put the transmit call in the while loop:
while (1)
{
while(HAL_CAN_GetTxMailboxesFreeLevel(&hcan1) == 0);/* Wait till a Tx mailbox is free */
HAL_CAN_AddTxMessage(&hcan1, &TxHeader, TxData, &TxMailbox);
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
}