# CAN Bus first steps

In a few months, I will need to build a project that will let me connect from my PC to a power supply via CAN bus.

I don't have this power supply here and have zero knowledge (even less) of how to do this.

I want to prepare by arranging a demo, to put some device that I want to give commands to, from my PC, and see that it connects, and also be able to read something from that device.

My guess is that I will need a device, a wire to connect to this device, and a converter from the USB or Ethernet connector of my PC to this type of wire.

As you can see, I'm clueless. I will appreciate any help in these first steps, like what should I buy for this, nothing is too simple for me.

Thanks in advance for any help.

• We are also clueless what you mean with this power supply and some device. Can you improve your question? – Jeroen3 Jan 30 '19 at 9:30
• I want a simple device, no matter what device, i want to see that i can send a simple message and read a simple message. – Sharon Jan 30 '19 at 10:28
• That's still vague. For CAN, I can recommend Kvaser, however buying questions are also considered off topic here. – Jeroen3 Jan 30 '19 at 10:41

A good start is watching some tutorials. The web is full of stuff, and even being totally clueless it's easy enough to find something useful. For instance, have a look at this one: https://www.youtube.com/watch?v=RRbrk3SdSKA

But actually, for your purpose you don't have to have really detailed knowledge on CAN. What you have to know is how to control your PC software to send and receive messages, and of course you will finally need a specification of the power supply's CAN interface:
- What messages does it expect?
- What messages is it able to send?
- What's the meaning of the data bytes in the messages?

The PC software is usually bundled with a specific CAN hardware from the same supplier. Kvaser was already mentioned, Vector is another (expensive) one, Intrepid has solutions matching your needs, ...
They all offer professional control software, but also have free libraries to allow interfacing their hardware with your own software solution or third party tools like LabView.

Let me add ETAS Busmaster as another very interesting tool: It can deal with the above mentioned and various other hardware interfaces, it's open source, and it's free of charge.

The Arduino solution mentioned in another answer may be the cheapest from hardware side, but IMHO not the easiest and quickest way to get things running - unless you are willing and able to deal with source code and building your own application more or less "from scratch".

• Timing aspects of messages are also very important. – Lundin Feb 1 '19 at 10:07

Obviously you will need to study CAN, but what you need in terms of hardware/software is this:

• An USB-to-CAN converter with USB in one end and a DB9M dsub connector in the other end. Well-known manufacturers are IXXAT, Vector, Kvaser. You can buy 2 of these to "speak with yourself" if you have no other CAN hardware available - CAN always requires at least 2 nodes to work.

• CAN listener software on the PC. You can buy this too from the above mentioned companies. Typically they give you a limited "light version" of such a tool together with the USB-to-CAN adapter. Better CAN listeners cost a lot of money, but they come with a PC programming API that you can use, to manage all communication directly from the PC.

You will always need a CAN listener no matter if you run CAN from PC or a microcontroller. Forget about decoding messages manually with a scope.

• Build some lab wire with 9 pin ribbon cable and as many IDC dsub connectors as you like. Add an option to put 120 ohm terminating resistors at each end of the wire, between CAN_H and CAN_L. The pinout is standardized:

First, I suggest doing some research on the physical layer of CAN -- Wikipedia is usually a good start.

The easiest and quickest way to get up and running is to purchase an Arduino or Teensy and a CAN breakout board. These latter devices typically employ an MCP2515 CAN transceiver that's controlled by a SPI interface. Make sure the breakout board includes a 120 $$\\Omega\$$ termination resistor on the CAN signals.

Since you have a few months before your project begins, I suggest buying two of each of the above and making your own two-node network. Look into the structure of CAN messages and try sending messages back and forth. There are tutorials online (search 'arduino can tutorial') and you can come back here with specific questions if you get stuck.

EDIT: As Lundin points out, these CAN controllers are not ideal -- especially if you plan on a permanent setup. The next step up would be to use the Teensy, which includes a CAN peripheral (but no library support), and a transceiver. The only transceiver breakout I found was here, and the company also provides a short tutorial on interfacing the board with a Teensy.

• This is not a good idea. AVR and external CAN controllers is all stone age technology from the previous millennium. Making this needlessly complicated. – Lundin Feb 1 '19 at 9:49
• @Lundin They're cheap, well-supported, easy to connect, and widely available. I agree that a transceiver breakout would be more of-the-times, but I hesitated since I only found one company that offers them. I'll update my answer anyway. – calcium3000 Feb 1 '19 at 12:59
• Needlessly expanding your BOM for the purpose of using legacy technologies is not what I would call cheap. Whoever designed that board was probably cheap to hire though, as they excluded CAN signal ground and picked a 120R resistor which can't handle the current... – Lundin Feb 1 '19 at 13:05
• @Lundin "Needlessly expanding your BOM?" Once the OP gets this working Bob's the uncle -- I don't see your point. You even recommend in your answer buying two setups to "speak with yourself." These are "first steps" and "nothing is too simple" for the OP, so why not suggest the most approachable platform in electronics? – calcium3000 Feb 1 '19 at 14:12
• Because it is hobbyist crap that can't be used for professional applications anyway? I really don't see why you would learn quicker by starting with a legacy MCU with bloated libraries, in an unsuitable programming language. Instead of just getting any ARM evaluation board and run the default examples provided by the tool chain, then write the code in standard C. The step "learn how some hobbyist cult do it first" isn't productive and can be skipped. You'll waste time learning how artificial libraries work, instead of learning how microcontrollers work. – Lundin Feb 1 '19 at 14:23