Skip to main content
Graduate
August 28, 2024
Solved

STM32F446RET6R TWO CAN PERIPHERALS

  • August 28, 2024
  • 2 replies
  • 6187 views

Hello!!

I'm trying to use both CAN peripherals in an STM32F446RET6R on a custom PCB, but something is not going well enough.

I've done the basic configuration using the STMCubeIDE platform (I'll add the code later, but first I want to know if someone has had similar issues with this microcontroller).

The problem is that if I only configure one peripheral, CAN1 (the Master), everything works okay—no error bits in SFRs, no BUSOFFs or anything like that, everything is transmitted and received well.

But when I configure CAN2 (SLAVE), CAN1 continues working perfectly, but CAN2 starts sending frames with CRC errors and corrupted data (I'm using CANoe to read the messages). The TEC bit starts incrementing until the node gets stopped.

The flags raised when the transmission stops are TEC, EPVF, and EWGF.

I also want to add that if I configure everything without a reception interrupt in CAN2, the transmission and reception in CAN1 and transmission in CAN2 work fine without any flags raised.

If anyone can help me with this topic, I’d appreciate it a lot. I've done similar configurations with other microcontrollers, and they worked well.

 

THANKS!!

 

 

    This topic has been closed for replies.
    Best answer by mƎALLEm

    Hello,

    Attached a project I made for Nucleo-F446RE board:

    CAN1 and CAN2 are in loopback mode. Nothing connected externally. Activated all the possible CAN errors.

    Nothing happened, CAN1 and CAN2 "transceive" both the frames correctly and none of the activated errors has raised.

    Please run this FW on your board, open the "Live Expressions" and check especially CAN1_errors and CAN2_errors.

    As you can see from my debug session screen shot, CAN1 and CAN2 are receiving messages in loopback mode without errors:

    SofLit_0-1725445254952.png

     

    2 replies

    Technical Moderator
    August 29, 2024

    Hello,

    The issue is not well understood from my side and this statement is ambiguous:


    I also want to add that if I configure everything without a reception interrupt in CAN2, the transmission and reception in CAN1 and transmission in CAN2 work fine without any flags raised.

     

     Could you please provide a sketch how you did connect CAN1, CAN2 and "CANoe" ?

    Davaol19Author
    Graduate
    August 29, 2024

    Hello, thanks for your reply.

    What i wanted to explain is that my problem starts at the point where i activate the notificacions from CAN2, before that, everythings works as expected with no flags rised or crc errors detected.

    Here is the configuracion i used (sorry for the bad quality but i did it fast).

     

    Davaol19_0-1724934223149.png

    Also tried to connect both peripherals to the canoe interface with the db9 wire set that comes with the package (one interface is able to receive two separated can networks in the same db9) and the result were the same.

    As you can see the resistance on both can networks are 60 ohms, i also had that problem with the nucleo board with this microcontroller.

    I attach the main, interrupts and .ioc FYI.

     

    Technical Moderator
    August 29, 2024

    Hello,


    my problem starts at the point where i activate the notificacions from CAN2, before that, everythings works as expected with no flags rised or crc errors detected.

     


    What do you mean by that? CAN2 is working well but when you activate the notification you get bit errors?


    As you can see the resistance on both can networks are 60 ohms,


    No. You need 120ohm terminating resistors in both side of the bus.

    + As per your ioc file you are using HSI as a source clock of the system clock which will be the also of the CAN clock which is not recommended. You need to use HSE with an external crystal.

     

    Davaol19Author
    Graduate
    August 29, 2024
     

    Yes, I have two 120-ohm resistors at the end of each node (because in this test, I only have two nodes in every network), and 60 ohms is the network resistance.

    And yes, when I activate notifications on CAN2, this peripheral starts sending messages with the wrong CRC and corrupted data. The TEC flag starts incrementing, and the EPVF and EWGF flags get raised, and finally, the node stops.

    I haven’t activated the crystal yet, but it’s a feature I’ve implemented on the PCB.

    Do you really think the problem could be the HSI? I’ve seen lots of PCBs without an HSE, with both peripherals working on microcontrollers like the STM32F105R8T6.

    Anyway, I’ll try it and let you know.

    Technical Moderator
    August 29, 2024
     

    And yes, when I activate notifications on CAN2, this peripheral starts sending messages with the wrong CRC and corrupted data. The TEC flag starts incrementing, and the EPVF and EWGF flags get raised, and finally, the node stops.


    This doesn't make sense.

    Which notifications did you activate?

     


    Do you really think the problem could be the HSI? 

    It could be.. but activating notifications could not cause errors ..

     


    I’ve seen lots of PCBs without an HSE, with both peripherals working on microcontrollers like the STM32F105R8T6.

    Yes I know.. but it's not recommended.

     

    Davaol19Author
    Graduate
    August 29, 2024

     

    HAL_CAN_ActivateNotification(&hcan2, CAN_IT_RX_FIFO1_MSG_PENDING);

     

    I use this sentence to activate de notifications from the peripheral. 

    I know that is something strange, but if i comment this line, the CAN2 peripheral is able to transmit messages without crc errors.