2024-08-08 03:45 AM - last edited on 2024-08-20 03:07 AM by SofLit
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/
2024-08-08 09:59 PM
Hi, Please any one reply....
2024-08-19 10:21 PM - last edited on 2024-08-21 01:40 AM by SofLit
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.
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.
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)
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..");
}
}
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
2024-08-20 02:45 AM
To clear the above points I also adding the block diagram of my system.
2024-08-20 03:11 AM
Hello @skhanna
My first question is: what is the clock source of FDCAN? if you are using cubeMx please attach your ioc file.
2024-08-20 03:28 AM - edited 2024-08-20 03:31 AM
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.
2024-08-20 03:37 AM
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?
2024-08-20 03:44 AM
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
2024-08-20 03:46 AM
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.
2024-08-20 04:11 AM
This is link of transriciver
This is for USB to CAN converter
https://www.waveshare.com/product/usb-can-a.htm