Skip to main content
VCasa.3
Associate II
May 25, 2025
Solved

STM32H750 FDCAN Not transmiting

  • May 25, 2025
  • 1 reply
  • 1315 views

Dear Sirs,

I am implementing an interface between an STM32H750 and a CanBus device of an electric bike. I have the FDCAN peripheral configured to 250kbit/s (FDCAN clock is 48MHz)

VCasa3_0-1748185676203.pngVCasa3_1-1748185692372.png

I have to interface with devices that use Extended Frames, but the speed is fixed to 250bit/s, so I wanted to use normal mode.

First I ninitialize the peripheral as:

// Configure TX Header for FDCAN2
 CAN_TxHeader.Identifier = 0x03;
 CAN_TxHeader.IdType = FDCAN_EXTENDED_ID;
 CAN_TxHeader.TxFrameType = FDCAN_DATA_FRAME;
 CAN_TxHeader.DataLength = FDCAN_DLC_BYTES_8;
 CAN_TxHeader.ErrorStateIndicator = FDCAN_ESI_ACTIVE;
 CAN_TxHeader.BitRateSwitch = FDCAN_BRS_OFF;
 CAN_TxHeader.FDFormat = FDCAN_FD_CAN;
 CAN_TxHeader.TxEventFifoControl = FDCAN_NO_TX_EVENTS;
 CAN_TxHeader.MessageMarker = 0;

 /* Configure standard ID reception filter to Rx buffer 0 */
 CAN_FilterConfig.IdType = FDCAN_EXTENDED_ID;
 CAN_FilterConfig.FilterIndex = 0;
 CAN_FilterConfig.FilterType = FDCAN_FILTER_DUAL;
 CAN_FilterConfig.FilterID2 = 0x0;
 CAN_FilterConfig.RxBufferIndex = 0;

 if(HAL_FDCAN_ConfigFilter(&hfdcan2, &CAN_FilterConfig) != HAL_OK)
 {
	 Error_Handler();
 }

 if(HAL_FDCAN_Start(&hfdcan2)!= HAL_OK)
 {
	 Error_Handler();
 }

 if (HAL_FDCAN_ActivateNotification(&hfdcan2, FDCAN_IT_RX_FIFO1_NEW_MESSAGE, 0) != HAL_OK)
 {
	 /* Notification Error */
	 Error_Handler();
 }

 if(HAL_FDCAN_AddMessageToTxFifoQ(&hfdcan2, &CAN_TxHeader, &CAN_TxData[0]) != HAL_OK)
 {
	 Error_Handler();
 }

and then in a FreeRTOS task I send data:

void canBus(void *argument)
{
 /* USER CODE BEGIN canBus */
	HAL_StatusTypeDef rtv = HAL_ERROR;
 /* Infinite loop */
 for(;;)
 {
	 // Send the HeartBeat Message to the controller
	 CAN_TxHeader.DataLength = FDCAN_DLC_BYTES_4;
	 CAN_TxData[0] = 0x05;
	 CAN_TxData[1] = 0x03;
	 CAN_TxData[2] = 0x00;
	 CAN_TxData[3] = 0x01;
	 rtv = HAL_FDCAN_AddMessageToTxFifoQ(&hfdcan2, &CAN_TxHeader, &CAN_TxData[0]);

	 // Check is there are Received Messages in the CAN RX FIFO
	if (can_rx_message_available != 0)
	{
		// Process them
		canBusMsgProcess();
		can_rx_message_available = 0;
	}

 osDelay(1000);
 }
 /* USER CODE END canBus */
}

 

Debugging the code, placing a breakpoint, I get that rtv is always HAL_OK, and if with the oscilloscope I monitor the CAN_TX pins, there is activity, but then in the bus, there is no activity (CANH/CANL lines)

 

I have been going back and forth with this for days, and I do not know what can be problem.

Is it something with initialization? Probably with the FIFO?

I do not want to filter Messages on the Bus, as this will interface with a lot of different devices.

 

Thank you so much in advance,

Best regards

Best answer by mƎALLEm

Hello,

What frame format your CAN bus needs to support classic or FD?

I see in your code:

CAN_TxHeader.FDFormat = FDCAN_FD_CAN;

Are you sure it's FD?

You didn't share your CAN initialization code.

I suggest to share your project so we can check all the parameters and config.

Please remove all the stuff not related to the CAN. Keep only the minimal but a complete project that let others run a test.

1 reply

mƎALLEm
mƎALLEmBest answer
Technical Moderator
May 26, 2025

Hello,

What frame format your CAN bus needs to support classic or FD?

I see in your code:

CAN_TxHeader.FDFormat = FDCAN_FD_CAN;

Are you sure it's FD?

You didn't share your CAN initialization code.

I suggest to share your project so we can check all the parameters and config.

Please remove all the stuff not related to the CAN. Keep only the minimal but a complete project that let others run a test.

To give better visibility on the answered topics, please click "Best answer" on the reply which solved your issue or answered your question.
VCasa.3
VCasa.3Author
Associate II
May 28, 2025

Changing this:

CAN_TxHeader.FDFormat = FDCAN_FD_CAN;

Fixed the issue

Thank you so much!