Go Down

Topic: Arduino Nano v3 + MCP2515 8MHz + Vehicle CAN (Read 13296 times) previous topic - next topic

marcio.ota

May 12, 2017, 03:44 pm Last Edit: May 12, 2017, 09:19 pm by marcio.ota
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):
github.com/coryjfowler/MCP_CAN_lib
github.com/Flori1989/MCP2515_lib
github.com/autowp/arduino-mcp2515

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



Arduino Nano v3
MCP2515 module 8MHz
Step-down

 :smiley-sad:

marcio.ota

#1
May 12, 2017, 06:58 pm Last Edit: May 12, 2017, 08:45 pm by marcio.ota
I should cross SI and SO ?? Or close J1 jumper (terminal resistor 120ohms?

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

coryjfowler

#2
May 12, 2017, 11:48 pm Last Edit: May 13, 2017, 01:11 am by coryjfowler
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: http://forum.arduino.cc/index.php?topic=402018.msg3209207#msg3209207. 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.
"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

marcio.ota

#3
May 14, 2017, 04:33 am Last Edit: May 14, 2017, 05:11 am by marcio.ota
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?

coryjfowler

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:
Code: [Select]
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


"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

marcio.ota

#5
May 16, 2017, 12:31 am Last Edit: May 16, 2017, 12:36 am by marcio.ota
Testing again:

Code: [Select]
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:
Code: [Select]
0x7E8       DLC: 8  Data: 0x06 0x41 0x00 0xBE 0x3E 0xA8 0x13 0xAA

When off:
Code: [Select]
0x7E8       DLC: 8  Data: 0x03 0x7F 0x01 0x22 0xAA 0xAA 0xAA 0xAA

How can I dump all data from car???

coryjfowler

Well, looks like its all working correctly.  

How can I dump all data from car???
You can request OBD-II data using the program you are running now.  The line:
Code: [Select]
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: https://en.wikipedia.org/wiki/OBD-II_PIDs

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.
"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

marcio.ota

#7
May 17, 2017, 03:19 am Last Edit: May 18, 2017, 02:15 am by 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!!!

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?

coryjfowler

#8
May 18, 2017, 02:28 am Last Edit: May 18, 2017, 02:47 am by coryjfowler
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.

Quote from: 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.

Quote from: 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.
"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

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)

coryjfowler

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.
"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

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

Go Up