2020-06-05 03:58 AM
1) FDCAN init is loopback mode, the config as follow:
/* USER CODE BEGIN FDCAN1_Init 0 */
/* USER CODE END FDCAN1_Init 0 */
/* USER CODE BEGIN FDCAN1_Init 1 */
HAL_FDCAN_DeInit(&hfdcan1);
/* USER CODE END FDCAN1_Init 1 */
hfdcan1.Instance = FDCAN1;
hfdcan1.Init.FrameFormat = FDCAN_FRAME_CLASSIC;
hfdcan1.Init.Mode = FDCAN_MODE_INTERNAL_LOOPBACK;
hfdcan1.Init.AutoRetransmission = DISABLE;
hfdcan1.Init.TransmitPause = DISABLE;
hfdcan1.Init.ProtocolException = DISABLE;
hfdcan1.Init.NominalPrescaler = 4;//80M/4 = 20M -> 50ns
hfdcan1.Init.NominalSyncJumpWidth = 8;//canbaudrate = 80M/prescale/(seg1+seg2+1) = 80/2/(23+8+8+1) = 500K
hfdcan1.Init.NominalTimeSeg1 = 31;
hfdcan1.Init.NominalTimeSeg2 = 8;
hfdcan1.Init.DataPrescaler = 4;
hfdcan1.Init.DataSyncJumpWidth = 8;
hfdcan1.Init.DataTimeSeg1 = 31;
hfdcan1.Init.DataTimeSeg2 = 8;
hfdcan1.Init.MessageRAMOffset = 0;
hfdcan1.Init.StdFiltersNbr = 1;
hfdcan1.Init.ExtFiltersNbr = 0;
hfdcan1.Init.RxFifo0ElmtsNbr = 1;
hfdcan1.Init.RxFifo0ElmtSize = FDCAN_DATA_BYTES_8;
hfdcan1.Init.RxFifo1ElmtsNbr = 1;
hfdcan1.Init.RxFifo1ElmtSize = FDCAN_DATA_BYTES_8;
hfdcan1.Init.RxBuffersNbr = 1;
hfdcan1.Init.RxBufferSize = FDCAN_DATA_BYTES_8;
hfdcan1.Init.TxEventsNbr = 0;
hfdcan1.Init.TxBuffersNbr = 1;
hfdcan1.Init.TxFifoQueueElmtsNbr = 1;
hfdcan1.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION;
hfdcan1.Init.TxElmtSize = FDCAN_DATA_BYTES_8;
if (HAL_FDCAN_Init(&hfdcan1) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN FDCAN1_Init 2 */
FDCAN_FilterTypeDef can_filter = {0};
can_filter.IdType = FDCAN_STANDARD_ID;
can_filter.FilterIndex = 0;
can_filter.FilterType = FDCAN_FILTER_MASK;
can_filter.FilterConfig = FDCAN_FILTER_TO_RXFIFO0;
can_filter.FilterID1 = 1; //only receive ID=1 from RxFIFO0
can_filter.FilterID2 = 1;
if (HAL_OK != HAL_FDCAN_ConfigFilter(&hfdcan1,&can_filter))
{
printf("\r\n fdcan1 filter failed.");
return;
}
if (HAL_OK != HAL_FDCAN_ConfigGlobalFilter(&hfdcan1, FDCAN_REJECT, FDCAN_REJECT, ENABLE, ENABLE))
{//filter global enable
printf("\r\n fdcan filter enable failed.");
return;
}
if (HAL_OK != HAL_FDCAN_Start(&hfdcan1))
{
printf("\r\n fdcan1 start failed.");
return;
}
2) FDCAN1 send test as below:
int FDCAN1_TXTest(void)
{
FDCAN_TxHeaderTypeDef can_txheader = {0};
unsigned char i;
unsigned char can_txdata[8] = {0};
unsigned int ret;
can_txheader.Identifier = 0x123;
can_txheader.IdType = FDCAN_STANDARD_ID;
can_txheader.TxFrameType = FDCAN_DATA_FRAME;
can_txheader.FDFormat = FDCAN_CLASSIC_CAN;
can_txheader.ErrorStateIndicator = FDCAN_ESI_ACTIVE;
can_txheader.BitRateSwitch = FDCAN_BRS_OFF;
can_txheader.DataLength =FDCAN_DLC_BYTES_8;//
can_txheader.TxEventFifoControl = FDCAN_NO_TX_EVENTS;
can_txheader.MessageMarker = 0;
memset((char *)can_txdata, 0x55, sizeof(can_txdata));
ret = HAL_FDCAN_AddMessageToTxFifoQ(&hfdcan1, &can_txheader, can_txdata);
if (HAL_OK == ret)
{
printf("\r\n can1 tx(len = %d) ok:", (can_txheader.DataLength>>16));
for (i = 0;i < (can_txheader.DataLength>>16);i++)
{
if ((i % 8) == 0) printf("\r\n");
printf("%02x ", can_txdata[i]);
}
return 0;
}
else
{
printf("\r\n can1 send err(0x%x), ErrorCode = 0x%x , state = 0x%x", ret, hfdcan1.ErrorCode, hfdcan1.State);-------The probelm is here, this printf is on.
return 1;
}
}
The return is not OK. The value is 0x200 that means "HAL_FDCAN_ERROR_FIFO_FULL". Please help us, thanks a lot.
2020-06-05 04:52 AM
Hi,
Do You have function for receive data from CAN1?
2020-06-05 05:18 AM
Hi, thanks for your anwser firstly. In the beginning, we try to send one packet and receive packet in the normal mode, then find the erorr. So we try only to send without receive in the loopback mode, but this probelm is still on.
2020-06-07 06:09 PM
Hi, anyone would help us ?
2021-02-04 03:44 AM
Hi, did you find the problem? I'm facing the same issue with the STM32H743I-Eval2 board.