cancel
Showing results for 
Search instead for 
Did you mean: 

STM32G491 FDCAN2 Receiving Issue

YY_John
Visitor

Hi,

I am using STM32G491 with 2 FDCAN channels. FDCAN1 is working normally for sending and receiving data. FDCAN2 is sending out data normally, but it can't receive any data, not able to generate any receiving interrupts. Here is the initialization code. Can anyone have any ideas what could be the issue? Thanks. 

void MX_FDCAN2_Classic_Init(void)

{



FDCAN_FilterTypeDef sFilterConfig;

__HAL_RCC_FDCAN_CLK_ENABLE();





hfdcan2.Instance = FDCAN2;

hfdcan2.Init.ClockDivider = FDCAN_CLOCK_DIV1;

hfdcan2.Init.FrameFormat = FDCAN_FRAME_CLASSIC;

hfdcan2.Init.Mode = FDCAN_MODE_NORMAL;

hfdcan2.Init.AutoRetransmission = DISABLE;

hfdcan2.Init.TransmitPause = DISABLE;

hfdcan2.Init.ProtocolException = DISABLE;

//CAN 500kbps

hfdcan2.Init.NominalPrescaler = 16;

hfdcan2.Init.NominalSyncJumpWidth = 1;

hfdcan2.Init.NominalTimeSeg1 = 2;

hfdcan2.Init.NominalTimeSeg2 = 2;

hfdcan2.Init.DataPrescaler = 1;

hfdcan2.Init.DataSyncJumpWidth = 1;

hfdcan2.Init.DataTimeSeg1 = 1;

hfdcan2.Init.DataTimeSeg2 = 1;

hfdcan2.Init.StdFiltersNbr = 0;

hfdcan2.Init.ExtFiltersNbr = 0;

hfdcan2.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION;

if (HAL_FDCAN_Init(&hfdcan2) != HAL_OK)

{

Error_Handler();

}



/* Configure the CAN Filter */

sFilterConfig.IdType = FDCAN_STANDARD_ID;

sFilterConfig.FilterIndex = 1;

sFilterConfig.FilterType = FDCAN_FILTER_RANGE;

sFilterConfig.FilterConfig = FDCAN_FILTER_TO_RXFIFO0;

sFilterConfig.FilterID1 = 0x321;

sFilterConfig.FilterID2 = 0x7FF;



if (HAL_FDCAN_ConfigFilter(&hfdcan2, &sFilterConfig) != HAL_OK) {

Error_Handler();

}



if (HAL_FDCAN_Start(&hfdcan2) != HAL_OK) {

Error_Handler();

}



// 2. Assign the event to a specific interrupt line (Line 0 is default)

HAL_FDCAN_ConfigInterruptLines(&hfdcan2, FDCAN_IT_GROUP_RX_FIFO0, FDCAN_INTERRUPT_LINE0);

HAL_FDCAN_ConfigInterruptLines(&hfdcan2, FDCAN_IT_GROUP_RX_FIFO1, FDCAN_INTERRUPT_LINE1);

// 3. Enable the global FDCAN Line 0

//HAL_FDCAN_ConfigInterruptLines(&hfdcan2, FDCAN_INTERRUPT_LINE0);



// 4. Activate the specific notification (e.g., RX FIFO 0 New Message)

HAL_FDCAN_ActivateNotification(&hfdcan2, FDCAN_IT_RX_FIFO0_NEW_MESSAGE, 0);

HAL_FDCAN_ActivateNotification(&hfdcan2, FDCAN_IT_RX_FIFO1_NEW_MESSAGE, 0);

//if (HAL_FDCAN_ActivateNotification(&hfdcan2, FDCAN_IT_RX_FIFO0_NEW_MESSAGE, 0) != HAL_OK) {

//Error_Handler();

//}



NVIC_SetPriority(FDCAN2_IT0_IRQn, 2);

NVIC_EnableIRQ(FDCAN2_IT0_IRQn);



NVIC_SetPriority(FDCAN2_IT1_IRQn, 2);

NVIC_EnableIRQ(FDCAN2_IT1_IRQn);



/* Configure Transmission process */

FDCAN2_TxHeader.Identifier = 0x321;

FDCAN2_TxHeader.IdType = FDCAN_STANDARD_ID;

FDCAN2_TxHeader.TxFrameType = FDCAN_DATA_FRAME;

FDCAN2_TxHeader.DataLength = FDCAN_DLC_BYTES_8;

FDCAN2_TxHeader.BitRateSwitch = FDCAN_BRS_OFF;

FDCAN2_TxHeader.FDFormat = FDCAN_CLASSIC_CAN;

}

 

7 REPLIES 7
Karl Yamashita
Principal

In the future, use the </> to insert code so it's properly formatted.

Attach your IOC file.

If a reply has proven helpful, click on Accept as Solution so that it'll show at top of the post.
CAN Jammer an open source CAN bus hacking tool
CANableV3 Open Source

Ozone
Principal III

> FDCAN2 is sending out data normally, but it can't receive any data, not able to generate any receiving interrupts.

Are you sure ?
Putting a CAN message into the FIFO does not equal "sending out", this is not how CAN works.
Use a CAN monitoring tool or an oscilloscope to check the actual bus signals.

mƎALLEm
ST Employee

Hello @YY_John and welcome to the ST community,

1- As said by @Karl Yamashita , in next time please use </> button to share your code. I'll edit your post then.. And please refer to How to write your question to maximize your chances to find a solution.

2- At first glance at your code you didn't set the filter number, you set both filters number to 0:

hfdcan2.Init.StdFiltersNbr = 0;
hfdcan2.Init.ExtFiltersNbr = 0;

I don't know what frame format you're supposed to receive but set at least 1 for each filter to receive both formats:

hfdcan2.Init.StdFiltersNbr = 1;
hfdcan2.Init.ExtFiltersNbr = 1;

And please avoid this kind of timing parameters:

hfdcan2.Init.NominalPrescaler = 16;
hfdcan2.Init.NominalTimeSeg1 = 2;
hfdcan2.Init.NominalTimeSeg2 = 2;

-> Low TSEGs values with high prescaler. You need to select a sample point around 87,5% of the bit time.

Please refer to CAN (bxCAN) bit time configuration on STM32 MCUs. It treats bxCAN peripheral but the principle applies to FDCAN in Classic mode.

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.

Yes. I am using a CAN monitoring tool, and I can see all the CAN traffic data on the bus. Thanks


@YY_John wrote:

Yes. I am using a CAN monitoring tool, and I can see all the CAN traffic data on the bus. Thanks


You didn't state on my reply.

Did you check my points I highlighted in my previous post?

If the filters number =0 for both filters you won't receive any CAN frame even if all is OK.

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.

I tried the following configurations.

 <>

hfdcan2.Init.StdFiltersNbr = 1;

hfdcan2.Init.ExtFiltersNbr = 1;

 </>

 It is not working. Thanks.

Attach your complete project including the ioc file then ..

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.