cancel
Showing results for 
Search instead for 
Did you mean: 

FDCAN interrupt not working

PPopo.1
Senior

Hello,

 

I am trying to use FDCAN but for some reason interrupt is not triggering. Im using PEAK CAN to send and recieve messages. With osciloscope I can see the data being transfared to the STM board but the interrupt doesn't trigger. The speed I want is 125 kbit/s . I've done this with the CAN before but with FDCAN just cant seem to figure it out.

I have enabled FDCAN1 interupt 0 in the NVIC with priority 5.

Any idea what should I check? I have a feeling that it might be the filter settings that are wrong but Im just not sure.

 

 

 

I've tried sending data to 0x11 and 0x22 but nothing happens. 

PPopo1_0-1721635882543.png

 

Filter and fdcan setup:

 

 

 

 

 

/* USER CODE END FDCAN1_Init 1 */
  hfdcan1.Instance = FDCAN1;
  hfdcan1.Init.ClockDivider = FDCAN_CLOCK_DIV1;
  hfdcan1.Init.FrameFormat = FDCAN_FRAME_CLASSIC;
  hfdcan1.Init.Mode = FDCAN_MODE_NORMAL;
  hfdcan1.Init.AutoRetransmission = ENABLE;
  hfdcan1.Init.TransmitPause = DISABLE;
  hfdcan1.Init.ProtocolException = DISABLE;
  hfdcan1.Init.NominalPrescaler = 12;
  hfdcan1.Init.NominalSyncJumpWidth = 1;
  hfdcan1.Init.NominalTimeSeg1 = 13;
  hfdcan1.Init.NominalTimeSeg2 = 2;
  hfdcan1.Init.DataPrescaler = 24;
  hfdcan1.Init.DataSyncJumpWidth = 1;
  hfdcan1.Init.DataTimeSeg1 = 13;
  hfdcan1.Init.DataTimeSeg2 = 2;
  hfdcan1.Init.StdFiltersNbr = 1;
  hfdcan1.Init.ExtFiltersNbr = 1;
  hfdcan1.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION;
  if (HAL_FDCAN_Init(&hfdcan1) != HAL_OK)
  {
    Error_Handler();
  }
  /* USER CODE BEGIN FDCAN1_Init 2 */

  //FDCAN1 FILTER

  FDCAN_FilterTypeDef sFilterConfig;

  sFilterConfig.IdType = FDCAN_STANDARD_ID; // Use standard IDs
  sFilterConfig.FilterIndex = 0;            // Filter index 0
  sFilterConfig.FilterType = FDCAN_FILTER_DUAL; // Use range filter
  sFilterConfig.FilterConfig = FDCAN_FILTER_TO_RXFIFO0; // Route accepted messages to RX FIFO 0
  sFilterConfig.FilterID1 = 0x11;          // Start of ID range
  sFilterConfig.FilterID2 = 0x22;          // End of ID range (standard ID max is 0x7FF)
  if (HAL_FDCAN_ConfigFilter(&hfdcan1, &sFilterConfig) != HAL_OK)
  {
    /* Filter configuration Error */
    Error_Handler();
  }

 

 

 

 

 

FDCAN defines:

 

 

 

 

 

    		// Configure TX Header for FDCAN1
    		TxHeader1.Identifier = 0x11;
    		TxHeader1.IdType = FDCAN_STANDARD_ID;
    		TxHeader1.TxFrameType = FDCAN_DATA_FRAME;
    		TxHeader1.DataLength = FDCAN_DLC_BYTES_12;
    		TxHeader1.ErrorStateIndicator = FDCAN_ESI_ACTIVE;
    		TxHeader1.BitRateSwitch = FDCAN_BRS_OFF;
    		TxHeader1.FDFormat = FDCAN_FD_CAN;
    		TxHeader1.TxEventFifoControl = FDCAN_NO_TX_EVENTS;
    		TxHeader1.MessageMarker = 0;

 

 

 

 

 

Callback function:

 

 

 

 

 

// FDCAN1 Callback
void HAL_FDCAN_RxFifo0Callback(FDCAN_HandleTypeDef *hfdcan, uint32_t RxFifo0ITs)
{
  if((RxFifo0ITs & FDCAN_IT_RX_FIFO0_NEW_MESSAGE) != RESET)
  {
    /* Retreive Rx messages from RX FIFO0 */
    if (HAL_FDCAN_GetRxMessage(hfdcan, FDCAN_RX_FIFO0, &RxHeader1, RxData1) != HAL_OK)
    {
    /* Reception Error */
    Error_Handler();
    }

    if (HAL_FDCAN_ActivateNotification(hfdcan, FDCAN_IT_RX_FIFO0_NEW_MESSAGE, 0) != HAL_OK)
    {
      /* Notification Error */
      Error_Handler();
    }
  }
}

 

 

 

 

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
PPopo.1
Senior

So the solution was that when running sys tick with TIM 6 you have to change priority from 15 (default) to something lower otherwise it wont work... Also ControllersTech example tutorial and also older version of STM32 examples are not mentioning GLOBAL FILTER, which you also have to use.

View solution in original post

14 REPLIES 14
SofLit
ST Employee

Hello,

You didn't tell what product you are using?

I suggest first to start with Loopback mode before Normal mode to discard any connection or HW issues.

See also this article.

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.

I am using STM32H7S7L8 discovery board. Good idea, Ill get back to you after I do that.

So I have connected the LoopBack. The interrupt works fine. In the Callback function I can see the TxBuffer changing but the RxBuffer doesn't update. When I meassure with osciloscope I get nothing on the Rx and Tx fdcan pins. I dont have the transciever connected to the Tx and Rx, should I have done it ? 

PPopo1_0-1721647987654.png

 

 

Callback function:

void HAL_FDCAN_RxFifo0Callback(FDCAN_HandleTypeDef *hfdcan, uint32_t RxFifo0ITs)
{
  if((RxFifo0ITs & FDCAN_IT_RX_FIFO0_NEW_MESSAGE) != RESET)
  {
    /* Retreive Rx messages from RX FIFO0 */
    if (HAL_FDCAN_GetRxMessage(hfdcan, FDCAN_RX_FIFO0, &RxHeader, RxData) != HAL_OK)
    {
    /* Reception Error */
    Error_Handler();
    }

    if (HAL_FDCAN_ActivateNotification(hfdcan, FDCAN_IT_RX_FIFO0_NEW_MESSAGE, 0) != HAL_OK)
    {
      /* Notification Error */
      Error_Handler();
    }
  }
}

 

No need for a transceiver in Loop Back mode. 

Did you select External Loop Back mode? this is the mode where you can see the frames on Tx pin.

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.

Yes, I chose the external one

I don't have a full picture what you did. So please share your project in External Loopback mode so I can look at it and try it by tomorrow.

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.
PPopo.1
Senior

Okay thank you. This is the project. It should be pretty simple since I followed the controllerstech tutorial.

Thank you. Where is the ioc file? could you please repackage the zip with the ioc file?

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.
PPopo.1
Senior

Im sorry, TouchGFX auto generates it outside of the STM32cubeIDE folder, didn't even notice.