cancel
Showing results for 
Search instead for 
Did you mean: 

CAN bus frame bit rate setting issue

skhanna
Associate II

I am using CAN bus on my project and I am using  NUCLEO-H753ZI board. The second board is nvdia orin nx. I also using CAN to USB converter to monitor the frames.

When STM32 send the frame it is received on CAN to USB converter software without error but Orin NX showing error frame. When I send frame from Orin NX then it is received at CAN to USB converter correctly but not at STM32.

So I am not able to understand where is the problem. I change the frame bitrate by adjusting the Tseg1-85 and Tseg2-13. at CAN bit rate of 125000. But it is not working. Then I try at Tseg1-573, Tseg2-62 then this work with Orin but if 10 frame are send from STM32 then only 2 or 3 received other show error. So please help me on this.  

The Tseg1 and Tseg2 value are calculated from following link.

https://kvaser.com/support/calculators/can-fd-bit-timing-calculator/

 

 

15 REPLIES 15
skhanna
Associate II

Hi, Please any one reply....

skhanna
Associate II

Hi, This is image (first image) and it is transmitted by USB to CAN converter (can bus identifier 64). It is received correctly on my Linux board (This converter also uses stm32F403). The baud rate is 125Kbps and CAN standard. 

can_64.png

Now this is from (second image) NUCLEO-H753ZI  this frame always give error (can bus identifier 304) on linux board. But on USB to CAN converter it is received without any issue. I also check this on microchip CAN bus analyzer and it work there also. But not on Linux board. I also send frame form CAN bus analyzer and it is received correctly on Linux board. 

Please note that during this testing all 3 device  (NUCLEO, UAB to CAN converter and linux board)are connected on same CAN bus. Bus termination resistance (120 ohm on each device) also there on CAN transceiver.   

I capture these waveform on the linux board CAN-RX pin.

can_304_error.png

Here you can see after error the frame is again transmitted correctly but not received correctly and show as error.

This frame (frame 3) is same as above but screen short of correct frame(this is also not received)

can304-1.png

This is my stm32 initialization code. CAN  input frequency is 50Mhz.

void Initialize_FDCAN(void)
{
    CAN_GPIO_ClockInit();
    MX_FDCAN1_Init();
 
    /* Configure Tx buffer message */
    TxHeader.Identifier = 0x130; 
    TxHeader.IdType = FDCAN_STANDARD_ID;
    TxHeader.TxFrameType = FDCAN_DATA_FRAME;
    TxHeader.DataLength = FDCAN_DLC_BYTES_8;
    TxHeader.ErrorStateIndicator = FDCAN_ESI_ACTIVE;
    TxHeader.BitRateSwitch = FDCAN_BRS_OFF;
    TxHeader.FDFormat = FDCAN_CLASSIC_CAN;//FDCAN_FD_CAN;
    TxHeader.TxEventFifoControl = FDCAN_NO_TX_EVENTS;
    TxHeader.MessageMarker = 0x0; // Ignore because FDCAN_NO_TX_EVENTS


    if(HAL_FDCAN_AddMessageToTxBuffer(&hfdcan1, &TxHeader, CAN_TxData, FDCAN_TX_BUFFER0) != HAL_OK)
    {
Error_Handler("HAL_FDCAN_AddMessageToTxBuffer");
    }

    /* Configure standard ID reception filter to Rx buffer 0 */
    sFilterConfig.IdType = FDCAN_STANDARD_ID;
    sFilterConfig.FilterIndex = 0;
#if 0
    sFilterConfig.FilterType = FDCAN_FILTER_DUAL; // Ignore because FDCAN_FILTER_TO_RXBUFFER
#endif
    sFilterConfig.FilterConfig = FDCAN_FILTER_TO_RXBUFFER;
    sFilterConfig.FilterID1 = 0x3; // ID Node2
#if 0
    sFilterConfig.FilterID2 = 0x0; // Ignore because FDCAN_FILTER_TO_RXBUFFER
#endif
    sFilterConfig.RxBufferIndex = 0;
    if(HAL_FDCAN_ConfigFilter(&hfdcan1, &sFilterConfig) != HAL_OK)
    {
Error_Handler("HAL_FDCAN_ConfigFilter");
    }

    /* Start the FDCAN module */
    if(HAL_FDCAN_Start(&hfdcan1) != HAL_OK)
    {
Error_Handler("HAL_FDCAN_Start()");
    }


HAL_FDCAN_ConfigInterruptLines(&hfdcan1, FDCAN_IT_TX_COMPLETE, FDCAN_INTERRUPT_LINE0);
HAL_FDCAN_ActivateNotification(&hfdcan1, FDCAN_IT_TX_COMPLETE, FDCAN_TX_BUFFER0);
__HAL_FDCAN_ENABLE_IT(&hfdcan1, FDCAN_IT_TX_COMPLETE);

HAL_FDCAN_ConfigInterruptLines(&hfdcan1, FDCAN_IT_RX_BUFFER_NEW_MESSAGE, FDCAN_INTERRUPT_LINE0);
HAL_FDCAN_ActivateNotification(&hfdcan1, FDCAN_IT_RX_BUFFER_NEW_MESSAGE, FDCAN_TX_BUFFER0);
__HAL_FDCAN_ENABLE_IT(&hfdcan1, FDCAN_IT_RX_BUFFER_NEW_MESSAGE);

    /* Send Tx buffer message */
    if(HAL_FDCAN_EnableTxBufferRequest(&hfdcan1, FDCAN_TX_BUFFER0) != HAL_OK)
    {
       Error_Handler("HAL_FDCAN_EnableTxBufferRequest()");
    }


 
}

void MX_FDCAN1_Init(void)
{
hfdcan1.Instance = FDCAN1;
//hfdcan1.Init.FrameFormat = FDCAN_FRAME_FD_BRS;//FDCAN_FRAME_CLASSIC;
hfdcan1.Init.FrameFormat = FDCAN_FRAME_CLASSIC;
hfdcan1.Init.Mode = FDCAN_MODE_NORMAL;
hfdcan1.Init.AutoRetransmission = ENABLE;
hfdcan1.Init.TransmitPause = DISABLE;
hfdcan1.Init.ProtocolException = DISABLE;
hfdcan1.Init.NominalPrescaler = 25;  
hfdcan1.Init.NominalSyncJumpWidth = 8;
hfdcan1.Init.NominalTimeSeg1 = 13;
hfdcan1.Init.NominalTimeSeg2 = 2;
hfdcan1.Init.DataPrescaler = 1;
hfdcan1.Init.DataSyncJumpWidth = 4;
hfdcan1.Init.DataTimeSeg1 = 1;
hfdcan1.Init.DataTimeSeg2 = 1;
hfdcan1.Init.MessageRAMOffset = 0;
hfdcan1.Init.StdFiltersNbr = 1;
hfdcan1.Init.ExtFiltersNbr = 0;
hfdcan1.Init.RxFifo0ElmtsNbr = 0;
hfdcan1.Init.RxFifo0ElmtSize = FDCAN_DATA_BYTES_8;
hfdcan1.Init.RxFifo1ElmtsNbr = 0;
hfdcan1.Init.RxFifo1ElmtSize = FDCAN_DATA_BYTES_8;
hfdcan1.Init.RxBuffersNbr = 1;
hfdcan1.Init.RxBufferSize = FDCAN_DATA_BYTES_8;
hfdcan1.Init.TxEventsNbr = 0;
hfdcan1.Init.TxBuffersNbr = 2;
hfdcan1.Init.TxFifoQueueElmtsNbr = 0;
hfdcan1.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION;
hfdcan1.Init.TxElmtSize = FDCAN_DATA_BYTES_8;
if (HAL_FDCAN_Init(&hfdcan1) != HAL_OK)
{
Error_Handler("NA..");
}

}​

---------------------------------------------------------------------------------------------------------------------------------------
This is I am getting on the linux terminal..

Timestamp: 1724069829.861631 ID: 004 S Rx E DL: 8 00 10 00 00 00 00 00 7f Channel: can0
Timestamp: 1724069829.905609 ID: 040 S Rx DL: 8 00 01 02 03 04 05 06 07 Channel: can0
Timestamp: 1724069830.258881 ID: 004 S Rx E DL: 8 00 10 00 00 00 00 00 7f Channel: can0
Timestamp: 1724069830.324557 ID: 040 S Rx DL: 8 00 01 02 03 04 05 06 07 Channel: can0

The ID 40 frame is from USB to CAN converter and ID 004 is from micorcontroller. I am assuming that some thing is wrong with micrcontroller code that why I am not able to receive the data 

  

 

To clear the above points I also adding the block diagram of my system.

can_dig1.jpg

Hello @skhanna 

My first question is: what is the clock source of FDCAN? if you are using cubeMx please attach your ioc file.

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.

Thanks for reply,

I am using the external 8 MHz crystal oscillator available on  NUCLEO-H753ZI. and sorry IOS file is not available. CAN frequency is 50MHz. 

PLease see this for more clarity–All device are connected as shown in my previous post figure.

  1. “USB to CAN controller” to Linux board --Working
  2. Linux boars to “USB to CAN controller” --Working
  3. Micorconteoller to “USB to CAN converter”–Working
  4. Linux board to microcontroller–Not Working
  5. Microcontroller to Linux board–Not working

  

 

It's not easy to determine what the problem is in such kind of situation. You need to provide more details:

- STM32H7 schematics including the transceiver connections. We need details on this part.

- What about the the termination resistors? As you are using two other nodes "Orin NX" and "CAN to USB bridge", are you sure you have only two 120 ohm resistors on the both termination of the bus?

 

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.

As you ask...

1) only two 120 ohm resistors on the both termination of the bus?-- Yes I also check the communication by connecting linux board and STM32 board only, at this time USB to CAN is not connected. Error is still coming and as I say i am able to receive on USB to CAN controller so I think hardware connection are correct. Please first cross check the STM32 driver I share in my post


Please first cross check the STM32 driver I share in my post

Sorry, you need to provide your HW details before: STM32H7 schematics including the transceiver connections.

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.