2021-06-25 01:35 AM
I am having trouble establishing stable communication between the FDCAN on the NUCLEO-H755ZI and CAN 2.0 on the NUCLEO-F446RE. The transceivers it uses are SN65HVD230.
During communication (regardless of the 1 / s, 10 ... 100 / s message sending intervals), not all messages are received by both systems. Nevertheless, on F4 fewer frames do not reach, on H7, despite sending 1 / s message, sometimes a few frames in a row fail. On the analyzer I can see that some lost frames have ACK and do not arrive and some have ERROR after CRC and also do not arrive. The times of the bits are the same for both those sent by H7 and F4.
Tested various transmission speeds of 1Mb / s, 500kb / s.
The clock for the FDCAN is set to 40Mhz, the same is set for the NUCLEO-F446RE. Bit timings configured the same on both boards (prescalery, syncjump, bit1seg, bit2seg), other configurations also tested.
Transceivers tested on two NUCLEO-F446RE. All sent frames are received.
I configured the FDCAN in normal mode with support for classic Can frames.
void MX_FDCAN1_Init(void)
{
/* USER CODE END FDCAN1_Init 1 */
hfdcan1.Instance = FDCAN1;
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 = 5;
hfdcan1.Init.NominalSyncJumpWidth = 1;
hfdcan1.Init.NominalTimeSeg1 = 13;
hfdcan1.Init.NominalTimeSeg2 = 2;
hfdcan1.Init.MessageRAMOffset = 0;
hfdcan1.Init.StdFiltersNbr = 0;
hfdcan1.Init.ExtFiltersNbr = 0;
hfdcan1.Init.RxFifo0ElmtsNbr = 10;
hfdcan1.Init.RxFifo0ElmtSize = FDCAN_DATA_BYTES_8;
hfdcan1.Init.RxFifo1ElmtsNbr = 2;
hfdcan1.Init.RxFifo1ElmtSize = FDCAN_DATA_BYTES_8;
hfdcan1.Init.RxBuffersNbr = 1;
hfdcan1.Init.RxBufferSize = FDCAN_DATA_BYTES_8;
hfdcan1.Init.TxEventsNbr = 10;
hfdcan1.Init.TxBuffersNbr = 10;
hfdcan1.Init.TxFifoQueueElmtsNbr = 10;
hfdcan1.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION;
hfdcan1.Init.TxElmtSize = FDCAN_DATA_BYTES_8;
if (HAL_FDCAN_Init(&hfdcan1) != HAL_OK)
{
Error_Handler();
}
HAL_FDCAN_ConfigGlobalFilter(&hfdcan1, FDCAN_ACCEPT_IN_RX_FIFO0,
FDCAN_ACCEPT_IN_RX_FIFO0, FDCAN_FILTER_REMOTE, FDCAN_FILTER_REMOTE);
HAL_FDCAN_Start(&hfdcan1);
HAL_FDCAN_EnableTxBufferRequest(&hfdcan1, FDCAN_TX_BUFFER0);
HAL_FDCAN_ActivateNotification(&hfdcan1, FDCAN_IT_RX_FIFO0_NEW_MESSAGE, FDCAN_RX_FIFO0);
HAL_FDCAN_ConfigInterruptLines(&hfdcan1, FDCAN_IT_RX_FIFO0_NEW_MESSAGE, FDCAN_INTERRUPT_LINE0);
NVIC_EnableIRQ(FDCAN1_IT0_IRQn);
}
CAN2.0 on F4 initlalization code:
void MX_CAN1_Init(void)
{
hcan1.Instance = CAN1;
hcan1.Init.Prescaler = 5;
hcan1.Init.Mode = CAN_MODE_NORMAL;
hcan1.Init.SyncJumpWidth = CAN_SJW_1TQ;
hcan1.Init.TimeSeg1 = CAN_BS1_13TQ;
hcan1.Init.TimeSeg2 = CAN_BS2_2TQ;
hcan1.Init.TimeTriggeredMode = DISABLE;
hcan1.Init.AutoBusOff = DISABLE;
hcan1.Init.AutoWakeUp = DISABLE;
hcan1.Init.AutoRetransmission = DISABLE;
hcan1.Init.ReceiveFifoLocked = DISABLE;
hcan1.Init.TransmitFifoPriority = DISABLE;
if (HAL_CAN_Init(&hcan1) != HAL_OK)
{
Error_Handler();
}
CAN_FilterTypeDef can1_filter;
can1_filter.FilterMode = CAN_FILTERMODE_IDMASK;
can1_filter.FilterBank = 0;
can1_filter.FilterFIFOAssignment = CAN_FILTER_FIFO0;
uint16_t filter_id = 0;
const uint16_t filter_mask = 0;
can1_filter.FilterIdHigh = (filter_id << 5);
can1_filter.FilterIdLow = 0;
can1_filter.FilterMaskIdHigh = (filter_mask << 5);
can1_filter.FilterMaskIdLow = 0;
can1_filter.FilterScale = CAN_FILTERSCALE_32BIT;
can1_filter.FilterActivation = ENABLE;
HAL_CAN_ConfigFilter(&hcan1, &can1_filter);
HAL_CAN_Start(&hcan1);
HAL_CAN_ActivateNotification(&hcan1, CAN_IT_RX_FIFO0_MSG_PENDING);
NVIC_EnableIRQ(CAN1_RX0_IRQn);
}