Arduino Nano v3 + MCP2515 8MHz + Vehicle CAN

Hi,

I can not get the CAN data from my vehicle.. The INT pin (2) never enter in LOW mode.

Has anyone ever been able to read using a NANO?

Initialization went OK, even in debug mode there was no error.

Already try this libs (using 125, 250 and 500kbps):

My schema:
Source: github.com/marcio-ota/mb_canbus/blob/master/mb_canbus.ino

Arduino Nano v3
MCP2515 module 8MHz
Step-down

:slightly_frowning_face:

I should cross SI and SO ?? Or close J1 jumper (terminal resistor 120ohms?

Nano x MCP2515
SI <--> SO
SO <--> SI

marcio.ota:
I should cross SI and SO ?? Or close J1 jumper (terminal resistor 120ohms?

Nano x MCP2515
SI <--> SO
SO <--> SI

No, MOSI should go to MOSI and MISO to MISO like you have it or else configuration would have failed.

The Arduino Nano is based off the ATmega328 microcontroller which is what the Duemilanove and the Uno use. I've used the library with plenty of ATmega328 ICs, so there shouldn't be an issue with the Nano.

What CAN bus are you connecting to, a car? Have you tried sending an OBDII PID request? See the code I posted here for a starting point: Can not receive CAN DATA from Arduino UNO with MCP2515 Module. - #12 by coryjfowler - Networking, Protocols, and Devices - Arduino Forum. If you still do not see any received messages, change "CAN0.setMode(MCP_NORMAL);" to "CAN0.setMode(MCP_LOOPBACK);" this will test the protocol controller chip. If that works, your issue lies beyond the protocol controller.

I changed in your code (like nexts posts):

16MHz -> 8MHz

INT on pin 9 -> pin 10

Tried:

CAN0.setMode(MCP_NORMAL); and CAN0.setMode(MCP_LOOPBACK);

#define standard 1 and 0

MCP_ 125/250/500 kbps

But not received data... (from a CAN BUS connector in a Mercedes A200 2014)

Need changes on Tools>Programmer menu? Actually is 'AVRISP mkll'
Can I try another thing?

marcio.ota:
I changed in your code (like nexts posts): [...] INT on pin 9 -> pin 10

I hope you meant the CS pin.

I just tested the code against my vehicle and found some bugs that I fixed. Would you please try it again. I messed up initializing the generic filters and corrected the less generic filters.

Just remember, if you do not receive any messages when using the loopback test, that means there is possibly a wiring issue between the Arduino and the CAN interface or the CAN interface is bad.

Just for example, this is what I expect to see in serial console when connected to a vehicle:

MCP2515 Initialized Successfully!
Simple CAN OBD-II PID Request
Message Sent Successfully!
Extended ID: 0x18DAF110  DLC: 8  Data: 0x06 0x41 0x00 0xBE 0x3E 0xA8 0x13 0x00
Message Sent Successfully!
Extended ID: 0x18DAF110  DLC: 8  Data: 0x06 0x41 0x00 0xBE 0x3E 0xA8 0x13 0x00
Message Sent Successfully!
Extended ID: 0x18DAF110  DLC: 8  Data: 0x06 0x41 0x00 0xBE 0x3E 0xA8 0x13 0x00
Message Sent Successfully!
Extended ID: 0x18DAF110  DLC: 8  Data: 0x06 0x41 0x00 0xBE 0x3E 0xA8 0x13 0x00
Message Sent Successfully!
Extended ID: 0x18DAF110  DLC: 8  Data: 0x06 0x41 0x00 0xBE 0x3E 0xA8 0x13 0x00
Message Sent Successfully!
Extended ID: 0x18DAF110  DLC: 8  Data: 0x06 0x41 0x00 0xBE 0x3E 0xA8 0x13 0x00
Message Sent Successfully!
Extended ID: 0x18DAF110  DLC: 8  Data: 0x06 0x41 0x00 0xBE 0x3E 0xA8 0x13 0x00

Testing again:

Entering Configuration Mode Successful!
Setting Baudrate Successful!
MCP2515 Initialized Successfully!
Simple CAN OBD-II PID Request
Message Sent Successfully!
Standard ID: 0x7E8       DLC: 8  Data: 0x03 0x7F 0x01 0x22 0xAA 0xAA 0xAA 0xAA
Standard ID: 0x7E9       DLC: 8  Data: 0x06 0x41 0x00 0x98 0x18 0x00 0x11 0x00
Message Sent Successfully!
Standard ID: 0x7E8       DLC: 8  Data: 0x03 0x7F 0x01 0x22 0xAA 0xAA 0xAA 0xAA
Standard ID: 0x7E9       DLC: 8  Data: 0x06 0x41 0x00 0x98 0x18 0x00 0x11 0x00
Message Sent Successfully!
Standard ID: 0x7E8       DLC: 8  Data: 0x03 0x7F 0x01 0x22 0xAA 0xAA 0xAA 0xAA
Standard ID: 0x7E9       DLC: 8  Data: 0x06 0x41 0x00 0x98 0x18 0x00 0x11 0x00
Message Sent Successfully!
Standard ID: 0x7E8       DLC: 8  Data: 0x06 0x41 0x00 0xBE 0x3E 0xA8 0x13 0xAA
Standard ID: 0x7E9       DLC: 8  Data: 0x06 0x41 0x00 0x98 0x18 0x00 0x11 0x00
Message Sent Successfully!
Standard ID: 0x7E8       DLC: 8  Data: 0x03 0x7F 0x01 0x22 0xAA 0xAA 0xAA 0xAA
Standard ID: 0x7E9       DLC: 8  Data: 0x06 0x41 0x00 0x98 0x18 0x00 0x11 0x00

When car ignition is on:

0x7E8       DLC: 8  Data: 0x06 0x41 0x00 0xBE 0x3E 0xA8 0x13 0xAA

When off:

0x7E8       DLC: 8  Data: 0x03 0x7F 0x01 0x22 0xAA 0xAA 0xAA 0xAA

How can I dump all data from car???

Well, looks like its all working correctly.

marcio.ota:
How can I dump all data from car???

You can request OBD-II data using the program you are running now. The line:

byte txData[] = {0x02,0x01,0x00,0x55,0x55,0x55,0x55,0x55};

is the payload being sent to onto the CAN bus. The third byte, 0x00, is the PID I have the program requesting. Your output this request tells me what PIDs 0x01 to 0x20 are available. It appears that PIDs 0x01, 0x04, 0x05, 0x0C, 0x0D, 0x1C, and 0x20 are available. If you change the 0x00 in that request to 0x0C, the 0x7E9 message should show engine speed. More info on OBD-II PIDs can be found here: OBD-II PIDs - Wikipedia

Additionally, you can try the receive example sketch included with the library and that should show you anything your vehicle transmits without a request, but be aware that data is usually not disclosed publicly outside of what others may have decoded. Google would be your friend here.

Great! I get a lot of data Standard (over 500kbps and unfiltered). Standard was only from engine? To get data of steering wheel, a/c,... is in extended? If I connect in CAN of radio, its possible get this type of data?

tanks a lot!!!

Edit: Only works if I set:
#define standard 1
// 7E0/8 = Engine ECM
// 7E1/9 = Transmission ECM
#if standard == 1
#define LISTEN_ID 0x7EA
#define REPLY_ID 0x7E0
#define FUNCTIONAL_ID 0x7DF
#else
#define LISTEN_ID 0x98DAF101
#define REPLY_ID 0x98DA01F1
#define FUNCTIONAL_ID 0x98DB33F1
#endif

Why LISTEN_ID and REPLY_ID are needed?

marcio.ota:
Great! I get a lot of data Standard (over 500kbps and unfiltered). Standard was only from engine? To get data of steering wheel, a/c,... is in extended? If I connect in CAN of radio, its possible get this type of data?

tanks a lot!!!

That data could be from anything on the CAN bus. The ID type doesn't mean anything other than how many bits are available in the ID.

marcio.ota:
Edit: Only works if I set:
#define standard 1
// 7E0/8 = Engine ECM
// 7E1/9 = Transmission ECM
#if standard == 1
#define LISTEN_ID 0x7EA
#define REPLY_ID 0x7E0
#define FUNCTIONAL_ID 0x7DF
#else
#define LISTEN_ID 0x98DAF101
#define REPLY_ID 0x98DA01F1
#define FUNCTIONAL_ID 0x98DB33F1
#endif

OBD-II has two standards on CAN, one uses standard IDs and the other uses extended IDs. My old Ford Escape used standard IDs while my 2015 Renegade uses extended.

marcio.ota:
Why LISTEN_ID and REPLY_ID are needed?

They are not used. Its code from another sketch that I used as a base. I was simulating an OBD-II ECM.

I always need to send at least 1 query to start receiving the dump (unfiltered). Is this really necessary? (like to register the new slave ID)

marcio.ota:
I always need to send at least 1 query to start receiving the dump (unfiltered). Is this really necessary? (like to register the new slave ID)

For your vehicle, yes it very well could be. I really have no way to know, but in my experience with a Ford Escape and a Jeep Renegade, they have a constant stream of CAN data when the vehicle ignition is first turned on (engine still off).

The only way to find out is to search for others trying to interface with a similar vehicle by the same make to see what they've found out.

Hi,
I use the same can bus module and the same library. In the standard setting I can get answer on standard OBD pid request - rpm, coolant temp etc. But only when I send request, I get answer.
But I cant recieve no traffic. When I use example to recieve can bus communication, in the terminal is shown nothing.
My car is VW sharan from 2011.

Thank you tor your help

stepos:
Hi,
I use the same can bus module and the same library. In the standard setting I can get answer on standard OBD pid request - rpm, coolant temp etc. But only when I send request, I get answer.
But I cant recieve no traffic. When I use example to recieve can bus communication, in the terminal is shown nothing.
My car is VW sharan from 2011.

Thank you tor your help

same issue here. i cant get any data without request from my 2015 mazda3.
pls help

Search for a car hacking forum specific to your car.
A Google search for "forum mazda 3 can bus hacking" gives 700000 results.

mikb55:
Search for a car hacking forum specific to your car.
A Google search for "forum mazda 3 can bus hacking" gives 700000 results.

good idea.. many thanks for your help, it works now.