cancel
Showing results for 
Search instead for 
Did you mean: 

STM32G431 CANFD with internal clock

kavinkumar
Associate III

Hi, I made an STM32G4 and TCAN1044VDRQ1 setup and tried to use the FDCAN, but I couldn't get it to work. There is no response from the transceiver. I tried all the bit timings and used calculators to compute the values. I used a USB-to-CAN FD analyzer and sent a message, but there is no response in the HAL_FDCAN_RxFifo0Callback interrupt.

It is not getting triggered when a message comes in. I don’t know what to do. I’ve spent too much time on this. Any help would be appreciated. Thank you. I don’t know what other details I need to share, if you think you need something, please let me know and I’ll send a reply.

void CAN_Init(uint8_t can_id) {
    hfdcan1.Instance = FDCAN1;
    hfdcan1.Init.ClockDivider = FDCAN_CLOCK_DIV1;
    hfdcan1.Init.FrameFormat = FDCAN_FRAME_FD_NO_BRS;
    hfdcan1.Init.Mode = FDCAN_MODE_NORMAL;
    hfdcan1.Init.AutoRetransmission = ENABLE;
    hfdcan1.Init.TransmitPause = DISABLE;
    hfdcan1.Init.ProtocolException = DISABLE;

    hfdcan1.Init.NominalPrescaler = 1;
    hfdcan1.Init.NominalSyncJumpWidth = 3;
    hfdcan1.Init.NominalTimeSeg1 = 8;
    hfdcan1.Init.NominalTimeSeg2 = 3;
    hfdcan1.Init.DataPrescaler = 1;
    hfdcan1.Init.DataSyncJumpWidth = 3;
    hfdcan1.Init.DataTimeSeg1 = 8;
    hfdcan1.Init.DataTimeSeg2 = 3;

    hfdcan1.Init.StdFiltersNbr = 1;
    hfdcan1.Init.ExtFiltersNbr = 0;
    hfdcan1.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION;

    if (HAL_FDCAN_Init(&hfdcan1) != HAL_OK) Error_Handler();

    sFilterConfig.IdType = FDCAN_STANDARD_ID;
    sFilterConfig.FilterIndex = 0;
    sFilterConfig.FilterType = FDCAN_FILTER_MASK;
    sFilterConfig.FilterConfig = FDCAN_FILTER_TO_RXFIFO0;
    sFilterConfig.FilterID1 = can_id;
    sFilterConfig.FilterID2 = 0x7FF;
    if (HAL_FDCAN_ConfigFilter(&hfdcan1, &sFilterConfig) != HAL_OK) Error_Handler();

    if (HAL_FDCAN_ConfigGlobalFilter(&hfdcan1, FDCAN_REJECT, FDCAN_REJECT, FDCAN_REJECT_REMOTE, FDCAN_REJECT_REMOTE) != HAL_OK) Error_Handler();

    if (HAL_FDCAN_Start(&hfdcan1) != HAL_OK) Error_Handler();
}
24 REPLIES 24

Yeah i used the Kvaser CANFD bit time tool but the values generated for the dataprescaler was not in the range 
The DataSyncJumpWidth value is coming as 63

kavinkumar_0-1752660129607.png

but stm32cubeide tells that it should be btw 1 and 16
kavinkumar_1-1752660158910.png

As for the bitrates The Nominal bitrate is 500 000bit/s and Data bitrate is 1000 000bit/s

@kavinkumar wrote:

As for the bitrates The Nominal bitrate is 500 000bit/s and Data bitrate is 1000 000bit/s


But here you set 500kb/s for both Nominal and data phases:

mALLEm_0-1752661913130.png

 

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 was just trying different bits rates and how that affects the bit timings cause the timing values generated are not in the range of STM32CUBEIDE values. I just want my CAN communication to work. between my TCAN1044 has a propagation delay of 90 us

mƎALLEm
ST Employee

Hello,

Attached an example in Loopback mode using HSI, Nominal: 500kb/s, Data: 1Mb/s.

Please test it

 

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.

Thank you for your time. I will test this code and let you know. i saw your code to know it is working i just need to see the if the data from TxData is copied to the RxData in the debug console right?

I didn't test with the debug console. BufferCmp8b() was used for data comparison Rx vs Tx.

Put two break points:

1- One at Error_Handler() (line 194 ) -> comparison failed -> communication failed

2- One at while(1) (line 200) -> comparison succeeded -> communication succeeded

PS: the attached project is based on this example: https://github.com/STMicroelectronics/STM32CubeG4/tree/master/Projects/STM32G474E-EVAL1/Examples/FDCAN/FDCAN_Loopback

 

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.

Seems it worked i guess the program entered the while loop also i can see the last TxData inside the Rxdata

kavinkumar_0-1752683586310.png



Edit: So I have a doubt, is this check independent of my transceiver? Does it just verify that the STM32 is working and cannot verify that my transceiver is working, or does it verify that too?


@kavinkumar wrote:


Edit: So I have a doubt, is this check independent of my transceiver? Does it just verify that the STM32 is working and cannot verify that my transceiver is working, or does it verify that too?


That was a preliminary test to check the STM32 and the CAN config (except the bitrate) and the filters are working well.

The Loopack mode excludes the transceiver from the test. 

1- For Normal mode did you follow the schematic provided in the transceiver datasheet?

mALLEm_0-1752684714473.png

2 - What about both power supplies VCC and VIO? please check the power supply:

mALLEm_0-1752685405680.png

3 - What about the STB (Standby mode) voltage level? tied to GND? please do a continuity test with the tranceiver powred off.

mALLEm_1-1752684868037.png

4 - What about the terminating resistors 2x120ohm? did you connect them on both sides of the bus? one of them is present in the USB-to-CAN FD analyzer?

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.

kavinkumar_0-1752685073879.png

Yep i followed all the thing is the datasheet.
I connected the STB to a GPIO (PC13) to the STM32 and pulled it low programmatically.
*** I'm sorry seeing now  i haven't given the +5v it comes from the main supply through a buck and I've been giving only +3.3v from the STlink.

Can i now just change the mode to Normal Mode and keep everything else same and check again will you think it will work?

And yes i have a termination resistor in my STM32 board and one in my USB to CAN analyzer as well 

1- You need to poser supply the tranceiver as following VCC=5V, VIO=3.3V

2- To me the schematic is OK. You need to ensure that STB pin is tied to the ground either externally or with a GPIO pin.

3- You need to use HSE with a crystal in Normal mode. The project I've attached uses HSI (allowed in the loopback mode not in Normal mode). Do you have a crystal on the board connected to the HSE? if yes what is it's frequency value?

If not I'm not sure that it will be working.

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.