cancel
Showing results for 
Search instead for 
Did you mean: 

STM32G474RE FDCAN0 Transmit Errors & Passive Mode without CAN Master or Analyzer

omkarprayag
Associate III

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.");
    }
}

 

 

 

 

The Issue

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.

 

Questions for the Community

  1. Given that both devices are sensor nodes on CANopen, should they need a master or analyzer to activate the bus, or should the nodes be able to communicate autonomously?
  2. Are there any additional configurations to ensure the devices move to an Active state and avoid the passive error mode?
  3. Is manually initiating communication via an NMT (Network Management) Start command necessary, or should each node operate independently on the bus?

Any insights or suggestions would be greatly appreciated! Thank you!

36 REPLIES 36

@SofLit ,

Thanks a lot for your support so far!

I’ll go through all the possibilities along with the code you shared and get back to you with my observations.

Really appreciate your help on this—it’s been a bit of a sticking point for over a week now, but I’m hopeful we can sort it out this time.

 

 


 

I suggest to find the failing node first i.e. you keep the CAN analyzer on the bus and each time you put one node and disconnect the other at a time. The node with which you get an error is the failing node. At that time focus on its HW.

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.

@SofLit ,

Yes, I did that, both the nodes individually working perfect along with CAN analyser.

 

Do you mean, each time you connect a node individually with the CAN analyzer, it is working fine? and this is true for both STM32G4 nodes? 

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.

@SofLit ,

yes, that’s true for both the nodes

 

Frankly hard to  tell what the origin of the issue but I'm pretty sure it's a HW problem.

Check the terminating resistors on both sides of the bus at each time, are they present? Are they really connected to the bus (use the continuity option in the multimeter)?

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.

@SofLit ,

 

yes, the connection is intact, checked with continuity.

Once again, I will check with termination resistor and records the bus resistance as well by tomorrow.