2025-02-01 09:53 AM
I am using STM32 Nucleo-l476rg. I am trying to use the CAN peripheral and have tried every resource I came across. I am unable to send or receive messages:
I have no filter, everything is wired correctly, what could be the issue? I even made it so that it just toggles an LED when the interrupt occurs. In case the interrupt is not set up properly, I have it polling HAL_CAN_GetRxFifoFillLevel, and if it is >0, it toggles the LED, but the LED never toggles.
Am I missing something that is not autogenerated after configuring the peripherals in the .ioc file? In all the videos I have watched, it seems quite straightforward. What am I missing?
2025-02-01 10:02 AM
Hello @at3 and welcome to the community,
Need to provide more details:
1 - Are you using CAN in Normal mode or Loopback mode?
2 - If in Normal mode, did you establish a CAN node i.e. you connected at least another CAN node to your board using CAN tranceivers?
3 - Could you also attach your projet inclusing the ioc file?
2025-02-01 10:41 AM
Thank you for your welcome.
1) I am using CAN in normal mode
2) Yes, the current set up is an Arduino configured to send a CAN message. We are using an mcp2562, which connects to the STM32. Using an oscilloscope, we have verified the CAN message is being transmitted properly, and so is the serial data from the transceiver to the STM32. I feel there is a root cause in the configuration for the CAN that is causing an issue, since when I try to send a message, there is no activity on the CAN_tx pin of the stm32, it just stays at 0V.
3) Yes, I will attach my code. Many blocks may be commented out, I tested and these and it did not work. There may be other tests that I did that I ended up deleting, please feel free to ask if there is additional information I can provide. The project I am attaching is just the receiving code.
2025-02-01 11:23 AM
Checking your ioc and main files:
I have two remarks:
1- You are using HSI as clock source for CAN wich is not recommanded. You need to use an external precise clock source like a crystal.
2- I don't see any filter configuration. You need to configure at least one filter even you don't need to filter the messages.
See this example on how to configure a pass "all ID" filter.
Regarding the hardware:
1- How you did connect STDBY pin of the tranceiver?
2- How you did connect VIO pin of the tranceiver?
3- Did you connect the terminating resistors 120ohm x 2?
2025-02-01 11:42 AM
I see, I saw using a crystal was recommended, but in the board documentation it said it can have 24 or 48 Mhz, do you know how I can determine which one it is. Also, what clock configuration settings should I implement
STDBY is connected to GND, VIO is connected to 3v3. There are terminating resistors
Thanks!
2025-02-01 11:51 AM
The crystal is not soldered by default on the board but you can use STLINK-MCO output as a clock source for your case: and you need to be sure the solder bridge SB50 is closed.
For that you need to configure the RCC/HSE in Bypass mode:
and be sure that the input frequency is set to 8MHz.
Hope that helps.
2025-02-01 12:04 PM
Thank you so much!
I will try these and see how it goes