CAN bus example?

Does anyone out there have a CAN bus example using the Panda? How do I wire the CAN bus in a car for example, and what does the code look like to access it?


If you’re looking to read diagnostic info from your vehicle via the CAN bus, one way is to use the popular ELM327 ([url]OBD – Elm Electronics) with a CAN tranceiver. The ELM already has all the intelligence built in to decode not only the CAN messages for you, but all the other OBD2 protocols as well.

I’m working on this same thing right now. I have an OBD CAN ECU simulator that I’ve hooked up to my Cobra dev kit and I’m successfully reading/displaying RPM, speed, etc. Tomorrow I plan on hooking it up to an actual vehicle for the first time. If all goes well, I’ll post code/video/wiring/etc. to the wiki. Although my ELM327 driver code is running on the Cobra, there’s nothing Cobra-specific in it. What I have so far will fit into the Panda’s flash.


I created a working CAN interface with one IC and two resistors. MCP2551 is the CAN transceiver, which handles converting the logic-level outputs from the FEZ to play well with the real CAN bus. It also protects the FEZ from shorts, some transient voltages/etc.

I used two resistors of identical value (any value) for creating Vref, which is just VCC (or whatever it is) / 2. I have seem some circuitry which omits providing a value for Vref; your mileage may vary. Took all of 10 minutes to get working.

OBDII can be a couple different protocols/setups, it may be easier to buy a pre-made setup like Chuckie mentioned, or one which does all of the protocols, or if you only want to deal with a specific time period/manufacturer, you could wire it up yourself pretty easily.

Thanks for the good information. I guess my question is more theoretical than practical. Is an external device or circuit my only way of reading from the CAN bus in a car? What are the CAN pins on the Panda used for if not for this type of scenario?

Thanks for all the help!

The CAN pins on the Panda can be used when interfacing other CAN devices, as long as those other can devices can also communicate at 3.3V. If they are unable to communicate at that voltage level, that’s where a CAN transceiver comes in handy.

That being said, an external circuit is probably the only way to safely interface with an automobile CAN bus. The issue with circuits (all of them, not just CAN) that connect to automobiles is that they generally need to handle transient conditions that other applications don’t have - during engine cranking, I have seen voltages go as low as 8.5V, while during running, I have seen voltages as high as 14.1 (Actually, I had an alternator go bad on me last year and start outputting over 18V - it killed my battery pretty quickly; I’m lucky it didn’t kill anything else.)

I’m also working on putting together a circuit using a Panda along with a Texas Instruments SH65HVD230 to interface with an existing CANBus. This will withstand the transients I talked about earlier.

It’s analogous to using a MAX232 to communicate via RS232 - the FEZ can do Serial without a problem, but not at the voltages required for an RS-232 interface. So, you need either a MAX232 or equivalent, or a USB->serial converter in order to make it work properly unless you’re just using TTL-level signals.

I stumbled across this PDF file that explains a setup using the NXP 23xx series chips - the same chips used in all the FEZ devices - it’s useful to get a better idea of how other people interface using CAN.

You can’t connect CAN directly between devices. A transceiver is a must for CAN.

CAN is completely different from UART in every way.

Yep, you’re right - the high voltage level for can is at least 4V, so you can’t use the CAN lines on the FEZ without a transceiver - I wasn’t thinking about this when I originally wrote my other post.

The problem with CAN is that it is a pain to find out much useful information about it.

I know CAN very well so feel free to ask :wink:

Does anyone have a full schematic for implementing the MCP2551 CAN transceiver with the FEZ Mini? I’m attempting with little luck. Wondering if an additional controller is necessary between the mini and the MCP2551? Also the FEZ Mini documentation refers to a CAN in and out rather than TxD and RxD, may I assume that TxD is Out at RxD is in???


Please start new threads for new topic instead of replying to od one…se we can help you better.

You can use the EMX DevSys schematic which has CAN transceiver already.

I successfully got CAN to talk to itself using PANDA. I used the two separate CAN interfaces on the PANDA and two transceivers.
You will notice that I attached a schematic to the original post.

I finally got it working using the MCP2551 transceiver on the FEZ Mini.
Some Notes:
FEZ Mini > MCP2551 > Note(MCP2551)
Di4 > 1 > TxD
Di2 > 4 > RxD
GND > 2 > Vss
5Vout > 3 > Vdd
GND > 8 > Rs (tie to ground for High Speed)
NA > 7 > CAN Hi to Vehicle
NA > 6 > CAN Low to Vehicle
NA > 5 > Vref (not used)

Working at 250kb/s connected to Vector CANcaseXL logger running CANalyzer
BRP = 12;
T1 = 15;
T2 = 8;