cancel
Showing results for 
Search instead for 
Did you mean: 

Using a FDCAN controller with a CAN transciever (NUCLEO-G431KB)

Mysterious Wolf
Associate II

I have a source of can messages connected to the SN65HVD232D CAN controller, which is then wired to a NUCLEO-G431KB via the FDCAN1 TX and RX pins. I confirmed with an oscilloscope/digital decoder that the transceiver does indeed output valid CAN messages, but the interrupt never triggers. This is the setup I use in an attempt to receive classic CAN messages using the hardware I have:

0693W00000NqahWQAR.png 

These are the settings in STM32CubeMX:

0693W00000NqahbQAB.png 

This is the code these settings generate in the form of an init function that is called in the init section for those who don't use the "wizard", but still use the STM32 HAL:

   hfdcan1.Instance = FDCAN1;
 
     hfdcan1.Init.ClockDivider = FDCAN_CLOCK_DIV24;
 
     hfdcan1.Init.FrameFormat = FDCAN_FRAME_CLASSIC;
 
     hfdcan1.Init.Mode = FDCAN_MODE_NORMAL;
 
     hfdcan1.Init.AutoRetransmission = DISABLE;
 
     hfdcan1.Init.TransmitPause = DISABLE;
 
     hfdcan1.Init.ProtocolException = DISABLE;
 
     hfdcan1.Init.NominalPrescaler = 1;
 
     hfdcan1.Init.NominalSyncJumpWidth = 1;
 
     hfdcan1.Init.NominalTimeSeg1 = 2;
 
     hfdcan1.Init.NominalTimeSeg2 = 2;
 
     hfdcan1.Init.DataPrescaler = 1;
 
     hfdcan1.Init.DataSyncJumpWidth = 1;
 
     hfdcan1.Init.DataTimeSeg1 = 1;
 
     hfdcan1.Init.DataTimeSeg2 = 1;
 
     hfdcan1.Init.StdFiltersNbr = 0;
 
     hfdcan1.Init.ExtFiltersNbr = 0;
 
     hfdcan1.Init.TxFifoQueueMode = FDCAN_TX_QUEUE_OPERATION;
 
     if (HAL_FDCAN_Init(&hfdcan1) != HAL_OK)
 
     {
 
       Error_Handler();
 
     }

I then initialize the filters that should allow every packet to get through (which doesn't print any errors):

   FDCAN_FilterTypeDef sFilterConfig;
 
   sFilterConfig.IdType = FDCAN_STANDARD_ID;
 
   sFilterConfig.FilterIndex = 0;
 
   sFilterConfig.FilterType = FDCAN_FILTER_RANGE;
 
   sFilterConfig.FilterConfig = FDCAN_FILTER_TO_RXFIFO0;
 
   sFilterConfig.FilterID1 = 0;
 
   sFilterConfig.FilterID2 = 0x1FFFFFFF;
 
 
   if (HAL_FDCAN_ConfigFilter(&hfdcan1, &sFilterConfig) != HAL_OK) {
 
      /* Filter configuration Error */
 
      printf("[CAN] Unable to configure!\n");
 
   }
 
 
   if (HAL_FDCAN_Start(&hfdcan1) != HAL_OK) {
 
      /* Start Error */
 
      printf("[CAN] Unable to start!\n");
 
   }
 
 
   if (HAL_FDCAN_ActivateNotification(&hfdcan1, FDCAN_IT_RX_FIFO0_NEW_MESSAGE, 0) != HAL_OK) {
 
      /* Notification Error */
 
      printf("[CAN] Unable to activate the CAN interrupt!\n");
 
   }

As well as the interrupt function with a simple breakpoint (in Keil) to indicate any interrupt calls:

   void HAL_FDCAN_RxFifo0Callback(FDCAN_HandleTypeDef *hfdcan, uint32_t RxFifo0ITs) {
 
     __breakpoint(0);
 
   }

From what I've read in the brief FDCAN peripheral overview by ST, there should be no problem receiving CAN 2.0 packets, yet my attempts don't seem to yield any results. Any help would be greatly appreciated!

1 ACCEPTED SOLUTION

Accepted Solutions
SofLit
ST Employee

Also I'm wondering why you are using these values:

Prescaler = 24

Nominal bit time Seg1/Seg2 = 2

Data bit time Seg1/Seg2 = 1 !!!!

Please decrease as much as possible the prescaler and increase as much as possible Nominal and data time segs to fit your bit rate.

Please refer to this thread:

https://community.st.com/s/question/0D53W00001TeTPvSAN/can-anyone-help-me-with-my-project-using-a-stm32f103-and-a-can-transceiver-i-cant-make-it-work

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

5 REPLIES 5
SofLit
ST Employee

Hello,

There is no issue if your FDCAN transmission doesn't exceed 1MB/s either for Nominal or Data rates.

From SN65HVD23x datasheet:

0693W00000NqdWbQAJ.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.
SofLit
ST Employee

Also I'm wondering why you are using these values:

Prescaler = 24

Nominal bit time Seg1/Seg2 = 2

Data bit time Seg1/Seg2 = 1 !!!!

Please decrease as much as possible the prescaler and increase as much as possible Nominal and data time segs to fit your bit rate.

Please refer to this thread:

https://community.st.com/s/question/0D53W00001TeTPvSAN/can-anyone-help-me-with-my-project-using-a-stm32f103-and-a-can-transceiver-i-cant-make-it-work

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.
Mysterious Wolf
Associate II

Hi,

I've changed my timings to match my transceiver and other nodes (which are all operating at fixed 1 Mbps) without success. My core clock is 170 MHz.

These are the values I tried

  • First, I tried setting the nominal and data rates both to rates that work with a normal CAN controller (PS: 10, SJW: 1, SEQ1: 14, SEQ2: 2) with a sample point of 88%
  • Then I tried using it with values that should work with a FD CAN controller with nominal rates on PS: 1, SJW: 30, SEQ1: 139, SEQ2: 30 and data rates at PS:10, SJW: 3, SEQ1: 13, SEQ2: 3 (sample points at 82% for nominal and 52% for data rates)
  • Lastly I tried a matching sample point at 82% with PS: 1, SJW: 30, SEQ1: 139, SEQ2: 30 and data rates at PS:10, SJW: 8, SEQ1: 8, SEQ2: 8.

None of these seem to yield any results. There is no error code in the FDCAN handle instance and its "State" is always in "HAL_FDCAN_STATE_BUSY". Is this normal, or should it be in "HAL_FDCAN_STATE_READY"?

I've also tested the can controller with the loopback mode and it does indeed return all the packages it gets, so I'm guessing this isn't an issue with the filters, but I'm still doing something wrong with the timing.

I mistakenly believed all nodes operated at 1 Mbps while in reality they operated at 250 kbps, so changing the timings was indeed the correct solution. Thank you!

kriha.1
Associate

Hi,

you must check if the FDCAN1 Interrupt 0 is active or not

0693W00000QL5PgQAL.pngthe following lines must be present on stm32g4xxx_hal_msp.c file

  /* FDCAN1 interrupt Init */

  HAL_NVIC_SetPriority(FDCAN1_IT0_IRQn, 0, 0);

  HAL_NVIC_EnableIRQ(FDCAN1_IT0_IRQn);

  HAL_NVIC_SetPriority(FDCAN1_IT1_IRQn, 0, 0);

  HAL_NVIC_EnableIRQ(FDCAN1_IT1_IRQn);

 /* USER CODE BEGIN FDCAN1_MspInit 1 */