cancel
Showing results for 
Search instead for 
Did you mean: 

How can I send multiple frames of data with FD-CAN using different IDs?

Choudharyas
Associate III

Hi everyone,

I am working on a FD-CAN project and i am able to send a 64 byte data frame. But I want to send multiple frames of data with different IDs. Any help would be greatly appreciated!

1 ACCEPTED SOLUTION

Accepted Solutions

Hello,

You're using the filter in Mask Mode and that's normal. Try to use FDCAN_FILTER_RANGE instead of FDCAN_FILTER_MASK.

0693W00000NrFb0QAF.png

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

9 REPLIES 9
SofLit
ST Employee

Hello,

What do you mean by "send multiple frames of data with different IDs."?

based on your question, the solution is simply sending successive messages with different IDs

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.

Yeah i tried sending successive messages but how can i assign different IDs to every message without changing the TxHeader(as I initialized the ID in TxHeader). Thanks for help.

Hello,

Sorry I didn't understand.

You said "assign different IDs to every message" but at the same type you want to keep it by "without changing the TxHeader(as I initialized the ID in TxHeader)"

Do you want to keep the same ID for several messages or set each message with its specific ID?

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.

Hi, 

Sorry for that. I want to set a specific ID for every message. Again thanks ​for help.

But why you don't want to update TxHeader.Identifier for every message? is there any constraint?

Normally, you have to update each structure member of TxHeader each time there is a change: ID, ID type etc ..

For your case you have to update only TxHeader.Identifier followed by a call of the API that sends FDCAN message such as HAL_FDCAN_AddMessageToTxFifoQ().

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.

Hi,

Thanks i tried that. but on receiver side i am receiving the messages from all the IDs into the FDCAN_RX_FIFO0 even after configuring the filter to receive the messages only from a particular ID. In my case i am sending two messages with IDs 0x111 and 0x223 and on receiver side configured the filter to receive the messages only from 0x223 ID but it is also receiving the message from 0x111 ID. my code snippet is shown below:

/* Configure reception filter to Rx FIFO 0 */
  sFilterConfig.IdType = FDCAN_STANDARD_ID;
  sFilterConfig.FilterIndex = 0;
  sFilterConfig.FilterType = FDCAN_FILTER_MASK;
  sFilterConfig.FilterConfig = FDCAN_FILTER_TO_RXFIFO0;
  sFilterConfig.FilterID1 = 0x223;
  sFilterConfig.FilterID2 = 0x7FF;
  if (HAL_FDCAN_ConfigFilter(&hfdcan1, &sFilterConfig) != HAL_OK)
  {
    Error_Handler();
  }
 
  /* Configure global filter:
     Filter all remote frames with STD and EXT ID
     Reject non matching frames with STD ID and EXT ID */
  if (HAL_FDCAN_ConfigGlobalFilter(&hfdcan1, FDCAN_REJECT, FDCAN_REJECT, FDCAN_FILTER_REMOTE, FDCAN_FILTER_REMOTE) != HAL_OK)
  {
    Error_Handler();
  }
 
  /* Activate Rx FIFO 0 new message notification */
  if (HAL_FDCAN_ActivateNotification(&hfdcan1, FDCAN_IT_RX_FIFO0_NEW_MESSAGE, 0) != HAL_OK)
  {
    Error_Handler();
  }
 
void HAL_FDCAN_RxFifo0Callback(FDCAN_HandleTypeDef *hfdcan, uint32_t RxFifo0ITs)
{
  if((RxFifo0ITs & FDCAN_IT_RX_FIFO0_NEW_MESSAGE) != 0)
  {
    /* Retrieve Rx messages from RX FIFO0 */
    if (HAL_FDCAN_GetRxMessage(hfdcan, FDCAN_RX_FIFO0, &RxHeader, RxData) != HAL_OK)
    {
      Error_Handler();
    }
 

Hello,

You're using the filter in Mask Mode and that's normal. Try to use FDCAN_FILTER_RANGE instead of FDCAN_FILTER_MASK.

0693W00000NrFb0QAF.png

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.

Hi,

Thanks for the help. Now i am able to filter out the messages according to IDs.

Hello,

Thank you for the feedback.

Could you please mark my answer that resolved your issue by selecting "Select as best". This will help other users find that answer faster.

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.