cancel
Showing results for 
Search instead for 
Did you mean: 

STM32H743ZI CAN BUS Does Not Work

avarekeci
Associate

I have two STM32H743ZI NUCLEO Boards and I'm trying to communicate through Can Bus protocol in classic mode. In the H7 example projects, there is not an Can example for STM32H743ZI but I tried to adapt example of STM32H743I-EVAL FDCAN project but I couldn't success. How can I solve this? Anyone has tested can config for this board? By the way, I use STM32CubeMX .

2 REPLIES 2
KModi.1074
Associate II

I am facing the same issue. Here is my initialization code.

static void MX_FDCAN1_Init(void)

{

FDCAN_FilterTypeDef sFilterConfig;

 /* 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.ttcan = NULL;

 hfdcan1.Init.FrameFormat = FDCAN_FRAME_CLASSIC;

 hfdcan1.Init.Mode = FDCAN_MODE_NORMAL;

 //hfdcan1.Init.Mode = FDCAN_MODE_BUS_MONITORING;

 //hfdcan1.Init.Mode = FDCAN_MODE_INTERNAL_LOOPBACK;

 //hfdcan1.Init.Mode = FDCAN_MODE_EXTERNAL_LOOPBACK;

 hfdcan1.Init.AutoRetransmission = DISABLE;

 hfdcan1.Init.TransmitPause = DISABLE;

 hfdcan1.Init.ProtocolException = DISABLE;

 hfdcan1.Init.NominalPrescaler = (128);

 hfdcan1.Init.NominalSyncJumpWidth = 2;

 hfdcan1.Init.NominalTimeSeg1 = 16;

 hfdcan1.Init.NominalTimeSeg2 = 8;

 /*

 hfdcan1.Init.DataPrescaler = 1;

 hfdcan1.Init.DataSyncJumpWidth = 1;

 hfdcan1.Init.DataTimeSeg1 = 1;

 hfdcan1.Init.DataTimeSeg2 = 1;

 */

 hfdcan1.Init.MessageRAMOffset = 0;

 hfdcan1.Init.StdFiltersNbr = 0;

 hfdcan1.Init.ExtFiltersNbr = 0;

 hfdcan1.Init.RxFifo0ElmtsNbr = 2;

 hfdcan1.Init.RxFifo0ElmtSize = FDCAN_DATA_BYTES_8;

 hfdcan1.Init.RxFifo1ElmtsNbr = 0;

 hfdcan1.Init.RxFifo1ElmtSize = FDCAN_DATA_BYTES_8;

 hfdcan1.Init.RxBuffersNbr = 0;

 hfdcan1.Init.RxBufferSize = FDCAN_DATA_BYTES_8;

 hfdcan1.Init.TxEventsNbr = 0;

 hfdcan1.Init.TxBuffersNbr = 0;

 hfdcan1.Init.TxFifoQueueElmtsNbr = 16;

 hfdcan1.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION;

 hfdcan1.Init.TxElmtSize = FDCAN_DATA_BYTES_8;

 if (HAL_FDCAN_Init(&hfdcan1) != HAL_OK)

 {

  Error_Handler();

  HAL_Delay(100);

  HAL_UART_Transmit_IT(&huart2,(uint8_t *)"Init Failed\r\n",13);

 }

 else

 {

  HAL_Delay(100);

  HAL_UART_Transmit_IT(&huart2,(uint8_t *)"Init Success\r\n",14);

 }

 /* Configure Rx filter */

  sFilterConfig.IdType = FDCAN_STANDARD_ID;

  sFilterConfig.FilterIndex = 0;

  sFilterConfig.FilterType = FDCAN_FILTER_MASK;

  sFilterConfig.FilterConfig = FDCAN_FILTER_TO_RXFIFO0;

  sFilterConfig.FilterID1 = 0x111;

  //sFilterConfig.FilterID2 = 0x7FF; /* For acceptance, MessageID and FilterID1 must match exactly */

  sFilterConfig.FilterID2 = 0x0;

  HAL_FDCAN_ConfigFilter(&hfdcan1, &sFilterConfig);

  /* Configure global filter to reject all non-matching frames */

  //HAL_FDCAN_ConfigGlobalFilter(&hfdcan1, FDCAN_REJECT, FDCAN_REJECT, FDCAN_REJECT_REMOTE, FDCAN_REJECT_REMOTE);

  /* Configure Rx FIFO 0 watermark to 2 */

  HAL_FDCAN_ConfigFifoWatermark(&hfdcan1, FDCAN_CFG_RX_FIFO0, 1);

  /* Start the FDCAN module */

     if(HAL_FDCAN_Start(&hfdcan1) != HAL_OK)

     {

       HAL_Delay(100);

       HAL_UART_Transmit_IT(&huart2,(uint8_t *)"Start Failed\r\n",14);

     }

     else

     {

       HAL_Delay(100);

       HAL_UART_Transmit_IT(&huart2,(uint8_t *)"Start Success\r\n",15);

     }

  /* Activate Rx FIFO 0 watermark notification */

  HAL_FDCAN_ActivateNotification(&hfdcan1, FDCAN_IT_RX_FIFO0_WATERMARK | FDCAN_IT_TX_COMPLETE, 0);

  /* Prepare Tx Header */

   TxHeader.Identifier = 0xFF;

   TxHeader.IdType = FDCAN_STANDARD_ID;

   TxHeader.TxFrameType = FDCAN_DATA_FRAME;

   TxHeader.DataLength = FDCAN_DLC_BYTES_1;

   TxHeader.ErrorStateIndicator = FDCAN_ESI_ACTIVE;

   TxHeader.BitRateSwitch = FDCAN_BRS_OFF;

   TxHeader.FDFormat = FDCAN_CLASSIC_CAN;

   TxHeader.TxEventFifoControl = FDCAN_NO_TX_EVENTS;

   TxHeader.MessageMarker = 0;

 /* USER CODE BEGIN FDCAN1_Init 2 */

 /* USER CODE END FDCAN1_Init 2 */

}

Please let me know if I am doing something wrong.

https://community.st.com/s/question/0D50X0000BaMTRaSQO/stm32h743zi-can-not-working

So I don't have to dig for the linkage later.

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