2024-04-17 05:34 AM - last edited on 2024-04-17 06:30 AM by SofLit
board:MB1549-U575ZIQ-C03 (mcu stm32U575)
I debug the FDCNA function with a CANalyst tool
1. Work at FDCAN_MODE_BUS_MONITORING mode, It can receive data from the CANalyst tool
2. Work at FDCAN_MODE_EXTERNAL_LOOPBACK,It can receive data itself and the canslyst tool can receive the data
3. Work at FDCAN_MODE_NORMAL, It cann't receive data,and send data fail
void MX_FDCAN1_Init(void)
{
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 = 32;
hfdcan1.Init.NominalSyncJumpWidth = 1;
hfdcan1.Init.NominalTimeSeg1 = 2;
hfdcan1.Init.NominalTimeSeg2 = 2;
hfdcan1.Init.DataPrescaler = 1;
hfdcan1.Init.DataSyncJumpWidth = 1;
hfdcan1.Init.DataTimeSeg1 = 1;
hfdcan1.Init.DataTimeSeg2 = 1;
hfdcan1.Init.StdFiltersNbr = 0;
hfdcan1.Init.ExtFiltersNbr = 0;
hfdcan1.Init.TxFifoQueueMode = FDCAN_TX_QUEUE_OPERATION;
if (HAL_FDCAN_Init(&hfdcan1) != HAL_OK)
{
Error_Handler();
}
#if 1
FDCAN_FilterTypeDef FDCAN1_RXFilter;
FDCAN1_RXFilter.IdType=FDCAN_STANDARD_ID;
FDCAN1_RXFilter.FilterIndex=0;
FDCAN1_RXFilter.FilterType=FDCAN_FILTER_RANGE;
FDCAN1_RXFilter.FilterConfig=FDCAN_FILTER_TO_RXFIFO0;
FDCAN1_RXFilter.FilterID1=0x0000;
FDCAN1_RXFilter.FilterID2=0x0000;
if(HAL_FDCAN_ConfigFilter(&hfdcan1,&FDCAN1_RXFilter)!=HAL_OK)
{
Error_Handler();
}
HAL_FDCAN_Start(&hfdcan1);
HAL_FDCAN_ActivateNotification(&hfdcan1,FDCAN_IT_RX_FIFO0_NEW_MESSAGE,0);
#endif
/* USER CODE END FDCAN1_Init 2 */
}
void HAL_FDCAN_MspInit(FDCAN_HandleTypeDef* fdcanHandle)
{
GPIO_InitTypeDef GPIO_InitStruct = {0};
RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
if(fdcanHandle->Instance==FDCAN1)
{
/* USER CODE BEGIN FDCAN1_MspInit 0 */
/* USER CODE END FDCAN1_MspInit 0 */
/** Initializes the peripherals clock
*/
PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_FDCAN1;
PeriphClkInit.Fdcan1ClockSelection = RCC_FDCAN1CLKSOURCE_PLL1;
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
{
Error_Handler();
}
/* FDCAN1 clock enable */
__HAL_RCC_FDCAN1_CLK_ENABLE();
__HAL_RCC_GPIOD_CLK_ENABLE();
/**FDCAN1 GPIO Configuration
PD0 ------> FDCAN1_RX
PD1 ------> FDCAN1_TX
*/
GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_PULLUP;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF9_FDCAN1;
HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
/* FDCAN1 interrupt Init */
HAL_NVIC_SetPriority(FDCAN1_IT0_IRQn, 4, 0);
HAL_NVIC_EnableIRQ(FDCAN1_IT0_IRQn);
/* USER CODE BEGIN FDCAN1_MspInit 1 */
/* USER CODE END FDCAN1_MspInit 1 */
}
}
uint8_t FDCAN1_Send_Msg(uint8_t* msg)
{
fdcan1_TxHeader.Identifier = 0x001;
fdcan1_TxHeader.IdType = FDCAN_STANDARD_ID;
fdcan1_TxHeader.TxFrameType = FDCAN_DATA_FRAME;
fdcan1_TxHeader.DataLength = FDCAN_DLC_BYTES_8;
fdcan1_TxHeader.ErrorStateIndicator = FDCAN_ESI_ACTIVE;
fdcan1_TxHeader.BitRateSwitch = FDCAN_BRS_OFF;
fdcan1_TxHeader.FDFormat = FDCAN_CLASSIC_CAN;
fdcan1_TxHeader.TxEventFifoControl = FDCAN_NO_TX_EVENTS;
fdcan1_TxHeader.MessageMarker = 0x52;
if(HAL_FDCAN_AddMessageToTxFifoQ(&hfdcan1,&fdcan1_TxHeader,msg)!=HAL_OK) return 1;//发送
return 0;
}
void HAL_FDCAN_RxFifo0Callback(FDCAN_HandleTypeDef *hfdcan, uint32_t RxFifo0ITs)
{
/* Prevent unused argument(s) compilation warning */
UNUSED(hfdcan);
UNUSED(RxFifo0ITs);
if((RxFifo0ITs & FDCAN_IT_RX_FIFO0_NEW_MESSAGE) != RESET)
{
/* Retrieve Rx messages from RX FIFO0 */
memset(RxData, 0, sizeof(RxData));
if (HAL_FDCAN_GetRxMessage(hfdcan, FDCAN_RX_FIFO0, &RxHeader, RxData) != HAL_OK)
{
Error_Handler();
}
}
}
Solved! Go to Solution.
2024-04-18 08:17 PM
Thand you for your reply
I find the cause of the problem
The transceiver need to power of 5V, but I only provide 3.3V
2024-04-17 05:37 AM
hfdcan1.Init.Mode = FDCAN_MODE_NORMAL; // can not work
hfdcan1.Init.Mode = FDCAN_MODE_BUS_MONITORING; // work well
hfdcan1.Init.Mode = FDCAN_MODE_EXTERNAL_LOOPBACK; // work well
2024-04-17 06:30 AM
Hello,
hfdcan1.Init.NominalPrescaler = 32;
hfdcan1.Init.NominalTimeSeg1 = 2;
hfdcan1.Init.NominalTimeSeg2 = 2
See my answer in this thread.
2024-04-17 06:07 PM
Are you using a transceiver with another CAN node connected to the bus?
1. had can transceiver
2024-04-17 06:08 PM
work at FDCAN_MODE_BUS_MONITORING or FDCAN_MODE_EXTERNAL_LOOPBACK ,It can receive or send data
2024-04-17 07:15 PM
2024-04-17 07:16 PM - last edited on 2024-04-18 03:36 AM by SofLit
I change below,but it doesn't work too
hfdcan1.Instance = FDCAN1;
hfdcan1.Init.ClockDivider = FDCAN_CLOCK_DIV10;
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 = 1;
hfdcan1.Init.NominalTimeSeg1 = 12;
hfdcan1.Init.NominalTimeSeg2 = 3;
hfdcan1.Init.DataPrescaler = 1;
hfdcan1.Init.DataSyncJumpWidth = 1;
hfdcan1.Init.DataTimeSeg1 = 1;
hfdcan1.Init.DataTimeSeg2 = 1;
hfdcan1.Init.StdFiltersNbr = 0;
hfdcan1.Init.ExtFiltersNbr = 0;
2024-04-18 03:21 AM - edited 2024-04-18 03:40 AM
Hello,
PS: please use </> button to insert your code.
2024-04-18 08:17 PM
Thand you for your reply
I find the cause of the problem
The transceiver need to power of 5V, but I only provide 3.3V