cancel
Showing results for 
Search instead for 
Did you mean: 

Hello, I am trying to set up a FDCAN communication (STD Id) at a baud rate of 250 kbit/s in STM32G473RBT . The Tx part seems to work perfectly but I have a problem at the level of the reception.

NToua.2461
Associate II

I try to just toggle a led for each received frame (STD ID).

With a logic analyser I checked the Rx pin on the Rx MCU and the frames arrive well. Hence my feeling that the problem lies at the level of the callback function where the MCU never go.

Thank you in advance for the help you will be able to give me.

1 ACCEPTED SOLUTION

Accepted Solutions

Hi,

You have problem with file "startup_stm32g473rbtx.s". I attached new file for Your project. Please replace only this file.

Best Regards,

Slawek

View solution in original post

16 REPLIES 16
SKacp.1
Senior II

Hi,

If You want to have communication 250 kb/s please change in the init section from hfdcan1.Init.NominalPrescaler = 1 to hfdcan1.Init.NominalPrescaler = 4.

Do no not change hfdcan1.Init.ClockDivider. This is divider main clock fequency for FDCAN. If You change this divider You must also change the parameters NominalTimeSeg1 and NominalTimeSeg2.

static void MX_FDCAN1_Init(void)
{
 
  /* USER CODE BEGIN FDCAN1_Init 0 */
 
  /* USER CODE END FDCAN1_Init 0 */
 
  /* USER CODE BEGIN FDCAN1_Init 1 */
 
  /* USER CODE END FDCAN1_Init 1 */
  hfdcan1.Instance = FDCAN1;
  hfdcan1.Init.ClockDivider = FDCAN_CLOCK_DIV1;
  hfdcan1.Init.FrameFormat = FDCAN_FRAME_CLASSIC;
  hfdcan1.Init.Mode = FDCAN_MODE_NORMAL;
  hfdcan1.Init.AutoRetransmission = ENABLE;
  hfdcan1.Init.TransmitPause = ENABLE;
  hfdcan1.Init.ProtocolException = DISABLE;
  hfdcan1.Init.NominalPrescaler = 4;
  hfdcan1.Init.NominalSyncJumpWidth = 16;
  hfdcan1.Init.NominalTimeSeg1 = 63;
  hfdcan1.Init.NominalTimeSeg2 = 16;
  hfdcan1.Init.DataPrescaler = 1;
  hfdcan1.Init.DataSyncJumpWidth = 4;
  hfdcan1.Init.DataTimeSeg1 = 5;
  hfdcan1.Init.DataTimeSeg2 = 4;
  hfdcan1.Init.StdFiltersNbr = 1;
  hfdcan1.Init.ExtFiltersNbr = 0;
  hfdcan1.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION;
  if (HAL_FDCAN_Init(&hfdcan1) != HAL_OK)
  {
    Error_Handler();
  }
  /* USER CODE BEGIN FDCAN1_Init 2 */
 
	FDCAN_FilterTypeDef sFilterConfig;
 
	sFilterConfig.IdType = FDCAN_STANDARD_ID;
	sFilterConfig.FilterIndex = 0;
	sFilterConfig.FilterType = FDCAN_FILTER_MASK;
	sFilterConfig.FilterConfig = FDCAN_FILTER_TO_RXFIFO0;
	sFilterConfig.FilterID1 = 0x321;
	sFilterConfig.FilterID2 = 0x7FF;
 
	if(HAL_FDCAN_ConfigFilter(&hfdcan1, &sFilterConfig) != HAL_OK)
	{
		Error_Handler();
	}
 
	if(HAL_FDCAN_ConfigGlobalFilter(&hfdcan1, FDCAN_REJECT, FDCAN_REJECT, FDCAN_FILTER_REMOTE, FDCAN_FILTER_REMOTE) != HAL_OK)
	{
		Error_Handler();
	}
 
	if(HAL_FDCAN_Start(&hfdcan1) != HAL_OK)
	{
		Error_Handler();
	}
 
	if(HAL_FDCAN_ActivateNotification(&hfdcan1, FDCAN_IT_RX_FIFO0_NEW_MESSAGE, 0) != HAL_OK)
	{
		Error_Handler();
	}
 
	TxHeader.Identifier = 0x123;
	TxHeader.IdType = FDCAN_STANDARD_ID;
	TxHeader.TxFrameType = FDCAN_DATA_FRAME;
	TxHeader.DataLength = FDCAN_DLC_BYTES_8;
	TxHeader.ErrorStateIndicator = FDCAN_ESI_ACTIVE;
	TxHeader.BitRateSwitch = FDCAN_BRS_OFF;
	TxHeader.FDFormat = FDCAN_CLASSIC_CAN;
	TxHeader.TxEventFifoControl = FDCAN_NO_TX_EVENTS;
	TxHeader.MessageMarker = 0;
 
 
  /* USER CODE END FDCAN1_Init 2 */
 
}

Best Regards,

Slawek

Best Regards

thank you for your reply but i don't have any problem with the baud rate because i word with 20mhz the clock of FD CAN.i get exactly 250 250 kb/s  with the hfdcan1.Init.NominalPrescaler = 1. the problem that i send message from ixxat and there is no receive callback :/. the interruption of FD CAN dosen't work .do you know the reason of that problem !! thank you

Hi,

How You check that You do not have receive callback from ixxat?

Please also check settings of Your "sFilterConfig".

Best Regards,

Slawek

hi,

I tested to place a breakpoint at the beginning of HAL_FDCAN_RxFifo0Callback ;the MCU never go to the call back when i sent a message from ixxat.

Best Regards,

Hi,

Your device ixxat send message with standardID 0x321 and the lenght is 8 byte?

Best Regards,

Slawek

YES ; i has verified this with oscilloscope

hi;

Now the probleme that when i send message with ixxat standardID 0x321 and the lenght is 8 byte. the MCU go to HardFault_Handler. do you now what can be the probleme please.

Best Regards,

nasri

Hi,

Please change filter settings from sFilterConfig.FilterID2 = 0x000 to sFilterConfig.FilterID2 = 0x7FF.

Best Regards,

Slawek

NToua.2461
Associate II

hi;

the same problem HardFault_Handler :/