cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F407 and CAN protocol in Loopback mode

Azizz
Associate III

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. 

1 ACCEPTED SOLUTION

Accepted Solutions

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 */
  }
To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.

View solution in original post

7 REPLIES 7
mƎALLEm
ST Employee

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.

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.
Azizz
Associate III

Hello,
I'm using only CAN1. Do i need to set the slave start filter bank ?

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?

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.
Azizz
Associate III

No, i didn't. I still have no value sent to RxData. 

Please share you project as zip and attach it to the discussion.

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.
Azizz
Associate III
 

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 */
  }
To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.