2024-11-12 10:34 PM - last edited on 2024-11-13 01:16 AM by Andrew Neil
Hello Community,
I'm using an STM32G474RE MCU with FDCAN0 to set up CANopen communication for a sensor node device. The setup is designed to cascade multiple sensor devices on the same CAN bus, each with a unique node ID, so they can transmit data independently.
Currently, I have two devices connected in a simple cascading configuration, both operating as CANopen nodes with different IDs. No CAN master or analyzer is connected, as these sensor nodes are meant to operate autonomously on the bus.
Here is my FDCAN initialization code:
void MX_FDCAN1_Init(void)
{
FDCAN_FilterTypeDef sFilterConfig;
/* FDCAN1 parameter configuration */
hfdcan1.Instance = FDCAN1;
hfdcan1.Init.DataPrescaler = 12;
hfdcan1.Init.NominalPrescaler = 12;
hfdcan1.Init.NominalTimeSeg1 = 13;
hfdcan1.Init.DataTimeSeg1 = 13;
hfdcan1.Init.ClockDivider = FDCAN_CLOCK_DIV1;
hfdcan1.Init.FrameFormat = FDCAN_FRAME_CLASSIC;
hfdcan1.Init.Mode = FDCAN_MODE_NORMAL;
hfdcan1.Init.AutoRetransmission = ENABLE;
hfdcan1.Init.TransmitPause = DISABLE;
hfdcan1.Init.ProtocolException = ENABLE;
hfdcan1.Init.NominalSyncJumpWidth = 1;
hfdcan1.Init.NominalTimeSeg2 = 2;
hfdcan1.Init.DataSyncJumpWidth = 1;
hfdcan1.Init.DataTimeSeg2 = 2;
hfdcan1.Init.StdFiltersNbr = 0;
hfdcan1.Init.ExtFiltersNbr = 0;
hfdcan1.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION;
if (HAL_FDCAN_Init(&hfdcan1) != HAL_OK)
{
Error_Handler();
}
/* Configure Rx filter */
sFilterConfig.IdType = FDCAN_STANDARD_ID;
sFilterConfig.FilterIndex = 0;
sFilterConfig.FilterType = FDCAN_FILTER_MASK;
sFilterConfig.FilterConfig = FDCAN_FILTER_TO_RXFIFO0;
sFilterConfig.FilterID1 = 0x0000;
sFilterConfig.FilterID2 = 0x0000;
if (HAL_FDCAN_ConfigFilter(&hfdcan1, &sFilterConfig) != HAL_OK)
{
DebugPrint("Failed to config filter.");
}
/* Configure global filter to accept all frames */
if (HAL_FDCAN_ConfigGlobalFilter(&hfdcan1, FDCAN_ACCEPT_IN_RX_FIFO0, FDCAN_ACCEPT_IN_RX_FIFO0, FDCAN_FILTER_REMOTE, FDCAN_FILTER_REMOTE) != HAL_OK)
{
DebugPrint("Failed to config global filter.");
}
/* Clearing Error Flags */
__HAL_FDCAN_CLEAR_FLAG(&hfdcan1, FDCAN_FLAG_ERROR_PASSIVE | FDCAN_FLAG_BUS_OFF);
/* Start the FDCAN module */
if (HAL_FDCAN_Start(&hfdcan1) != HAL_OK)
{
DebugPrint("Failed to start FDCAN.");
}
if (HAL_FDCAN_ActivateNotification(&hfdcan1, FDCAN_IT_RX_FIFO0_NEW_MESSAGE | FDCAN_IT_ERROR_PASSIVE | FDCAN_IT_BUS_OFF, 0) != HAL_OK)
{
DebugPrint("Failed to activate notifications.");
}
}
With the two sensor nodes connected, the bus doesn’t transition to an Active mode, as expected. Instead, it enters an Error Passive state, and the Transmit Error Counter (TEC) reaches 128. This seems to imply a problem with message transmission or bus communication even though both nodes have unique IDs.
Any insights or suggestions would be greatly appreciated! Thank you!
Solved! Go to Solution.
2024-12-03 03:28 AM - edited 2024-12-03 06:24 AM
Hello @omkarprayag ,
As promised, I've created a project running on two NUCLEO-G474RE boards (same project in the attachment). I used your ioc file as a base to create the project with some little modifications. I'm using MCP2562FD as a transceiver from both sides PA11 and PA12 pins for CAN communication and it's working fine.
This is the live expression where I put the Rx data. As you can see the yellow color says that the Rx values are changing in live:
So, I'm pretty sure you have an issue with your HW.
Hope it helps.
2024-11-12 11:14 PM
Hello,
Forget about CANOpen for the moment and establish a simple CAN communication (create a simple CAN project where two nodes are communicating together) and tell what do you find.
2024-11-13 12:54 AM
Hi @SofLit, Thank you for the reply.
I followed your suggestion and set up a simple CAN communication project with two nodes, bypassing CANopen, Unfortunately, I’m still encountering the same issue. Both nodes are entering Error Passive mode, and the Transmit Error Counter (TEC) reaches 128, which suggests there's an issue with message transmission or bus communication.
I’ve checked the wiring, including the termination resistors, and verified the CAN parameters. The issue persists, and no meaningful communication appears to be taking place.
Would you recommend further debugging steps, or do you think the problem might lie in the configuration of the CAN timing or another aspect of the physical layer?
Thanks for your help!
2024-11-13 01:00 AM
Hello,
At this stage I recommend to:
1- Share your schematics and mainly CAN part of the two nodes?
2- Share your code (I prefer the complete simple project). If there is an ioc file please attach it.
2024-11-13 01:20 AM
@omkarprayag wrote:With the two sensor nodes connected, the bus doesn’t transition to an Active mode, as expected. !
What about with just one node?
2024-11-13 01:24 AM
Hi @Andrew Neil ,
Thank you for your response.
On one of the nodes, the behavior is as expected. When no device is connected, it remains in Passive mode. However, when a CAN analyzer or master is connected, the node transitions to Active mode.
2024-11-13 01:39 AM
Just to clarify something: if you are using CAN in Normal mode and you are not connecting any other node on the Bus (establishing a CAN bus), this will never work and the acknowledgement mechanism is broken.
So please confirm you are doing a test with at least two nodes that are connected on the CAN bus.
Note: CAN analyzer is supposed to be the second node connected on the bus that's why you are not seeing an issue.
2024-11-13 01:46 AM
@SofLit ,
Yes, I am testing with two CAN nodes, both sensor nodes, and no CAN analyzer is connected to the bus. It is only in this setup that I am encountering the issue.
However, when I connect a CAN analyzer as one of the nodes, along with the sensor node, the issue does not occur.
2024-11-13 01:49 AM
Could you please give more details about the bus and what sensors are connected to? I prefer to draw a sketch with the different nodes with the CAN bus.
And:
1- Share your schematics and mainly CAN part of the two nodes?
2- Share your code (I prefer the complete simple project). If there is an ioc file please attach it.
2024-11-13 02:55 AM - edited 2024-11-13 02:57 AM
@SofLit , Attached is the connection diagram and schematics of the same