2019-11-07 11:10 AM
I am trying to use the STM32H743I-EVAL FDCAN_Com_IT example code to run CAN on STM32H743ZIT6. I am trying to transmit at regular intervals. When I look the signals on a scope, the TXD goes low for just a bit interval and then remains high. 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 do let me know if I am doing something wrong.
2019-11-07 11:56 AM
https://community.st.com/s/question/0D50X0000BJ1WupSQF/stm32h743zi-can-bus-does-not-work
2020-01-30 01:45 PM
Why set this:
"hfdcan1.Init.NominalPrescaler = (128);"
In my mind, the Prescaler never >=32.
Richard
2020-05-26 09:30 AM
did you get any solution ?
2020-06-05 02:26 AM
You should check if the EVAL board has all needed connections to the transceiver / bus. On the STM32H745ZI-Q board there is a solder bridge missing for CAN_TX or CAN_RX line. After soldering the pad my CAN project works! Maybe the H743 Eval board has the same 'problem'...
And why you use such a high prescaler? It's recommended to use the smallest possible prescaler for the CAN peripheral. I think the example project has a prescaler of 1 if you use FDCAN.