Skip to main content
Associate
August 8, 2024
Question

CAN bus frame bit rate setting issue

  • August 8, 2024
  • 15 replies
  • 4065 views

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/

 

 

This topic has been closed for replies.

15 replies

skhannaAuthor
Associate
August 9, 2024

Hi, Please any one reply....

skhannaAuthor
Associate
August 20, 2024

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 

 

 

skhannaAuthor
Associate
August 20, 2024

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

can_dig1.jpg

mƎALLEm
ST Technical Moderator
August 20, 2024

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 "Best answer" on the reply which solved your issue or answered your question.
mƎALLEm
ST Technical Moderator
August 20, 2024

When you remove "Linux board" and keep just the Converter are you able to send receive frames without issues?

To give better visibility on the answered topics, please click "Best answer" on the reply which solved your issue or answered your question.
skhannaAuthor
Associate
August 20, 2024

Yes, When I remove the Linux board and connect only NUCLEO-H753ZI board and USB to CAN converter, it work without any issue. Even I keep linux board then frames from STM to converter are received. The frame transmitted by STM is received on converter but not on linux board. Please note - No filter are used on any device to make sure all frame are received on all devices. 

The CAN to USB converter also uses STM32F103 microcontroller. So if you can tell what CAN config used in this type of device then I can try it also

This is screenshot of can to usb converter in which I am able to recive data..

can_tool.png

 

 

mƎALLEm
ST Technical Moderator
August 20, 2024

The CAN to USB converter also uses STM32F103 microcontroller. So if you can tell what CAN config used in this type of device then I can try it also


Just send a simple frame from the converter to your H7 MCU. If it is well received,  the issue is from Linux board side which I cannot provide clues.

To give better visibility on the answered topics, please click "Best answer" on the reply which solved your issue or answered your question.
skhannaAuthor
Associate
August 21, 2024

The converter to STM32 communication is already working. And as I say the when I send frame from converter to Linux board then it is also working fine and converter is also have a STM32F103. That's why I am focusing on STM32 not on Linux board.

It is helpful if you can check my code which I already share. Ig can point out some parameter by which we can get some result. For example frame bit rate setting.

 

 

 

mƎALLEm
ST Technical Moderator
August 21, 2024

Please be cooperative in order to help you efficiently.
For the moment, I don't see issue in the code snippet you shared (except I missed something).
The test I requested consist to enclose the problem, is it something related to STM32H7 or to the Linux board.
Is that possible to swap the transceivers between STM32H7 and Linux board?
Are you sure FDCAN is clocked by the external Crystal clock? Please provide your project to have a look.

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