Friday, April 25, 2014

Getting on the CAN bus

I co-worker from waaay back (199?) contacted me a while ago about helping out with some issues he had with a linux system that talks with a CAN bus. A very interesting system. But I won't go into specifics here on that point.

Anyway, CAN bus. Most will probably think OBD-II, cars and ELM327, understandable as that is what it was designed for. And that was just about all I did know about it myself too. Researching into it some more was very enlightening and I got some cool ideas on how to use CAN for one of my own little forever projects.

Now, CAN bus is quite simple, two wires, differential. All you need is a transceiver, a controller and something to tie that into your computer, USB, RS232, PCI, etc. Some Linux friendly and cheap boards even have CAN bus integrated in their SoC. And there are some easy to interface SPI controllers that you can use with your favourite microcontroller.

What makes it really interesting is that most of the low-level stuff is handled on-chip. Software does not need to care about timings, arbitration, bit-stuffing, CRC and all that. It is all on the chip. And you have a wide choice of bandwidth/length options. Need to connect that sensor a 100 meters away ? No problem. And thanks to being designed for hostile environments it should work over just about any two wires, or so I've heard.

There are some limits of course. Maximum data packet size is a whooping 8 bytes. And messages have only have a message ID, no sender or receiver ID. So the network is a 1:N broadcast network. But still, that is quite OK for a sensor network.

I ordered a couple of MCP2515 and MCP2551 chips and I hope I have some time do play with them soon.

No comments: