2024-08-28 10:05 AM - last edited on 2024-08-29 03:41 AM by SofLit
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!!
Solved! Go to Solution.
2024-09-04 03:21 AM - edited 2024-09-04 03:26 AM
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:
2024-08-29 03:46 AM
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" ?
2024-08-29 05:40 AM - edited 2024-08-29 05:41 AM
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).
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.
2024-08-29 05:49 AM
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.
2024-08-29 06:21 AM
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.
2024-08-29 06:28 AM
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.
2024-08-29 06:39 AM - edited 2024-08-29 06:41 AM
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.
2024-08-29 06:43 AM
This activates the Rx interrupt on FIFO1 on CAN2 and that doesn't induce to raise errors on the bus.
I don't have the full picture of your application (software/Hardware) but it seems you have HW issues including the clock config I mentioned before.
2024-08-29 07:11 AM
Let me know wich documentation do you need to improve the help, but is what i experienced.
I worked a lot with CAN in STM32 and ESP32 and always worked and the hardware is very simple, transceiver, resistor termination if needed, 4,7uF capacitor and ESD protection diodes.
As i said is a problem that i also experienced with the NUCLEO-F446RE and by that i though that probably the fault was in my code.
But i'm starting to think that this micrcontroller has an issue inside that peripheral.
2024-08-29 07:20 AM
But i'm starting to think that this micrcontroller has an issue inside that peripheral.
I don't think it's related to the MCU but to your HW/Configuration.