cancel
Showing results for 
Search instead for 
Did you mean: 

CANBUS Between two STM controllers

PatTheTrickster
Associate III

Hello I am trying to attempt a CANBUS communication between two different STM boards, I've been following the videos on the STM website as a reference and I got the LOOPBACK Mode to work with one STM board but I am having trouble getting the NORMAL mode to work with two Stm boards.

Video I am referencing:  https://youtu.be/KHNRftBa1Vc

My Master board is a Nucleo-L4R5ZI-P

Slave board is a Nucleo-L4A6ZG

Attached is an image of my current setup on trying to get the CAN transmit working

I kept the code mostly the same as the video, the problem I have right now is when I run it the video doesn't clarify if I should run the slave first then the master or run them in debug mode, doing either method I am getting all sorts of errors or just nothing happening, any clarification on what I can do to fix this would be massive help, Thank you!

 

19 REPLIES 19
Karl Yamashita
Lead II

"I am getting all sorts of errors or just nothing happening" is pretty vague. Be more specific.

Your picture doesn't show what are connected to the USB so don't know if you have one or two computers? My first thought is there is no ground reference between either CAN transceivers but goes back to what are connected to the USB connectors?

If you find my answers useful, click the accept button so that way others can see the solution.

Yes Sorry, The two USBS are connected to one computer, The kind of errors I get is if I run the master first then the slave I will get a
'Error in final Launch sequence
Failed to start GDB server'

if I run the slave first then the master I get a failure to bind to port 61234 on the command line

when I try running them in debug mode they will throw an error that the target is not responding,retrying and it will constantly just loop that till I get a problem occured message saying
'Error in final launch sequence:
Failed to execute MI command:

target remote localhost:61234

Haven't watched the video. What you describe looks more like a debugger issue, not CAN related.

If you use both ST-LINKs on the same computer, use two instances of STZM32CubeIDE. Connect only one board first, and in the Debugger Setup window enable ST-LINK serial number (S/N) and scan for it. Then, in the other instance, do the same for the other board. This should avoid using the same ST-LINK twice.

hth

KnarfB

I couldnt open two instances but I went into the Debug configuration and changed the ports that each device was binded to and set the st/link for both, Right now going into the debug menu the program will get to system_clock_config and immediately go into a error handler. Is running them both in debug mode or running them the right way of testing out the canbus or should I just run one of them?

Not sure I've got the patience to watch a 20 min controllers tech video narrated by a robot.

Keil has a simple bus method that might be applicable, bit simpler than the transceivers, hopefully you have those wired up correctly.

https://www.keil.com/appnotes/files/apnt_236.pdf

I would honestly try to avoid single step debugging this type of stuff, and rather use the serial port afforded by the NUCLEO boards to provide information and instrumentation as to what's going on.

You need a device that's reliably listening and responding/acknowledging packets when not using the loop-back mode. Make one the listener.

Most STM32 have TWO CAN, it might be simpler to debug that configuration where CAN1 and CAN2 communicate and you have the simple diode bus illustrated by Keil

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

When your loopback test is successful, you can easily program one board as a transmitter in normal mode, periodically transmitting a frame, say once per second. The payload can be an increasing counter value. You may also print the payload via the ST-LINK UART to a terminal prog. on your host. This gives you confidence that the transmitter is up and running. Then you can focus on (and maybe debug) the receiver side. When this works, try more adventurous configurations.

hth

KnarfB

> narrated by a robot.

At least no strange human accent...

SofLit
ST Employee

Hello,

You didn't provide your CAN bitrate config. Watching the video, I noticed that prescaler = 18, BS1=2 and BS2=2 which are not suitable values. You have to decrease CAN clock prescaler as much as possible and increase BS1 and BS2 to fit your bitrate where BS1 > BS2.

You have also to use an external crystal and not HSI as source clock for CAN communication.

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.

So my CAN bitrate config is this
On The Nucleo-L4R5ZI-P on the clock cofiguration I changed the parameters similar to the video (HSE and PLLCLK) but the HCLK I used was 120 MHz as that was the max
On the Nucleo L4A6ZG The HCLCK was set to 80 MHZ

For the L4R5ZI-P I had my Prescalar be 48 and Time quanta for 1 & 2 be 2 Times which resulted in Time Quantum being 400.0ns and the Baud rate being 500000 bit/s

For the L4A6ZG The Prescalar I had was 20 and the Time Quanta for 1 & 2 was 2 Times and 1 Times respectively, This resulted in a Time quantum of 500.0 NS and 500000 bit/s, Let me know if there's a config I should be using but I will take your advice and start playing with those values.