cancel
Showing results for 
Search instead for 
Did you mean: 

How to configure FDCAN recieve buffer?

KBied.1
Associate

Hello Everyone,

I have Nucleo-H723ZG and I managed to configure CAN to work there but only sending messages. I am not able to get anything in RX Buffer.

I configured CAN like:

hfdcan1.Instance = FDCAN1;
 hfdcan1.Init.FrameFormat = FDCAN_FRAME_CLASSIC;
 hfdcan1.Init.Mode = FDCAN_MODE_EXTERNAL_LOOPBACK;
 hfdcan1.Init.AutoRetransmission = ENABLE;
 hfdcan1.Init.TransmitPause = DISABLE;
 hfdcan1.Init.ProtocolException = DISABLE;
 hfdcan1.Init.NominalPrescaler = 30;
 hfdcan1.Init.NominalSyncJumpWidth = 2;
 hfdcan1.Init.NominalTimeSeg1 = 19;
 hfdcan1.Init.NominalTimeSeg2 = 12;
 hfdcan1.Init.DataPrescaler = 1;
 hfdcan1.Init.DataSyncJumpWidth = 1;
 hfdcan1.Init.DataTimeSeg1 = 1;
 hfdcan1.Init.DataTimeSeg2 = 1;
 hfdcan1.Init.MessageRAMOffset = 0;
 hfdcan1.Init.StdFiltersNbr = 128;
 hfdcan1.Init.ExtFiltersNbr = 0;
 hfdcan1.Init.RxFifo0ElmtsNbr = 0;
 hfdcan1.Init.RxFifo0ElmtSize = FDCAN_DATA_BYTES_8;
 hfdcan1.Init.RxFifo1ElmtsNbr = 0;
 hfdcan1.Init.RxFifo1ElmtSize = FDCAN_DATA_BYTES_8;
 hfdcan1.Init.RxBuffersNbr = 64; 
 hfdcan1.Init.RxBufferSize = FDCAN_DATA_BYTES_8; 
 hfdcan1.Init.TxEventsNbr = 32;
 hfdcan1.Init.TxBuffersNbr = 32;
 hfdcan1.Init.TxFifoQueueElmtsNbr = 32;
 hfdcan1.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION;
 hfdcan1.Init.TxElmtSize = FDCAN_DATA_BYTES_8;
 if (HAL_FDCAN_Init(&hfdcan1) != HAL_OK)
 {
   Error_Handler(); 
 }

Then I Initialize RX BUFFER:

sFilterConfig.IdType = FDCAN_STANDARD_ID;
   sFilterConfig.FilterIndex = 0;
   sFilterConfig.RxBufferIndex = 0;
   sFilterConfig.FilterConfig = FDCAN_FILTER_TO_RXBUFFER;
   sFilterConfig.FilterID1 = 0x100;
   sFilterConfig.IsCalibrationMsg = 0;
   if (HAL_FDCAN_ConfigFilter(&hfdcan1, &sFilterConfig) != HAL_OK)
   {
      Error_RXBuff(id);
   }
	if (HAL_FDCAN_ConfigGlobalFilter(&hfdcan1, FDCAN_REJECT, FDCAN_REJECT, FDCAN_FILTER_REMOTE, FDCAN_FILTER_REMOTE) != HAL_OK)
	{
		Error_Handler();
	}
	/* Start the FDCAN module */
	if (HAL_FDCAN_Start(&hfdcan1) != HAL_OK)
	{
		Error_Handler();
	}

Problem is that I can not recieve anything in that RXBUFFER.

To recieve I use:

if(HAL_FDCAN_IsRxBufferMessageAvailable(&hfdcan1, 0))
{
       FDCAN_RxHeaderTypeDef RxHeader;
	HAL_FDCAN_GetRxMessage(&hfdcan1, 0, &RxHeader, data);
	if(RxHeader.Identifier != 0)
	{
		*id = RxHeader.Identifier;
		return HAL_OK;
	}
	return HAL_ERROR;
}

What I do wrong with Recieve Buffer deffinition?

Sending messages works perfectly for me:

uint8_t CAN_putd(FDCAN_HandleTypeDef *hfdcan, uint32_t id, uint8_t *data, uint32_t  buff)
{
	FDCAN_TxHeaderTypeDef TxHeader;
 
	TxHeader.Identifier = id;
	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;
 
	buff = 1<<buff; // TX Buffer represented in binary way
 
	uint8_t status = HAL_OK;
 
	status = HAL_FDCAN_AddMessageToTxBuffer(hfdcan, &TxHeader, data, buff);
	if(status == HAL_OK)
	{
		status = HAL_FDCAN_EnableTxBufferRequest(hfdcan, buff);
	}
	return status;
}

Regards,

Chris

1 ACCEPTED SOLUTION

Accepted Solutions
KBied.1
Associate

Solved:

Simply use:

hfdcan1.Init.Mode = FDCAN_MODE_NORMAL;

View solution in original post

1 REPLY 1
KBied.1
Associate

Solved:

Simply use:

hfdcan1.Init.Mode = FDCAN_MODE_NORMAL;