2022-05-24 01:15 PM
I have a source of can messages connected to the SN65HVD232D CAN controller, which is then wired to a NUCLEO-G431KB via the FDCAN1 TX and RX pins. I confirmed with an oscilloscope/digital decoder that the transceiver does indeed output valid CAN messages, but the interrupt never triggers. This is the setup I use in an attempt to receive classic CAN messages using the hardware I have:
These are the settings in STM32CubeMX:
This is the code these settings generate in the form of an init function that is called in the init section for those who don't use the "wizard", but still use the STM32 HAL:
hfdcan1.Instance = FDCAN1;
hfdcan1.Init.ClockDivider = FDCAN_CLOCK_DIV24;
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 = 1;
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();
}
I then initialize the filters that should allow every packet to get through (which doesn't print any errors):
FDCAN_FilterTypeDef sFilterConfig;
sFilterConfig.IdType = FDCAN_STANDARD_ID;
sFilterConfig.FilterIndex = 0;
sFilterConfig.FilterType = FDCAN_FILTER_RANGE;
sFilterConfig.FilterConfig = FDCAN_FILTER_TO_RXFIFO0;
sFilterConfig.FilterID1 = 0;
sFilterConfig.FilterID2 = 0x1FFFFFFF;
if (HAL_FDCAN_ConfigFilter(&hfdcan1, &sFilterConfig) != HAL_OK) {
/* Filter configuration Error */
printf("[CAN] Unable to configure!\n");
}
if (HAL_FDCAN_Start(&hfdcan1) != HAL_OK) {
/* Start Error */
printf("[CAN] Unable to start!\n");
}
if (HAL_FDCAN_ActivateNotification(&hfdcan1, FDCAN_IT_RX_FIFO0_NEW_MESSAGE, 0) != HAL_OK) {
/* Notification Error */
printf("[CAN] Unable to activate the CAN interrupt!\n");
}
As well as the interrupt function with a simple breakpoint (in Keil) to indicate any interrupt calls:
void HAL_FDCAN_RxFifo0Callback(FDCAN_HandleTypeDef *hfdcan, uint32_t RxFifo0ITs) {
__breakpoint(0);
}
From what I've read in the brief FDCAN peripheral overview by ST, there should be no problem receiving CAN 2.0 packets, yet my attempts don't seem to yield any results. Any help would be greatly appreciated!
Solved! Go to Solution.
2022-05-25 02:19 AM
Also I'm wondering why you are using these values:
Prescaler = 24
Nominal bit time Seg1/Seg2 = 2
Data bit time Seg1/Seg2 = 1 !!!!
Please decrease as much as possible the prescaler and increase as much as possible Nominal and data time segs to fit your bit rate.
Please refer to this thread:
2022-05-25 02:11 AM
Hello,
There is no issue if your FDCAN transmission doesn't exceed 1MB/s either for Nominal or Data rates.
From SN65HVD23x datasheet:
2022-05-25 02:19 AM
Also I'm wondering why you are using these values:
Prescaler = 24
Nominal bit time Seg1/Seg2 = 2
Data bit time Seg1/Seg2 = 1 !!!!
Please decrease as much as possible the prescaler and increase as much as possible Nominal and data time segs to fit your bit rate.
Please refer to this thread:
2022-05-26 06:21 AM
Hi,
I've changed my timings to match my transceiver and other nodes (which are all operating at fixed 1 Mbps) without success. My core clock is 170 MHz.
These are the values I tried
None of these seem to yield any results. There is no error code in the FDCAN handle instance and its "State" is always in "HAL_FDCAN_STATE_BUSY". Is this normal, or should it be in "HAL_FDCAN_STATE_READY"?
I've also tested the can controller with the loopback mode and it does indeed return all the packages it gets, so I'm guessing this isn't an issue with the filters, but I'm still doing something wrong with the timing.
2022-05-26 08:50 AM
I mistakenly believed all nodes operated at 1 Mbps while in reality they operated at 250 kbps, so changing the timings was indeed the correct solution. Thank you!
2022-07-13 01:01 AM
Hi,
you must check if the FDCAN1 Interrupt 0 is active or not
the following lines must be present on stm32g4xxx_hal_msp.c file
/* FDCAN1 interrupt Init */
HAL_NVIC_SetPriority(FDCAN1_IT0_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(FDCAN1_IT0_IRQn);
HAL_NVIC_SetPriority(FDCAN1_IT1_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(FDCAN1_IT1_IRQn);
/* USER CODE BEGIN FDCAN1_MspInit 1 */