cancel
Showing results for 
Search instead for 
Did you mean: 

CAN Communication: Can't Receive Message

KMew
Senior III

I am attempting to use my STM32H7B3I-EVAL evaluation board to send and receive CAN communication messages. I am communicating with a Vector CANalayzer (16.0, VN1630A). The CANalyzer is being used both to display messages received from the evaluation board, as well as transmit its own data and send it to the evaluation board.

I am currently running the following C code attached to this.

The CANalyzer sees the data that is being sent in the bode for lines 111-138 in the code. However, when I try to receive data from the CANalyzer and make an LED blink on the evaluation board, it does not work.

CANalyzer settings:

0693W00000Svp2xQAB.png0693W00000Svp3MQAR.png 

0693W00000Svp2BQAR.png 

The data I'm sending from the CANalyzer:

Message ID: 0x123

Data Length: 8

Data: Alternates between 0x2233445566778899 to 0x1223344556677889 every 2 seconds

I'm unsure why this code is successfully sending data to the CANalyzer but not receiving the data sent from it.

Have I not configured the Rx properly?

9 REPLIES 9
Javier1
Principal

are you using a canbus transceiver?

show us a picture of your setup

we dont need to firmware by ourselves, lets talk
KMew
Senior III

0693W00000Svp5SQAR.jpg 

Hello Javier,

Thank you for the response. I am using the built-in CANbus transceiver on the evaluation board. I am communicating to the CANalyzer via a DB9 cable, as shown in the picture. I have verified the wiring (since I am successfully sending data from the evaluation board to the CANalyzer)

Hello Javier0693W00000SvpupQAB.jpg,

Thank you for the response. I am using the built-in CANbus transceiver on the evaluation board. I am communicating to the CANalyzer via a DB9 cable, as shown in the picture. I have verified the wiring (since I am successfully sending data from the evaluation board to the CANalyzer)

>>Have I not configured the Rx properly?

Use Unique Filter numbers, that way they don't overwrite / replace each other.

Perhaps Have a broad/open one that catches every thing rather than be selective, until you have something working.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

Hello,

Thank you for the reply!

I apologize if this is an obvious question, but how do I make it more broad/open? What do I have to change, specifically?

  /* Configure Rx filter */
  sFilterConfig.IdType = FDCAN_STANDARD_ID;
  sFilterConfig.FilterIndex = 0; // Multiple, and different
  sFilterConfig.FilterType = FDCAN_FILTER_MASK;
  sFilterConfig.FilterConfig = FDCAN_FILTER_TO_RXFIFO0;
  sFilterConfig.FilterID1 = 0x000; // Compare == ?
  sFilterConfig.FilterID2 = 0x000; // Mask &=
  if (HAL_FDCAN_ConfigFilter(&hfdcan, &sFilterConfig) != HAL_OK)
  {
    /* Filter configuration Error */
    Error_Handler();
  }
 
...
 
  /* Start the FDCAN module */
  if (HAL_FDCAN_Start(&hfdcan) != HAL_OK)
  {
    /* Start Error */
    Error_Handler();
  }
 
  if (HAL_FDCAN_ActivateNotification(&hfdcan, FDCAN_IT_RX_FIFO0_NEW_MESSAGE, 0) != HAL_OK)
  {
    /* Notification Error */
    Error_Handler();
  }
...

Or perhaps looks at using HAL_FDCAN_ConfigGlobalFilter() ?

HAL_FDCAN_ConfigGlobalFilter(&hfdcan, FDCAN_ACCEPT_IN_RX_FIFO1, FDCAN_ACCEPT_IN_RX_FIFO0, FDCAN_REJECT_REMOTE, FDCAN_REJECT_REMOTE);

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

Hello,

I tried implementing line 1-27 of your code and I'm still getting the same result. I also tried using a different LED (LED2 instead of LED1). It still does not blink.

I have a couple follow-up questions:

a) I do run the LED initialization properly, correct?

 /* Configure LED1 and LED2 */

 BSP_LED_Init(LED1);

 BSP_LED_Init(LED2);

b) BSP_LED_Toggle(LEDx) switches the LED's current status, correct? In other words, if it's off, it'll turn it on. If it's on, it'll turn it off?

c) If I want to receive a message from the CANalyzer, is "HAL_FDCAN_GetRxMessage(&hfdcan1, FDCAN_RX_BUFFER0, &RxHeader, RxData);" the correct function to call?

This is the new implementation I have:

 CAN_Init();

 CAN_RxStdFilter_Init();

 //CAN_RxExtFilter_Init();

 CAN_TxFilter_Init();

 if (HAL_FDCAN_ConfigFilter(&hfdcan1, &sFilterConfig) != HAL_OK)

  {

   /* Filter configuration Error */

   Error_Handler();

  }

 /* Start the FDCAN module */

 HAL_FDCAN_Start(&hfdcan1);

 if (HAL_FDCAN_ActivateNotification(&hfdcan1, FDCAN_IT_RX_FIFO0_NEW_MESSAGE, 0) != HAL_OK)

  {

   /* Notification Error */

   Error_Handler();

  }

 /* Send Tx buffer message */

 HAL_FDCAN_EnableTxBufferRequest(&hfdcan1, FDCAN_TX_BUFFER0);

static void CAN_RxStdFilter_Init(){

 sFilterConfig.IdType = FDCAN_STANDARD_ID;

 sFilterConfig.FilterIndex = 0;

 sFilterConfig.FilterType = FDCAN_FILTER_MASK;

 sFilterConfig.FilterConfig = FDCAN_FILTER_TO_RXFIFO0;

 sFilterConfig.FilterID1 = 0x000;

 sFilterConfig.FilterID2 = 0x000;

 //sFilterConfig.RxBufferIndex = 0;

 HAL_FDCAN_ConfigFilter(&hfdcan1, &sFilterConfig);

}

I'd expect you'd need the appropriate call-back functions, and call-in functions in the IRQHandlers, and the NVIC / FDCAN interrupt(s) enabled.

Watch for errors/status to be flagged, clear / handle as necessary. Especially overflow/overrun type failures.

Watch for things enabled in the MSP code.

Watch for C++ / .CPP name mangling, and linkage of routines expected in final build.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

Are IRQHandlers required for receiving messages?

I did try to make a separate project in the CubeMX and enabled FDCAN1 Interrupt 0 enabled, but I don't see any generated interrupt functions anywhere.

Also, what's the best way to watch for error statuses? Does the IDE have something built in to do that?

(I apologize for obvious questions... This is all still very new for me)