cancel
Showing results for 
Search instead for 
Did you mean: 

I am working on communication between STM32H735(STM32H735G-DK) and STM32H745(STM32H745I-Disco) via FDCAN according to the official tutorial( he used different MCUs). But I couldn't receive any message by RxData, any idea?

Acecream
Associate II

Here is the software setting:

For STM32H735(STM32H745 is the same but with different ID):

-Defines:

/* USER CODE BEGIN PV */

FDCAN_TxHeaderTypeDef TxHeader;

FDCAN_RxHeaderTypeDef RxHeader;

uint8_t TxData_Node1_To_Node2[] = {0x10, 0x32, 0x54, 0x76, 0x98, 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66};

uint8_t RxData_From_Node2[12];

/* USER CODE END PV */

-FDCAN:  

hfdcan1.Instance = FDCAN1;

 hfdcan1.Init.FrameFormat = FDCAN_FRAME_FD_BRS;

 hfdcan1.Init.Mode = FDCAN_MODE_NORMAL;

 hfdcan1.Init.AutoRetransmission = ENABLE;

 hfdcan1.Init.TransmitPause = DISABLE;

 hfdcan1.Init.ProtocolException = DISABLE;

 hfdcan1.Init.NominalPrescaler = 1;

 hfdcan1.Init.NominalSyncJumpWidth = 13;

 hfdcan1.Init.NominalTimeSeg1 = 86;

 hfdcan1.Init.NominalTimeSeg2 = 13;

 hfdcan1.Init.DataPrescaler = 2;

 hfdcan1.Init.DataSyncJumpWidth = 12;

 hfdcan1.Init.DataTimeSeg1 = 12;

 hfdcan1.Init.DataTimeSeg2 = 12;

 hfdcan1.Init.MessageRAMOffset = 0;

 hfdcan1.Init.StdFiltersNbr = 1;

 hfdcan1.Init.ExtFiltersNbr = 0;

 hfdcan1.Init.RxFifo0ElmtsNbr = 1;

 hfdcan1.Init.RxFifo0ElmtSize = FDCAN_DATA_BYTES_12;

 hfdcan1.Init.RxFifo1ElmtsNbr = 0;

 hfdcan1.Init.RxFifo1ElmtSize = FDCAN_DATA_BYTES_8;

 hfdcan1.Init.RxBuffersNbr = 0;

 hfdcan1.Init.RxBufferSize = FDCAN_DATA_BYTES_12;

 hfdcan1.Init.TxEventsNbr = 0;

 hfdcan1.Init.TxBuffersNbr = 1;

 hfdcan1.Init.TxFifoQueueElmtsNbr = 0;

 hfdcan1.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION;

 hfdcan1.Init.TxElmtSize = FDCAN_DATA_BYTES_12;

 if (HAL_FDCAN_Init(&hfdcan1) != HAL_OK)

 {

  Error_Handler();

}

-Filter:

FDCAN_FilterTypeDef sFilterConfig;

  sFilterConfig.IdType = FDCAN_STANDARD_ID;

  sFilterConfig.FilterIndex = 0;

 #if 0

  sFilterConfig.FilterType = FDCAN_FILTER_DUAL; // Ignore because FDCAN_FILTER_TO_RXBUFFER

 #endif

  sFilterConfig.FilterConfig = FDCAN_FILTER_TO_RXBUFFER;

  sFilterConfig.FilterID1 = 0x2; // ID Node2

 #if 0

  sFilterConfig.FilterID2 = 0x0; // Ignore because FDCAN_FILTER_TO_RXBUFFER

 #endif

  sFilterConfig.RxBufferIndex = 0;

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

  {

   Error_Handler();

  }

-Tx Header & send Message:

 /* USER CODE BEGIN 2 */

 /* Configure Tx buffer message */

  TxHeader.Identifier = 0x1;

  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_ON;

  TxHeader.FDFormat = FDCAN_FD_CAN;

  TxHeader.TxEventFifoControl = FDCAN_NO_TX_EVENTS;

  TxHeader.MessageMarker = 0x0; // Ignore because FDCAN_NO_TX_EVENTS

  if(HAL_FDCAN_AddMessageToTxBuffer(&hfdcan1, &TxHeader, TxData_Node1_To_Node2, FDCAN_TX_BUFFER0) != HAL_OK)

  {

   Error_Handler();

  }

  /* Start the FDCAN module */

  if(HAL_FDCAN_Start(&hfdcan1) != HAL_OK)

  {

   Error_Handler();

  }

  /* Send Tx buffer message */

  if(HAL_FDCAN_EnableTxBufferRequest(&hfdcan1, FDCAN_TX_BUFFER0) != HAL_OK)

  {

   Error_Handler();

  }

  /* Polling for transmission complete on buffer index 0 */

  while(HAL_FDCAN_IsTxBufferMessagePending(&hfdcan1, FDCAN_TX_BUFFER0) == 1);

  /* Polling for reception complete on buffer index 0 */

  while(HAL_FDCAN_IsRxBufferMessageAvailable(&hfdcan1, FDCAN_RX_BUFFER0) == 0);

  /* Retrieve message from Rx buffer 0. Rec msg from Node 2 */

  if(HAL_FDCAN_GetRxMessage(&hfdcan1, FDCAN_RX_BUFFER0, &RxHeader, RxData_From_Node2) != HAL_OK)

  {

   Error_Handler();

  }

As for hardware, I am using FDCAN1 on both board, and also connected STLK as told from the instraction.

0 REPLIES 0