cancel
Showing results for 
Search instead for 
Did you mean: 

How to Configure multiple FD CAN RX_BUFFER ?

ANguy.5
Associate II

Hello,

I configured my FD CAN on NUCLEO STM32H53 with the function as below. I want to have two RX Buffers to receive 2 specific CAN IDs.

However, when I checked RX_BUFFER0 with

if (HAL_FDCAN_IsRxBufferMessageAvailable(&hfdcan1, FDCAN_RX_BUFFER0) > 0), I do not receive anything in the buffer even though the frames were sending on the bus.

But when I checked RX_BUFFER1 with

if (HAL_FDCAN_IsRxBufferMessageAvailable(&hfdcan1, FDCAN_RX_BUFFER1) > 0) , I see CAN frame coming in. It looks like only buffer 1 working.

Do you know what I am missing here to have two buffers receiving CAN data?

Thanks!

static void MX_FDCAN1_Init(void)
{
	hfdcan1.Instance = FDCAN1;
	hfdcan1.Init.FrameFormat = FDCAN_FRAME_FD_NO_BRS;
	hfdcan1.Init.Mode = FDCAN_MODE_NORMAL;
	hfdcan1.Init.AutoRetransmission = ENABLE;
	hfdcan1.Init.TransmitPause = DISABLE;
	hfdcan1.Init.ProtocolException = ENABLE;
 
	hfdcan1.Init.NominalPrescaler = 1;
	hfdcan1.Init.NominalSyncJumpWidth = 8;
	hfdcan1.Init.NominalTimeSeg1 = 69;
	hfdcan1.Init.NominalTimeSeg2 = 10;
 
	hfdcan1.Init.DataPrescaler = 1;
	hfdcan1.Init.DataSyncJumpWidth = 4;
	hfdcan1.Init.DataTimeSeg1 = 15;
	hfdcan1.Init.DataTimeSeg2 = 4;
 
	hfdcan1.Init.MessageRAMOffset = 0;
	hfdcan1.Init.StdFiltersNbr = 2;
	hfdcan1.Init.ExtFiltersNbr = 0;
 
	hfdcan1.Init.RxFifo0ElmtsNbr = 0;
	hfdcan1.Init.RxFifo0ElmtSize = FDCAN_DATA_BYTES_64;
 
	hfdcan1.Init.RxFifo1ElmtsNbr = 0;
	hfdcan1.Init.RxFifo1ElmtSize = FDCAN_DATA_BYTES_64;
 
	hfdcan1.Init.RxBuffersNbr = 2;
	hfdcan1.Init.RxBufferSize = FDCAN_DATA_BYTES_64;
 
	hfdcan1.Init.TxEventsNbr = 0;
	hfdcan1.Init.TxBuffersNbr = 0;
	hfdcan1.Init.TxFifoQueueElmtsNbr = 2;
	hfdcan1.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION;
	hfdcan1.Init.TxElmtSize = FDCAN_DATA_BYTES_64;
 
	if (HAL_FDCAN_Init(&hfdcan1) != HAL_OK)
	{
	Error_Handler();
	}
 
	FDCAN_FilterTypeDef sFilterConfig;
 
	/* Configure Rx filter to receive synchronization message */
	sFilterConfig.IdType = FDCAN_STANDARD_ID;
	sFilterConfig.FilterIndex = 0;
	sFilterConfig.FilterConfig = FDCAN_FILTER_TO_RXBUFFER;
	sFilterConfig.FilterID1 = 0x73B;
	sFilterConfig.RxBufferIndex = 0;
	sFilterConfig.IsCalibrationMsg = 0;
	HAL_FDCAN_ConfigFilter(&hfdcan1, &sFilterConfig);
 
	/* Configure Rx filter to receive synchronization message */
	sFilterConfig.IdType = FDCAN_STANDARD_ID;
	sFilterConfig.FilterIndex = 0;
	sFilterConfig.FilterConfig = FDCAN_FILTER_TO_RXBUFFER;
	sFilterConfig.FilterID1 = 0x73A;
	sFilterConfig.RxBufferIndex = 1;
	sFilterConfig.IsCalibrationMsg = 0;
	HAL_FDCAN_ConfigFilter(&hfdcan1, &sFilterConfig);
 
	/* Configure and enable Tx Delay Compensation : TdcOffset = DataTimeSeg1*DataPrescaler */
	HAL_FDCAN_ConfigTxDelayCompensation(&hfdcan1, 15, 0);
	HAL_FDCAN_EnableTxDelayCompensation(&hfdcan1);
 
	if (HAL_FDCAN_Start(&hfdcan1) != HAL_OK)
	{
	  Error_Handler();
	}
}

1 ACCEPTED SOLUTION

Accepted Solutions
SKacp.1
Senior II

Hi,

I think so You should be changed filter index (sFilterConfig.FilterIndex = 0) for the next buffer Rx (sFilterConfig.FilterIndex = 1)

Best Regards,

Slawek

View solution in original post

3 REPLIES 3
SKacp.1
Senior II

Hi,

I think so You should be changed filter index (sFilterConfig.FilterIndex = 0) for the next buffer Rx (sFilterConfig.FilterIndex = 1)

Best Regards,

Slawek

ANguy.5
Associate II

Hello Slawek,

Thank you. Changing FIlterIndex solved the problem. I tried to understand what this FilterIndex is for, but reading in the manual, I don't see much explanation.

Would you mind to share your knowledge what this FilterIndex logic is for?

An