cancel
Showing results for 
Search instead for 
Did you mean: 

CAN-Bus no callback/received frame; FDCAN STM32G473

MMoha.10
Associate III

I'm trying to attempt CAN on a STM32G473 MCU. While transmission seems to be fine, I'm not receiving any data back. The receive call back function is not triggering.

Following is my setup:


_legacyfs_online_stmicro_images_0693W00000bjJuuQAE.pngBelow is the TxHeader and RxHeader initialization along with the call back function. I have a breakpoint in the call-back function which never gets triggered.

FDCAN_TxHeaderTypeDef TxHeader;
FDCAN_RxHeaderTypeDef RxHeader;
 
//uint32_t TxMailbox;
 
uint8_t TxData[12];
uint8_t RxData[12];
int indx = 0;
 
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 */
	  HAL_GPIO_WritePin(GPIOB, GPIO_PIN_13, 1);
    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();
    }
  }
}

This is the TxHeader setup and FDCAN start :

  /* USER CODE BEGIN 2 */
 
  if(HAL_FDCAN_Start(&hfdcan1)!= HAL_OK)
  {
	  Error_Handler();
  }
  if (HAL_FDCAN_ActivateNotification(&hfdcan1, FDCAN_IT_RX_FIFO0_NEW_MESSAGE, 0) != HAL_OK)
    {
      /* Notification Error */
      Error_Handler();
    }
//  HAL_FDCAN_GetRxFifoFillLevel
 
  TxHeader.Identifier = 0x11;
  TxHeader.IdType = FDCAN_STANDARD_ID;
  TxHeader.TxFrameType = FDCAN_DATA_FRAME;
  TxHeader.DataLength = FDCAN_DLC_BYTES_12;
  TxHeader.ErrorStateIndicator = FDCAN_ESI_ACTIVE;
  TxHeader.BitRateSwitch = FDCAN_BRS_OFF;
  TxHeader.FDFormat = FDCAN_FD_CAN;
  TxHeader.TxEventFifoControl = FDCAN_NO_TX_EVENTS;
  TxHeader.MessageMarker = 0;
 
  /* USER CODE END 2 */

The data that is transmitted ever second, (part of the while loop):

	  for (int i=0; i <12; i++)
	  {
		  TxData[i] = indx++;
	  }
 
	  if (HAL_FDCAN_AddMessageToTxFifoQ(&hfdcan1, &TxHeader, TxData)!= HAL_OK)
	   {
	    Error_Handler();
	   }
//	  HAL_GPIO_WritePin(GPIOB, GPIO_PIN_13, 0);
 
	  HAL_Delay (1000);

My MX_FDCAN_Init() function :

static void MX_FDCAN1_Init(void)
{
 
  /* USER CODE BEGIN FDCAN1_Init 0 */
 
  /* USER CODE END FDCAN1_Init 0 */
 
  /* USER CODE BEGIN FDCAN1_Init 1 */
 
  /* 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 = DISABLE;
  hfdcan1.Init.TransmitPause = DISABLE;
  hfdcan1.Init.ProtocolException = DISABLE;
  hfdcan1.Init.NominalPrescaler = 2;
  hfdcan1.Init.NominalSyncJumpWidth = 16;
  hfdcan1.Init.NominalTimeSeg1 = 130;
  hfdcan1.Init.NominalTimeSeg2 = 19;
  hfdcan1.Init.DataPrescaler = 4;
  hfdcan1.Init.DataSyncJumpWidth = 8;
  hfdcan1.Init.DataTimeSeg1 = 11;
  hfdcan1.Init.DataTimeSeg2 = 8;
  hfdcan1.Init.StdFiltersNbr = 1;
  hfdcan1.Init.ExtFiltersNbr = 0;
  hfdcan1.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION;
  if (HAL_FDCAN_Init(&hfdcan1) != HAL_OK)
  {
    Error_Handler();
  }
  /* USER CODE BEGIN FDCAN1_Init 2 */
 
  FDCAN_FilterTypeDef sFilterConfig;
 
  sFilterConfig.IdType = FDCAN_STANDARD_ID;
  sFilterConfig.FilterIndex = 0;
  sFilterConfig.FilterType = FDCAN_FILTER_MASK;
  sFilterConfig.FilterConfig = FDCAN_FILTER_TO_RXFIFO0;
  sFilterConfig.FilterID1 = 0x11;
  sFilterConfig.FilterID2 = 0x11;
//  sFilterConfig.RxBufferIndex = 0;
    if (HAL_FDCAN_ConfigFilter(&hfdcan1, &sFilterConfig) != HAL_OK)
    {
      /* Filter configuration Error */
      Error_Handler();
    }
 
 
 
  /* USER CODE END FDCAN1_Init 2 */
 
}

Oscilloscope reading on the CANH CANL lines
_legacyfs_online_stmicro_images_0693W00000bjJx0QAE.pngI have gone through posts (Link1, Link 2) who had similar issues, and I'm not facing that issue. My Std Filters Nbr=1 and Interrupt is enabled.

I'm not sure what I'm missing. Any help is appreciated.

1 ACCEPTED SOLUTION

Accepted Solutions
MMoha.10
Associate III

Hi Slawek,

Thank you for getting back. I haven't tried your suggestion yet. But this worked out for me : https://github.com/mackelec/meFDCAN

View solution in original post

2 REPLIES 2
SKacp.1
Senior II
MMoha.10
Associate III

Hi Slawek,

Thank you for getting back. I haven't tried your suggestion yet. But this worked out for me : https://github.com/mackelec/meFDCAN