Go Down

Topic: Cheap & simple MCP2551/MCP2515 CAN BUS set up (Read 88457 times) previous topic - next topic


DO NOT use MCP_STD or MCP_EXT in the can0.begin(...) function.  There is a bug in the silicon of the MCP2515 and the feature does NOT operate as specified in the datasheet.  The only two solid modes are MCP_ANY or MCP_STDEXT.  I have confirmation from Microchip on the bug.


Below is a proposed resolution from Microchip Engineering Support Team for your Ticket 278363

Area         : Analog/Interface Products
Product Group: SMPINT
Product      : MCP2515

Problem Description:
I have been developing a library for the MCP2515 protocol controller for the Arduino community.  I am at the point where I believe that the issue lies in the IC and not the library.  My issue is with the mask and filtering functions with-in the IC.  I have found that what I am seeing contradicts what the datasheet reads. DS21801G page 27 and 28 inform me that setting RXM1 and RXM0 on the RXBnCTRL register will change how received frames are handled.  Setting those bits to '11' receives everything and ignores the mask and filter functions, setting those bits to '10' will receive only valid extended IDs that meet filter criteria and so on..  I have set those bits to '10' in both registers and I still get standard IDs entering the receive buffer.  I have set up the library to read the register after it has written to the IC and shows the correct values were written.  The same goes if I set those bits to '01' I will still get extended IDs appearing, but, as the data sheet declares, the registers RXFnEID8:RXFnEID0 are ignored.  Basically, it was filtering the first 11 bits of the extended IDs that came in.  This was across more than one IC, though, they were probably from the same lot as they were purchased together from Mouser.  Assistance would be greatly appreciated. 

This is identical to Ticket 273853.

My test bus has standard identifier and extended identifier messages being transmitted on it.  With both masks empty both extended identifiers and standard identifiers entering the receive buffer of the MCP2515 I am using regardless of how the above bits are set which does not correspond to the datasheet as I understand it.

Problem Resolution:
Hi Cory,

I have received feedback from the MCP2515 applications engineer.

In short, he was able to reproduce the observations related to RXM 01 and 10 are not working as described. I am expressed interest in exercising similar tests on the MCP25625, a new CAN module, and exercising a design review of cause if there is a similar result. However, the given the age of the MCP2515 design, it is unlikely the MCP2515 will be reviewed by design and updated.

Observation Summary:
RXM 00 can be used to setup filters.
RXM 11 can be used to receive all messages.
RXM 01 and 10 are not working as described.

Thanks for your persistence,

"Taking the time to make a proper, punctuated, post is a mark of courtesy and respect."  http://forum.arduino.cc/index.php?topic=149022.0


I am trying to set up an CAN network using a can shield from aliexpress with the MCP2515 and a TJA1050 tranceiver.
For the test I am using a arduino nano and your libray Cory.

When I try the Send example the initializing works fine, but then I always get the "error sending message"

Is there a way, to get more debug information? Do I have the send an ack message or something else? I am just reading the can signals from the Arduino with a CAN USB interface which I use at work.

BR Alex


Sep 06, 2016, 05:18 am Last Edit: Sep 06, 2016, 05:28 am by coryjfowler
"Do you have to send the acknowledge"  - No, the acknowledge is a single dominant bit that is sent by any active receiving node on the CAN bus and should be an automatic thing handled by the protocol controller in your USB dongle assuming it is not in a listen-only mode.

What kind of USB dongle is this and are you receiving anything?

If you are receiving a message, I would check to ensure that the USB dongle you are using is in an active mode on the CAN bus (Not listen-only).  

If you are not receiving any messages, I would check to confirm the crystal frequency set in the program matches the actual crystal frequency on the shield and then confirm baud-rates are the same between the program and your USB dongle. (I have see a lot of cheap Chinese boards using 8MHz crystals instead of 16MHz that Seeedstudio and SKPang have used.)
"Taking the time to make a proper, punctuated, post is a mark of courtesy and respect."  http://forum.arduino.cc/index.php?topic=149022.0


Sep 06, 2016, 08:07 am Last Edit: Sep 07, 2016, 06:56 am by Casca
I am using a Vector VN1630 and for viewing the messages I use the trace function in CANape.
No I am not receiving anything. My shield has a 8Mhz crystal so I changed the initialize line to "CAN0.begin(MCP_ANY, CAN_500KBPS, MCP_8MHZ) == CAN_OK)"

For wiring the shield I used Pin10 (CS), Pin11 (MOSI), Pin12 (MISO), 13 (SCK).
This should be correct and also I got the "MCP2515 Initialized Successfully!" message so it seems that the spi connection works.

Edit: I found the error in the Shield. It has a pin header as well as a screw terminal for the CAN connection. The screw terminal somehow seems not be connected properly on the PCB because as I tried the pin header it works just fine!


Sorry about the delay, I just returned from a trip and I didn't have an Arduino with a CAN shield with

I have a clone UNO setup with an old Seeed Studio CAN shield and without any changes to the send example, I am able to see the example message come across CANalyzer at 500k.

Unfortunately the shield I have uses a 16MHz crystal, but I have a MCP2515_CAN break out that uses an 8Mhz crystal and with the frequency modification to the begin function, I see the message come across CANalyzer.

At this point I suspect the shield you sourced may have a bad connection between the protocol controller IC and the transceiver IC, or there is a wiring error between the shield and the CAN dongle.  I assume you also have the bus terminated; at least one termination resistance must be present for reliable communication to occur.
"Taking the time to make a proper, punctuated, post is a mark of courtesy and respect."  http://forum.arduino.cc/index.php?topic=149022.0


for the CAN-BUS Home Automation i made PCBs for use behinde a light switch or power outlet, the pcbs are already in production. This little PCB will have an atmega8 and a MCP2515/TJA1050 Can Bus Transceiver, a Relays for switching / a MOSFET for powering LEDs with pwm.
There are also 7 analog inputs for reading back some things like NTC, LDR or for other useage.
The 8th analog Input replys the state of the relays/mosfet.
There are 8 solder-jumpers for setting the CAN ID (lower 8 Bits of 11)
Here a preview of the pcb:

I use a standart 4 wire telephone cable for CAN-L, CAN-H, GND and 24V.
Every Slave has a little step-down converter to make the 5V.
Somewhere there will be 24V/7Ah PB-Batteries for Backup-Power, so the system runs even mains fail.
The sketch for the master you can see here: CAN MASTER
The sketch for the slave you can see here: CAN SLAVE
These 2 Units are running very stable since about 2 weeks!
I am using standart IDs 000-7FF.
The Master is a UNO+ElecFreaks CAN Shield
the Slave is a Nano with this small MCP2515 PCB,8Mhz.

more updates will be published...


the pcbs has arrived and i assembled two of them, everything works fine!
on my test-setup there are one Nano+2515 pcb, one uno+can-shield, 2 round pcb with atmega8.
one atmega8 runs at 12Mhz, the other one with 8 Mhz, both are more than fast enouhg.
The one round pcb is lighting a LED with PWM, the other one turns on/off a relays.
The Voltage is at the moment 12V, later 24-28V.
On AnalogInput7 there is a VoltageDivider to measure the output, there will be a second voltage divider on A6 for measuring the 24V, so i can read and monitor this.
The next step will be making a website for home automation.


Very nice! Like to see projects using Can Bus, it's very simple, reliable and incredibly cheap.

For your Website, have a look on using Grafana + Influxdb for graphing if you plan to collect sensor and status data. It's very simple to insert data and the create nice dashboards. I have created a little blog showing some basics: https://talk2.wisen.com.au/2016/05/24/influxdb-grafana/

I normally run it on a RPI with a Can Bus (don't forget RPi is 3.3v only) or connected via Serial with another Arduino working as Gateway, but I also have some setups using a Google Cloud VM, sending the data over the I internet.


looks pretty good!
Maybe i will use it for my homeautomation!


So im trying to use this library with a Sparkfun board, it seems as though the transmit buffers are not clearing after the message is being sent. Are the messages in the transmit buffers cleared by the code in this library? Or are they cleared on a receipt of an ACK?


well, i don't know, do you talk about the buffer in the chip or in the arduino?


Hi everyone,

I think this is the most live topic with MCP2515 so I will ask here.

I started playing with CAN Bus in my car. I got MCP2515, the one from the pictures above.
I have changed crystal for 16MHZ. I got some libraries and I made it work.
Or at least partially.
I used CanHacker software to sniff for messages from my CAN, and I got quite few.
I am trying to figure out whats what.

However I decided I want to send messages to the CAN, I have tried different libraries and even one from this post. But I am not sure if it works - I got "message sent successfully" but nothing seems to happening at all.
I only get reaction when I remove delay(100) between messages and the reaction is I have all possible errors on my dashboard - but I think this is due to flooding CAN network.

I decide I want to get information using OBD2 PID request through CAN bus.
So I sent 0x7DF [8] 02 01 0C 00 00 00 00 00 and I suppose to get message back on ID: 0x7E8.
However no matter what I send, I get nothing back.

I am not really sure where to go from this point.
Also, my main thing is I want to get RPM value. I can see which ID and bit is changing with car RPM. But I wasn't able to actually translate that bit HEX value to decimal real RPM value.
Anyone can suggest something with that ?


uneasy, sending CAN messages seems trivial at first, but it isn't. First, you must distinguish between the CAN frame and OBD-II messages. CAN is only the transport of the message, where OBD-II is a protocoll which describes what is carried inside the data.

You can't just send a single frame containing OBD-II information an expect a replay, it's not simple challenge/response. You must first establish a session.

Your car uses a foreign protocoll and codes the messages according to it's own standard. You can, of course determine current RPM from a OBD-II CAN communication, but also direct from the appropriate CAN-Message the powertrain module is sending to other modules in the car, e.g. the instrument-cluster which displays the RPM value by a gauge.

Also there are at least two separated CAN-busses in your car. One for the powertrain and one for comfortsystems (central locking, doors, interior light, etc.). Some cars so have an additional bus for multimedia/audio systems. Not all information is available on every bus. The powertrain is mostly driven at 500 kbit/s whereas the comfort and multimedia is 250 or 125 kbit/s. Often a gateway routes messages from one bus to the other. The OBD-II port of your car is a good place to gain access to the CAN bus(ses). At least HS-CAN (powertrain) and MS-CAN (comfort) are connected here. If you are lucky, they are directly wired to the bus. But some vendors connect the OBD-II port to a special gateway device, which will filter all traffic not wanted or authenticated to the car. This device is most often the router between the busses.

So, without some deeper knowledge of your cars wiring and modules, there are too many pitfalls. You should try to get some wiring diagrams and bus-lists. I done this myself before and believe me to start this way, or will won't get happy. Take a look here, on my website, where you can find the results of my research on Ford Mondeo MK4: http://mk4-wiki.denkdose.de/grundlagen/can-bus/start

I've spend hours and hours loggind CAN data, parsing, filtering and reading logs to know what CAN-ID came from which module, takes what data and how it is assembled. There are hundrets of messages with thousands of different data. To analyze them and find actors, sensors i "invented" some processes. The simplest is to look for differences in data while pushing some button. You can filter out all data not changing while you push a button on your dash and focus on the remaining. Then build a time profile to synchronize a data change with your action. This can mostly be done by looking at CANhacker in Monitor-Mode.

Push buttons are flags/bits and very easy to find. Komplex values hide better :-) Sometimes you need to know how the data is coded, even if you are shure about where in the messages it is. E.G. decimal values often shiftet by the number of their fractional part. So a 28.3 degree value could be in a two byte data, coded as 283. Also values which can have a sign (+ or -) can be coded with an offset. Temperaturevalues for example, often added with 40, so a value of 0 means -40° and a value of 40 means 0° and 60 means +20°.

You must know to divide by 10 to get the value in question. Other values are more complex to calculate, not all are linear. This is the hardest part. Look at OBD-II content. Here you find math to calculate the values. Maybe they are used by the car manufacturers CAN-messages also...


Aug 04, 2017, 03:42 pm Last Edit: Aug 06, 2017, 09:00 am by eltonio

Thank you for sharing your efforts. Seems to be small, universal and eligible for home automation needs CAN slave PCB. Could you share your EAGLE schema project too?


based on the idea of Megahz i created a project on https://github.com/MbedAndroid/Can

its running now on 3 devices now. Got 4 analog inputs, Canident i use a Ds1280 temp controller.
The frames are send to a Mbed which send it up via internet to a Pi
Home automation is running on the Pi

Go Up