Arduino Forum

Using Arduino => Networking, Protocols, and Devices => Topic started by: oasis on May 21, 2016, 01:59 pm

Title: Can not receive CAN DATA from Arduino UNO with MCP2515 Module.
Post by: oasis on May 21, 2016, 01:59 pm
Hi,
I'm trying to receive CAN DATA from Arduino UNO with MCP2515 Module.
I'm not using CAN-BUS Shield and am only using MCP2515 Module(MCP2515 CAN Controller with TJA1050 CAN transceiver. (Attachment #2))
http://www.aliexpress.com/item/MCP2515-CAN-Bus-Module-Board-TJA1050-Receiver-SPI-For-51-MCU-ARM-Controller-NEW/32581650373.html?spm=2114.01010208.8.8.aabjPj

I think that even though I do not use CAN-BUS Shield, I should be able to receive CAN DATA through the MCP2515 module because it includes MCP2515 CAN controller and TJA1050 CAN transceiver.. Is it right?

Here is my test environments:
1) Arduino setting: Attachment #1
OBD2 16pin cable => 6pin(CAN HIGH) and 14pin(CAN LOW) => MCP2515 CAN Module => Arduino UNO

2) CAN Module: Attachment #2
MCP2515 CAN Controller with TJA1050 CAN transceiver.
http://www.aliexpress.com/item/MCP2515-CAN-Bus-Module-Board-TJA1050-Receiver-SPI-For-51-MCU-ARM-Controller-NEW/32581650373.html?spm=2114.01010208.8.8.aabjPj

3) Vehicle : VW Tiguan

I connected several pins between with Arduino and MCP2515 module like below:
Arduino     MPC2515 module
5V            VCC
GND         GND
13            SCK
12            SO
11            SI
10            CS
2              INT

I downloaded MCP_CAN_LIB source files.
https://github.com/coryjfowler/MCP_CAN_lib

And I opened a "receive" example of MCP_CAN_LIB from Arduino IDE and initialized like "CAN0.begin(CAN_500KBPS, MCP_8MHz)" because my chinese clone MCP2515 moudule is using 8 Mhz crystal.

But I could not receive any CAN DATA.
The function "digitalRead(2)" always returns HIGH..

Has anyone got this problem?


Code: [Select]

// demo: CAN-BUS Shield, receive data
#include <mcp_can.h>
#include <SPI.h>

long unsigned int rxId;
unsigned char len = 0;
unsigned char rxBuf[8];

MCP_CAN CAN0(10);                               // Set CS to pin 10


void setup()
{
  Serial.begin(115200);
  CAN0.begin(CAN_500KBPS, MCP_8MHz);                       // init can bus : baudrate = 500k
  pinMode(2, INPUT);                            // Setting pin 2 for /INT input
  Serial.println("MCP2515 Library Receive Example...");
}

void loop()
{
    if(!digitalRead(2))                         // If pin 2 is low, read receive buffer
    {
      CAN0.readMsgBuf(&len, rxBuf);              // Read data: len = data length, buf = data byte(s)
      rxId = CAN0.getCanId();                    // Get message ID
      Serial.print("ID: ");
      Serial.print(rxId, HEX);
      Serial.print("  Data: ");
      for(int i = 0; i<len; i++)                // Print each byte of the data
      {
        if(rxBuf[i] < 0x10)                     // If data byte is less than 0x10, add a leading zero
        {
          Serial.print("0");
        }
        Serial.print(rxBuf[i], HEX);
        Serial.print(" ");
      }
      Serial.println();
    }
}
Title: Re: Can not receive CAN DATA from Arduino UNO with MCP2515 Module.
Post by: robwlakes on May 27, 2016, 07:02 am
Hi Oasis,

I am about to try a very similar set up with a 2007 VW Polo.  (I also own a Tiguan TDI  :) ). 

Have you made any progress?  Your request for assistance does not appear to have been heard?

I have ordered the same MCP2515 board and I have a spare Arduino Micro-Pro that I hope to be able to capture events on the car network to make my Car Radio more automatic.  EG turn off when key removed, dim screen when headlights are on. I am not looking to sample any other data at this stage.

My Polo radio connection has the 2 +-CAN-Bus wires in the loom so I am hoping to be able to tap into them.

Perhaps we can work together? Thank you for information above.  I will use it to get started myself.

Cheers, Rob
Title: Re: Can not receive CAN DATA from Arduino UNO with MCP2515 Module.
Post by: coryjfowler on Oct 05, 2016, 10:44 pm
The code should work with a MCP2510, MCP2515, and an MCP25625, but I have only confirmed it on the latter two ICs.  Additionally, I have tested the library with that very module you linked to and recently infact. 

When you tried the receive example, did you have it connected to the vehicle with the key-switch ON (engine OFF)?
Title: Re: Can not receive CAN DATA from Arduino UNO with MCP2515 Module.
Post by: RickyManfred on Nov 06, 2016, 10:45 pm
Hi Cory

Im trying to use your library to fetch data from a steering angle sensor, data bus it's on is running at 615.3846153846154 Kbit. I tried to modify your library like this;

mcp_can_dfs.h

#define MCP_16MHz_615kBPS_CFG1 (0x00)
#define MCP_16MHz_615kBPS_CFG2 (0xA4)
#define MCP_16MHz_615kBPS_CFG3 (0x01)


My shield is running at 16Mhz and I calculated those values using the spreadsheet included with your library, with BRP set to 0 i get a Time Quantum Max of 13, but I'm not sure I understand it all completely so right now my calculations are pure guesswork.

I tried it in car using the example CAN_recive but with my 615Kbit mod, only result i had was that I managed to get all sorts of warnings on on the cars dashboard when I had the Arduino powered on :)

//Fredrik
Title: Re: Can not receive CAN DATA from Arduino UNO with MCP2515 Module.
Post by: coryjfowler on Nov 07, 2016, 03:01 pm
Fredrik,

It looks good on my end with your sample point being at 84.62%.  The only two items I would change is setting the Sample Mode (SAM) bit to change the bit sampling from one sample to three averaged samples, and increase the Synchronization Jump Width (SJW) to 2, these will only help increase reliability but most likely wont fix your issue.  Outside of this, are you positive this is the baudrate and are you positive you have CAN_H and CAN_L correct (reverse them if not)?

The register modifications I mentioned would look like:
Code: [Select]
#define MCP_16MHz_615kBPS_CFG1 (0x80)
#define MCP_16MHz_615kBPS_CFG2 (0xE4)
#define MCP_16MHz_615kBPS_CFG3 (0x01)
Title: Re: Can not receive CAN DATA from Arduino UNO with MCP2515 Module.
Post by: RickyManfred on Nov 07, 2016, 08:37 pm
Cory, thanks for helping out.

The CAN-bus I'm connecting to is the one found on Saab Trionic 5 and 7 engine management systems. It's quite well documented here: http://www.trionictuning.com (http://www.trionictuning.com).
People active on that forum have written software to communicate with those ECU's over CAN and this is where I found the 615... kbps value. I need this to get the steering angle signal and convert it to an analog signal understandable by a Siemens ECU controlling an AWD system.

/Fredrik
Title: Re: Can not receive CAN DATA from Arduino UNO with MCP2515 Module.
Post by: reynard80 on Apr 03, 2017, 04:57 pm
I have the same setup (Arduino Uno -> MCP2515 -> TJA1050 -> ODB22 pin 6 and 14), and trouble receiving messages from my Peugeot 207.

Connection from the Arduino to the MCP2515 seems to be just fine, but I'm just not receiving any messages. Now I see the register modifactions mentioned here, but I don't really understand them. Could those also be my problem? Do I need to modify the library as well?
Title: Re: Can not receive CAN DATA from Arduino UNO with MCP2515 Module.
Post by: coryjfowler on Apr 03, 2017, 07:17 pm
Are you positive this vehicle has CAN?  The best way to tell is whether there is a physical contact for pins 6 and 14 on the OBDII port of the vehicle.

What baud rates have you tried?  FYI, 250k & 500k are OBDII standards.

Does the board you have come terminated? Remove it if so!  OBDII does not allow a scan tool to have a DC termination.  Also, keep in mind the cable length shouldn't be any longer than 1 meter.

Have you tried swapping the CAN connections going to your the OBDII port?  Eg, the polarity is wrong: CAN_H and CAN_L are reversed and this condition needs corrected.
Title: Re: Can not receive CAN DATA from Arduino UNO with MCP2515 Module.
Post by: reynard80 on Apr 03, 2017, 10:33 pm
Are you positive this vehicle has CAN?  The best way to tell is whether there is a physical contact for pins 6 and 14 on the OBDII port of the vehicle.
Yes, I'm sure. It is a 2008 car and it's mentioned in different specs. Furthermore, some people have been able to hack into the CAN bus for this vehicle, as can ben seen on Youtube (unfortunately they don't respond to my messages for more information).

Quote from: coryjfowler
What baud rates have you tried?  FYI, 250k & 500k are OBDII standards.
Yes, I have tried both.

Quote from: coryjfowler
Does the board you have come terminated? Remove it if so!  OBDII does not allow a scan tool to have a DC termination.  Also, keep in mind the cable length shouldn't be any longer than 1 meter.
The board has a jumper to terminate the connection. I've used the board unterminated. See these schematics (https://ae01.alicdn.com/kf/HTB1h6l.IFXXXXXJaXXXq6xXFXXXG/3pcs-MCP2515-CAN-Bus-Module-TJA1050-receiver-SPI-For-51-MCU-ARM-controller.jpg).

Quote from: coryjfowler
Have you tried swapping the CAN connections going to your the OBDII port?  Eg, the polarity is wrong: CAN_H and CAN_L are reversed and this condition needs corrected.
I have tried, but it actually made the instruments go crazy etc, and I got various diagnostic errors on my dashboard (which disappeared after running the car for a while).
Title: Re: Can not receive CAN DATA from Arduino UNO with MCP2515 Module.
Post by: coryjfowler on Apr 05, 2017, 12:17 am
Have you tried sending an OBD-II PID request?  I'd try at 250k first.   It could just be that the port has a CAN bus dedicated for OBD-II and nothing is broadcast over it.  Outside of that I would investigate your hardware.  The fact that reversing the polarity caused an issue tells me the port is active in some sense.
Title: Re: Can not receive CAN DATA from Arduino UNO with MCP2515 Module.
Post by: reynard80 on Apr 05, 2017, 09:13 pm
Have you tried sending an OBD-II PID request?  I'd try at 250k first.   It could just be that the port has a CAN bus dedicated for OBD-II and nothing is broadcast over it.  Outside of that I would investigate your hardware.  The fact that reversing the polarity caused an issue tells me the port is active in some sense.
That could very well be possible. I haven't tried sending an ODB-II PID. Forgive me if it's a stupid question, but how do I do this with the Arduino and MCP2515? I'm only familiar with sending serial commands via an ELM327.
Title: Re: Can not receive CAN DATA from Arduino UNO with MCP2515 Module.
Post by: coryjfowler on Apr 06, 2017, 02:27 pm
You can give this a whirl, it will probably be the weekend before I can load it on one of my boards and throw it at my car.


Code: [Select]
/* CAN OBD & UDS Simple PID Request
 *
 *  Currently requests PID 0x00 at a 1 second interval and
 *  displays all received CAN traffic to the terminal at 115200.
 *
 *  Written By: Cory J. Fowler  April 5th, 2017
 *
 *  (Disclaimer: Standard IDs are currently UNTESTED against a vehicle)
 *
 */

#include <mcp_can.h>
#include <SPI.h>

#define standard 0
// 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

// CAN TX Variables
unsigned long prevTx = 0;
unsigned int invlTx = 1000;
byte txData[] = {0x02,0x01,0x00,0x55,0x55,0x55,0x55,0x55};

// CAN RX Variables
unsigned long rxID;
byte dlc;
byte rxBuf[8];
char msgString[128];                        // Array to store serial string

// CAN Interrupt and Chip Select Pins
#define CAN0_INT 2                              /* Set INT to pin 2 (This rarely changes)   */
MCP_CAN CAN0(9);                                /* Set CS to pin 9 (Old shields use pin 10) */


void setup(){

  Serial.begin(115200);
  while(!Serial);
 
  // Initialize MCP2515 running at 16MHz with a baudrate of 500kb/s and the masks and filters disabled.
  if(CAN0.begin(MCP_STDEXT, CAN_500KBPS, MCP_16MHZ) == CAN_OK)
    Serial.println("MCP2515 Initialized Successfully!");
  else{
    Serial.println("Error Initializing MCP2515... Permanent failure!  Check your code & connections");
    while(1);
  }

//
//  // Allow all Standard IDs
//  CAN0.init_Mask(0,0x00000000);                // Init first mask...
//  CAN0.init_Filt(0,0x00000000);                // Init first filter...
//  CAN0.init_Filt(1,0x00000000);                // Init second filter...
//  // Allow all Extended IDs
//  CAN0.init_Mask(1,0x80000000);                // Init second mask...
//  CAN0.init_Filt(2,0x80000000);                // Init third filter...
//  CAN0.init_Filt(3,0x80000000);                // Init fouth filter...
//  CAN0.init_Filt(4,0x80000000);                // Init fifth filter...
//  CAN0.init_Filt(5,0x80000000);                // Init sixth filter...

#if standard == 1
  // Standard ID Filters
  CAN0.init_Mask(0,0x7F00000);                // Init first mask...
  CAN0.init_Filt(0,0x7DF0000);                // Init first filter...
  CAN0.init_Filt(1,0x7E10000);                // Init second filter...

  CAN0.init_Mask(1,0x7F00000);                // Init second mask...
  CAN0.init_Filt(2,0x7DF0000);                // Init third filter...
  CAN0.init_Filt(3,0x7E10000);                // Init fouth filter...
  CAN0.init_Filt(4,0x7DF0000);                // Init fifth filter...
  CAN0.init_Filt(5,0x7E10000);                // Init sixth filter...

#else
  // Extended ID Filters
  CAN0.init_Mask(0,0x90FF0000);                // Init first mask...
  CAN0.init_Filt(0,0x90DA0000);                // Init first filter...
  CAN0.init_Filt(1,0x90DB0000);                // Init second filter...

  CAN0.init_Mask(1,0x90FF0000);                // Init second mask...
  CAN0.init_Filt(2,0x90DA0000);                // Init third filter...
  CAN0.init_Filt(3,0x90DB0000);                // Init fouth filter...
  CAN0.init_Filt(4,0x90DA0000);                // Init fifth filter...
  CAN0.init_Filt(5,0x90DB0000);                // Init sixth filter...
#endif

  CAN0.setMode(MCP_NORMAL);                      // Set operation mode to normal so the MCP2515 sends acks to received data.

  // Having problems?  ======================================================
  // If you are not receiving any messages, uncomment the setMode line below
  // to test the wiring between the Ardunio and the protocol controller.
  // The message that this sketch sends should be instantly received.
  // ========================================================================
  //CAN0.setMode(MCP_LOOPBACK);

  pinMode(CAN0_INT, INPUT);                          // Configuring pin for /INT input
 
  Serial.println("Simple CAN OBD-II PID Request");
}

void loop(){

  if(!digitalRead(CAN0_INT)){                         // If CAN0_INT pin is low, read receive buffer
 
    CAN0.readMsgBuf(&rxID, &dlc, rxBuf);             // Get CAN data
  
    // Display received CAN data as we receive it.
    if((rxID & 0x80000000) == 0x80000000)     // Determine if ID is standard (11 bits) or extended (29 bits)
      sprintf(msgString, "Extended ID: 0x%.8lX  DLC: %1d  Data:", (rxID & 0x1FFFFFFF), dlc);
    else
      sprintf(msgString, "Standard ID: 0x%.3lX       DLC: %1d  Data:", rxID, dlc);
 
    Serial.print(msgString);
 
    if((rxID & 0x40000000) == 0x40000000){    // Determine if message is a remote request frame.
      sprintf(msgString, " REMOTE REQUEST FRAME");
      Serial.print(msgString);
    } else {
      for(byte i = 0; i<dlc; i++){
        sprintf(msgString, " 0x%.2X", rxBuf[i]);
        Serial.print(msgString);
      }
    }
      
    Serial.println();
  }
 
  /* Every 1000ms (One Second) send a request for PID 00           *
   * This PID responds back with 4 data bytes indicating the PIDs  *
   * between 0x01 and 0x20 that are supported by the vehicle.      */
  if((millis() - prevTx) >= invlTx){
    prevTx = millis();
    if(CAN0.sendMsgBuf(FUNCTIONAL_ID, 8, txData) == CAN_OK){
      Serial.println("Message Sent Successfully!");
    } else {
      Serial.println("Error Sending Message...");
    }
  }
}


Edit 20170514: Tested and fixed some bugs.  I can confirm that extended ID mode (#define standard 0) works with my vehicle and I unfortunately do not have access to a vehicle that operates in standard ID mode to confirm with.
Title: Re: Can not receive CAN DATA from Arduino UNO with MCP2515 Module.
Post by: reynard80 on Apr 06, 2017, 07:38 pm
Thanks a lot. I've tried your code (just changed 16MHz -> 8MHz, INT on pin 9 -> pin 10).

However, I'm not getting any output other than just the setup of the module. My knowledge in this field is very limited, but could the 8MHz crystal be the problem? Maybe some of the values in the timing registers for 8MHz?

Code: [Select]
Entering Configuration Mode Successful!
Setting Baudrate Successful!
MCP2515 Initialized Successfully!
Starting to Set Mask!
Setting Mask Successful!
Starting to Set Filter!
Setting Filter Successfull!
Starting to Set Filter!
Setting Filter Successfull!
Starting to Set Mask!
Setting Mask Successful!
Starting to Set Filter!
Setting Filter Successfull!
Starting to Set Filter!
Setting Filter Successfull!
Starting to Set Filter!
Setting Filter Successfull!
Starting to Set Filter!
Setting Filter Successfull!
Simple CAN OBD-II PID Request
Title: Re: Can not receive CAN DATA from Arduino UNO with MCP2515 Module.
Post by: coryjfowler on Apr 06, 2017, 09:05 pm
I have tested some of the more common 8MHz baud rate configuration register settings against a Peak adapter and a Vector VN1610, so I trust those to be good. 

I edited the send function to give some indication about when a message was sent or if there was an error while sending.  If there is no error while sending and your car doesn't exhibit any signs we are corrupting signals (like when the CAN line polarity was reversed), it should be safe to assume the baudrate of 250k is correct.  In that case, try changing the 1 in "#define standard 1" to a 0 to try OBD-II with extended IDs.  Otherwise, try it again, but only changing the baudrate to 500k.

If you get send errors at both 250k and 500k, change "CAN0.setMode(MCP_NORMAL);" to "CAN0.setMode(MCP_LOOPBACK);".  You should see the one packet we transmit come right back and display on the screen.  This will confirm your protocol controller is functioning as it should and that it is correctly wired to the Arduino.

If you do not see a received message, check your INT pin connection and the definition for it in the sketch.

If you see the received message while in loop back, I would check the connection between the protocol controller and the transceiver making sure that there is continuity between the ICs and that there are not shorts to ground, power, or another signal.
Title: Re: Can not receive CAN DATA from Arduino UNO with MCP2515 Module.
Post by: reynard80 on Apr 07, 2017, 02:10 pm
I have tested some of the more common 8MHz baud rate configuration register settings against a Peak adapter and a Vector VN1610, so I trust those to be good.  
Ok, it was just a thought, because 16MHz seem to be 'standard'.

I edited the send function to give some indication about when a message was sent or if there was an error while sending.  If there is no error while sending and your car doesn't exhibit any signs we are corrupting signals (like when the CAN line polarity was reversed), it should be safe to assume the baudrate of 250k is correct.  In that case, try changing the 1 in "#define standard 1" to a 0 to try OBD-II with extended IDs.  Otherwise, try it again, but only changing the baudrate to 500k.
I got the error message, both with 250k and 500k. I got the error message both when connected to the car, and when not connected to a CAN bus at all.

I measured the voltage with a multimeter on the ODBII port in the car, and when not connected to my project, the voltages are DC 2.56V both on H and L.

If you get send errors at both 250k and 500k, change "CAN0.setMode(MCP_NORMAL);" to "CAN0.setMode(MCP_LOOPBACK);".  You should see the one packet we transmit come right back and display on the screen.  This will confirm your protocol controller is functioning as it should and that it is correctly wired to the Arduino.

If you do not see a received message, check your INT pin connection and the definition for it in the sketch.

If you see the received message while in loop back, I would check the connection between the protocol controller and the transceiver making sure that there is continuity between the ICs and that there are not shorts to ground, power, or another signal.
I actually see the received message in loopback, so that seems to work. I have also checked the PCB for continuity between the MCP2515 and the TJA1050. Also, the VCC and GND connections seem to be working properly. I'm wondering however if maybe the VCC for the transceiver chip is too low, as I'm measuring 4.01V over the VCC and GND. The datasheet says 4.75V minimum. But maybe it is just normal to measure a lower voltage when the IC is running?
Title: Re: Can not receive CAN DATA from Arduino UNO with MCP2515 Module.
Post by: coryjfowler on Apr 07, 2017, 04:21 pm
Yes, I would say that voltage definitely needs fixed.  It should be much closer to 5.0 than that.
Title: Re: Can not receive CAN DATA from Arduino UNO with MCP2515 Module.
Post by: reynard80 on Apr 09, 2017, 08:52 pm
The (first) module I used may actually be faulty. I have acquired a second module, which gives normal values on the VCC voltages and I actually am receiving messages now!

However, with your code, I'm receiving messages, but the sending of the message keeps failing, like below. The CAN_receive example gives me just the Standard ID messages, so that seems to work now.

Code: [Select]
Entering Configuration Mode Successful!
Setting Baudrate Successful!
MCP2515 Initialized Successfully!
Starting to Set Mask!
Setting Mask Successful!
Starting to Set Filter!
Setting Filter Successfull!
Starting to Set Filter!
Setting Filter Successfull!
Starting to Set Mask!
Setting Mask Successful!
Starting to Set Filter!
Setting Filter Successfull!
Starting to Set Filter!
Setting Filter Successfull!
Starting to Set Filter!
Setting Filter Successfull!
Starting to Set Filter!
Setting Filter Successfull!
Simple CAN OBD-II PID Request
Standard ID: 0x2F5       DLC: 3  Data: 0x5E 0x00 0x80
Error Sending Message...
Standard ID: 0x2F5       DLC: 3  Data: 0x4F 0x00 0x80
Error Sending Message...
Standard ID: 0x488       DLC: 8  Data: 0x3D 0x00 0x70 0x00 0x1E 0x3C 0xFF 0x3D
Error Sending Message...
Standard ID: 0x612       DLC: 5  Data: 0x73 0x20 0x01 0x36 0x00
Error Sending Message...
Standard ID: 0x38D       DLC: 7  Data: 0x00 0x00 0x00 0x00 0xAF 0xD1 0x00
Error Sending Message...
Standard ID: 0x432       DLC: 6  Data: 0x81 0x59 0x48 0xFE 0x00 0x00
Error Sending Message...
Error Sending Message...
Standard ID: 0x348       DLC: 8  Data: 0x00 0x4F 0x2D 0x44 0xC0 0x01 0x00 0x40
Error Sending Message...
Error Sending Message...
Error Sending Message...
Error Sending Message...
Error Sending Message...
Standard ID: 0x412       DLC: 8  Data: 0x18 0x00 0x00 0x00 0x00 0x3C 0x0A 0x00
Error Sending Message...
Standard ID: 0x072       DLC: 5  Data: 0x02 0x00 0x00 0x00 0x00
Error Sending Message...
Standard ID: 0x208       DLC: 8  Data: 0x00 0x00 0x21 0x00 0x0C 0xFF 0xFF 0x4F
Error Sending Message...
Standard ID: 0x2F5       DLC: 3  Data: 0xC7 0x00 0x80
Error Sending Message...
Standard ID: 0x348       DLC: 8  Data: 0x00 0x4F 0x2D 0x44 0xC0 0x01 0x00 0x40
Error Sending Message...
Standard ID: 0x2F5       DLC: 3  Data: 0x4F 0x00 0x80
Error Sending Message...
Standard ID: 0x208       DLC: 8  Data: 0x00 0x00 0x21 0x00 0x0C 0xFF 0xFF 0x4F
Error Sending Message...
Standard ID: 0x2F5       DLC: 3  Data: 0x03 0x00 0x80
Error Sending Message...
Standard ID: 0x2F5       DLC: 3  Data: 0x7C 0x00 0x80
Error Sending Message...
Standard ID: 0x2F5       DLC: 3  Data: 0x6D 0x00 0x80
Error Sending Message...
Standard ID: 0x348       DLC: 8  Data: 0x00 0x4F 0x2D 0x44 0xC0 0x01 0x00 0x40
Error Sending Message...
Standard ID: 0x30D       DLC: 8  Data: 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
Error Sending Message...
Error Sending Message...
Standard ID: 0x30D       DLC: 8  Data: 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
Error Sending Message...
Standard ID: 0x30D       DLC: 8  Data: 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
Error Sending Message...
Error Sending Message...
Error Sending Message...
Error Sending Message...
Error Sending Message...
Error Sending Message...
Error Sending Message...
Error Sending Message...
Error Sending Message...
Error Sending Message...
Error Sending Message...
Error Sending Message...
Error Sending Message...
Error Sending Message...
Error Sending Message...
Standard ID: 0x348       DLC: 8  Data: 0x00 0x4F 0x2D 0x44 0xC0 0x01 0x00 0x40
Error Sending Message...
Standard ID: 0x2F5       DLC: 3  Data: 0xC7 0x00 0x80
Error Sending Message...
Standard ID: 0x38D       DLC: 7  Data: 0x00 0x00 0x00 0x00 0xAF 0x1D 0x00
Error Sending Message...
Standard ID: 0x592       DLC: 3  Data: 0x00 0x00 0x00
Error Sending Message...
Standard ID: 0x2F5       DLC: 3  Data: 0x4F 0x00 0x80
Error Sending Message...
Error Sending Message...
Title: Re: Can not receive CAN DATA from Arduino UNO with MCP2515 Module.
Post by: coryjfowler on Apr 10, 2017, 01:58 pm
Does it send okay in loopback mode?  I'd fault the module again if so, since it sounds like the TX CAN connection between the protocol controller and the transceiver might be open or shorted to something.

Glad to see that you're seeing messages from your vehicle though.
Title: Re: Can not receive CAN DATA from Arduino UNO with MCP2515 Module.
Post by: reynard80 on Apr 11, 2017, 03:10 pm
I have been working on it a bit more, but I am getting such strange results.

Does it send okay in loopback mode?  I'd fault the module again if so, since it sounds like the TX CAN connection between the protocol controller and the transceiver might be open or shorted to something.

Glad to see that you're seeing messages from your vehicle though.
Sending of the message in loopback mode does actually work. But it is also working when I just connect two modules with terminators. A 'local' CAN bus with two modules and two arduinos does seem to work just fine. I can send and receive messages on both modules. The voltages on the modules also seem in order.

Radio and steering wheel controls
As mentioned above, I finally got messages on the ODB2 port. However, they don't contain the data I'm looking for, namely the steering wheel controls for the radio (as my project is trying to use the steering wheel buttons to control some media players in the car).

To my understanding, the steering wheel controls work via CAN bus. This can also be seen when looking for commercially available adapters (http://Peugeot Steering Wheel Interface with RD4 / RT4 With CAN-Bus & Stalk Controls Order RPG001 to retain rear parking sensors. head units compatible with the following Vehicles: Peugeot 307 (2005 onwards) Peugeot 807 (2005 onwards) Peugeot 407 (2005 onwards) Peugeot 207 (2006 onwards) Peugeot 308 (2007 onwards) Peugeot 307 : 2005 Onwards Peugeot 408) and in this specification  (https://autowp.github.io/)of peugeot CAN bus messages.

So I tried connecting a module to the CAN bus wires of the radio (per this  (http://www.tehnomagazin.com/Auto-radio-car-connector/PEUGEOT-Car-Radio-Wiring-Connector.htm)schematic, for example). But this gave some strange results;

I'm actually quite lost now on what is happening here, and how to proceed :smiley-confuse:



PS. Sorry to the original poster for 'hijacking' your topic a bit  :smiley-roll-sweat:


Title: Re: Can not receive CAN DATA from Arduino UNO with MCP2515 Module.
Post by: coryjfowler on Apr 11, 2017, 04:27 pm
So I tried connecting a module to the CAN bus wires of the radio (per this  (http://www.tehnomagazin.com/Auto-radio-car-connector/PEUGEOT-Car-Radio-Wiring-Connector.htm)schematic, for example). But this gave some strange results;
Did those wires appear to be twisted together by chance?  That's usually a good indicator of some type of digital bus.  Also, its not unheard of for extra CAN buses to be populated on the OBD-II manufacture's discretion pins.  My old Escape had two and my new Jeep has three on the port.  (I found them via trial and error.)

At this point, I'd say you'd need an oscilloscope to see what is actually going on between your car and the CAN module.  Something just isn't right and its interesting that they work fine together, but not with your car.
Title: Re: Can not receive CAN DATA from Arduino UNO with MCP2515 Module.
Post by: reynard80 on Apr 12, 2017, 12:06 pm
I have managed to get hold of the electrical schemas of the car and this explains a lot. There are indeed multiple CAN buses in the car. The radio is on a seperate comfort CAN bus, which runs on 125kbps. So that explains quite a bit.

I've also read a bit more into CAN bus specifications and this clears things up quite a bit. The radio CAN bus signals actually are typical for a Low speed or Fault tolerant CAN bus. High speed transceivers are not compatible with such a bus, so I'll have to find a suitable fault tolerant CAN bus transceiver. Maybe build my own PCB.

Quote from: Wikipedia
Low speed/Fault tolerant CAN signaling drives the CAN high wire towards 5V and the CAN low wire towards 0V when transmitting a dominant (0), and does not drive either wire when transmitting a recessive (1). The dominant differential voltage must be greater than 2.3V (with a 5V Vcc) and the recessive differential voltage must be less than 0.6V The termination resistors passively return the CAN low wire to RTH where RTH is a minimum of 4.7V (Vcc-0.3V where Vcc is 5V nominal) and the CAN high wire to RTL where RTL is a maximum of 0.3V. Both wires must be able to handle -27 to 40V without damage.
(https://upload.wikimedia.org/wikipedia/commons/thumb/4/44/ISO11898-3_Waveform.svg/660px-ISO11898-3_Waveform.svg.png)
High speed transceivers are not compatible with such a bus, so I'll have to find a suitable fault tolerant CAN bus transceiver. Maybe build my own PCB. My question now is, will the MCP2515 controller and library work with such a transceiver?

My question now is, will the MCP2515 controller and library work with such a transceiver?
Title: Re: Can not receive CAN DATA from Arduino UNO with MCP2515 Module.
Post by: coryjfowler on Apr 13, 2017, 06:00 pm
My question now is, will the MCP2515 controller and library work with such a transceiver?
The transceiver and physical bus are independent of the protocol controller and the library wouldn't even notice the difference.

From a quick look, it appears that all low-speed transceivers are larger than a SOIC8 package due to the extra pins required for the termination resistors among other features, so a board would need to be made for this.  Looking at how each device is terminated, it seems to me that a good confirmation of your thought about the bus being low-speed fault-tolerant would be to disconnect the battery and measure the resistance between the CAN High and CAN Low of that bus to see if it reads around 60 ohms or not.  From what I'm seeing, I would expect a higher resistance or an open to be read when they are unpowered, but I could be wrong as I've not messed with this physical specification yet.  Its also worthy to note that a low-speed fault-tolerant bus is designed for a specific number of nodes in mind since each device has a termination resistance.  Hopefully the vendor thought about future proofing and the total line resistance is greater than 100 ohms allowing for an additional device or so.

Now I'm suddenly skeptical about my Jeep's 125k bus even though the high speed transceivers in the CAN adapter I was using was reading the data fine.
Title: Re: Can not receive CAN DATA from Arduino UNO with MCP2515 Module.
Post by: reynard80 on Apr 18, 2017, 10:29 pm
The transceiver and physical bus are independent of the protocol controller and the library wouldn't even notice the difference.
I thought and hoped so already. so that's good to hear..

From a quick look, it appears that all low-speed transceivers are larger than a SOIC8 package due to the extra pins required for the termination resistors among other features, so a board would need to be made for this.  Looking at how each device is terminated, it seems to me that a good confirmation of your thought about the bus being low-speed fault-tolerant would be to disconnect the battery and measure the resistance between the CAN High and CAN Low of that bus to see if it reads around 60 ohms or not.  From what I'm seeing, I would expect a higher resistance or an open to be read when they are unpowered, but I could be wrong as I've not messed with this physical specification yet.  Its also worthy to note that a low-speed fault-tolerant bus is designed for a specific number of nodes in mind since each device has a termination resistance.  Hopefully the vendor thought about future proofing and the total line resistance is greater than 100 ohms allowing for an additional device or so.

Now I'm suddenly skeptical about my Jeep's 125k bus even though the high speed transceivers in the CAN adapter I was using was reading the data fine.

I want to make my own board indeed, soldering a PCB is not a real problem. I have looked in to some circuit diagrams and it seems pretty easy to do.

The termination is good point though, I also read about this. I think the manufacturer thought about at least one more device, as there is a connection to a CD changer available on the radio with CANL and CANH. Also, there is an option for a handsfree set, which I don't have. I'm thinking of using the CD changer connection (this way I'll also have a neat solution for connecting my device).

Determining the value of the termination resistors is one thing I'll have to solve indeed. But I'm not sure how to do this exactly. I have included a (crude, sorry for that) diagram of the ECU's, as found in the official technical documentation of the car. So it seems I have six nodes on this bus, but I am not sure how to find the value for the termination resistors for my project. I'm not sure how to measure the termination resistance of each node, as measuring over CANH and CANL is not correct in this case I think. CANH and CANL don't seem to be connected by the termination resistance.

(http://www.ni.com/cms/images/devzone/tut/LS_CAN_Termination.gif)

Update for future searchers:

I managed to receive messages on the comfort/fault tolerant/low speed CAN bus of my Peugeot 207, via the RD4 radio. I finally got it working with the circuit as described in this  (https://www.google.nl/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&cad=rja&uact=8&ved=0ahUKEwiM__K2zbLTAhURIVAKHfxMBy4QFggnMAA&url=http%3A%2F%2Fcta.physik.uzh.ch%2Fpublic%2Ftheses%2Ffiles%2F2014-WidmerTimothy-Bachelor.pdf&usg=AFQjCNHGWuD-NMnzkVpUvh4h6lDd-1e-ew&sig2=-kTvPKq5glX92OZ67d4w8g)paper. Comparable designs and more information can also be found on a few German and Russian forums. Google Translate is my friend  :)

I still have to develop a refined 'production' board, as I now only have a breadboard prototype. Also, I haven't tested sending messages yet.
Title: Re: Can not receive CAN DATA from Arduino UNO with MCP2515 Module.
Post by: reynard80 on Apr 26, 2017, 10:55 am
While I have a working board now, I'm still running into some trouble. I'm receiving messages, but after a short while, this stops. It seems the MCP2515 does not give an interupt anymore, as there is some error situation.

The error does not seem to be with the transceiver, as it does not signal an error on its error-pin.

Is it possible to see the errors the MCP2515 encounters, with the library? When I read the datasheet, it seems that error flags can be read from the chip register? How can this be done?
Title: Re: Can not receive CAN DATA from Arduino UNO with MCP2515 Module.
Post by: coryjfowler on Apr 26, 2017, 05:07 pm
Is it possible to see the errors the MCP2515 encounters, with the library? When I read the datasheet, it seems that error flags can be read from the chip register? How can this be done?
Add the below to your main loop someplace.  When an error occurs, it will flood your terminal window.
With this piece of code in the main loop of my J1939 test application connected to my bench bus that has an ECM on it, I eventually get a receive buffer 0 overflow error which I expect to get on occasion since the ECM transmits cyclic messages at some high rates.

Code: [Select]
if(CAN0.checkError() == CAN_CTRLERROR){
    Serial.print("Error register value: ");
    byte tempErr = CAN0.getError() & MCP_EFLG_ERRORMASK; // We are only interested in errors, not warnings.
    Serial.println(tempErr, BIN);
   
    Serial.print("Transmit error counter register value: ");
    tempErr = CAN0.errorCountTX();
    Serial.println(tempErr, DEC);
   
    Serial.print("Receive error counter register value: ");
    tempErr = CAN0.errorCountRX();
    Serial.println(tempErr, DEC);
   
    //I do not have a function that clears errors and that has been added to my todo list. 04/26/17 CJF
  }
Title: Re: Can not receive CAN DATA from Arduino UNO with MCP2515 Module.
Post by: reynard80 on May 11, 2017, 01:42 pm
Add the below to your main loop someplace.  When an error occurs, it will flood your terminal window.
With this piece of code in the main loop of my J1939 test application connected to my bench bus that has an ECM on it, I eventually get a receive buffer 0 overflow error which I expect to get on occasion since the ECM transmits cyclic messages at some high rates.
...
Thanks, is there an overview of the error codes somewhere? I can't find it in the datasheet, or am I overlooking it? I am receiving errors like this, where the counter is counting down:

Code: [Select]

Error register value: 1000000
Transmit error counter register value: 0
Receive error counter register value: 65
Title: Re: Can not receive CAN DATA from Arduino UNO with MCP2515 Module.
Post by: coryjfowler on May 11, 2017, 09:30 pm
The error bits are read from the EFLG (ERROR FLAG) register of the MCP2515.  Looks like the 6th bit is set which the datasheet (http://ww1.microchip.com/downloads/en/DeviceDoc/21801e.pdf) says is RX0 overflow which is expected on a busy CAN bus.  What concerns me is the 65 receive errors...
Title: Re: Can not receive CAN DATA from Arduino UNO with MCP2515 Module.
Post by: reynard80 on May 12, 2017, 10:05 pm
The error bits are read from the EFLG (ERROR FLAG) register of the MCP2515.  Looks like the 6th bit is set which the datasheet (http://ww1.microchip.com/downloads/en/DeviceDoc/21801e.pdf) says is RX0 overflow which is expected on a busy CAN bus.  What concerns me is the 65 receive errors...
This may be a rather stupid question, but how do you see the 6th bit is set? Because there are 6 zeroes?
I think it is a busy CAN bus indeed, but does this mean the controller just hasn't got enough capacity to handle this busy bus? Or can something be done about it? Will setting a mask/filter help keeping the RX buffer from overflowing?
Title: Re: Can not receive CAN DATA from Arduino UNO with MCP2515 Module.
Post by: coryjfowler on May 12, 2017, 11:36 pm
I have the serial output formatted to binary in the error code snippet, just need to see a 1 and its zero-based position.

As for overflow, its not typically an issue unless RX1 also overflowed since I have the BUKT bit set by default.  BUKT being set moves the packet from RX0 to RX1 when a received message is destined for RX0. Filtering for only the CAN IDs you are interested in would definitely alleviate any overflows.  Anything to increase the microcontroller's ability to read from the CAN controller would also help, like increasing the SPI clock speed, removing/fixing blocking functions, limiting unnecessary serial writes and/or increasing the serial speed, etc.

As for the SPI clock speed, Arduino added some new SPI features that I've not had time to incorporate into the library and test out which has been on the todo list.  Something like SPISettings(10000000, MSBFIRST, SPI_MODE0) added below the CAN0.begin(...) function would help maximize the SPI clock.
Title: Re: Can not receive CAN DATA from Arduino UNO with MCP2515 Module.
Post by: muekno on Dec 01, 2017, 03:12 pm
have similar problems than above. I use the sketch from post #11. I use the Nirem CAN interface. If I set it to 500 kbs and 8 MHz and LOOPBACK Mode I get initialized OK, and send message OK, but do not receive anything. If I set it to 125 kbs I get an iitialization error.
As some wrote low baudrates are not working fine with 8 MHz cristal. I bulld up a circuit with original MCP2515 DILand 16 Mhz cristal. Here I get and send message error with the same sketch. I think it is clear that I changed the initializtions string acording the cristal. Adrduino board isoriginal Arduino UNO with the SMD Arduino.
connections are CS=10, SO =12, SI=11,SCK=13,INT=2
Thanks for any help or hint
Title: Re: Can not receive CAN DATA from Arduino UNO with MCP2515 Module.
Post by: coryjfowler on Dec 02, 2017, 07:25 am
I use the Nirem CAN interface.
This thing? https://wiki.kewl.org/dokuwiki/_detail/interfaces:niren.jpg?id=interfaces%3Aniren (https://wiki.kewl.org/dokuwiki/_detail/interfaces:niren.jpg?id=interfaces%3Aniren)

You would be somewhere around the third individual to have no luck with those boards and unless you have access to an actual CAN interface dongle and tools(Peak, Kvaser, Vector, etc) troubleshooting will be difficult.  I cannot recommend that CAN interface board.
Title: Re: Can not receive CAN DATA from Arduino UNO with MCP2515 Module.
Post by: Christer_A on Dec 21, 2017, 01:57 pm
I have Arduino UNO and Mega2560 with CAN bus shields from SEEED and Sparcfun and everything works fine.
These shields use a 16MHz Q.
Tested against each other RX/TX, Keysight Oscilloscope with CAN bus capability, against Garmin nmea2000 marine network and finally against Märklin digital toy train ! (Märklin uses CAN bus also...)
Eveything works perfectly!

I now use the CAN library from Cory Fowler with support also for 8 MHz.
Now I also have tried the NiRem Canbus board from China with a 8 MHz Q.
Tested 4 pieces and it simply does not work (only modification in code is 8MHz).

I think the problem is in these boards/PCB. I have run out of ideas to test more.
Title: Re: Can not receive CAN DATA from Arduino UNO with MCP2515 Module.
Post by: Christer_A on Dec 21, 2017, 07:59 pm
Regarding CAN library I am a bit confused.

In early 2016 I used the library from SEEED studio. This worked fine for my experiments.
However there was no support for other than 16 MHz Q.

Then in 2016 I used The library from Cory Fowler, and also changed some of my code. In this library there are support also for 8 MHz Q (and other).
I also noticed not to use   "CAN.getCanId();  ".

Now I see a new library from Adlerweb and still the use of   "CAN.getCanId();


As I am new to this I would appreciate some clarifications.

And what library to use.


Title: Re: Can not receive CAN DATA from Arduino UNO with MCP2515 Module.
Post by: coryjfowler on Dec 21, 2017, 11:52 pm
Regarding CAN library I am a bit confused. [...]
I also noticed not to use   "CAN.getCanId();  ".

Now I see a new library from Adlerweb and still the use of   "CAN.getCanId();
I removed it because I gave the CAN receive function ("CAN0.readMsgBuf(&rxID, &len, rxBuf)") the ability get that information into the user's "sketch" in one function call instead of two.

I would go to assume Adlerweb forked his version of the library before my changes we made.  At one point my change made it to Seeed's library, but they added it back for whatever reason.

As I am new to this I would appreciate some clarifications.

And what library to use.

You're welcome to use any library you want, but the sweet thing is, if you use mine I am more willing to help you when a problem occurs.  For instance, if you want to send me a couple of those boards you're not having luck with, I can take a look at them and see what I can come up with.

I actually have two of those boards I linked to in my previous post on this thread working, but I've not had near as many issues as I've encountered from the community which makes me feel like a counterfeit part is ruining an otherwise nice product.

PM me if you're interested.
Title: Re: Can not receive CAN DATA from Arduino UNO with MCP2515 Module.
Post by: Christer_A on Dec 22, 2017, 09:01 pm
Using the Cory Fowler library.
I forgot to say that the 8MHz "NiRem" board Initialize correct.
But there is nothing transmitted on the CAN bus.

Today I tested 3 other CAN shields. The 1.2 version from SEEED, Sparcfun CAN bus shild and also a shield from ElecFreaks in China. All three with the same formfactor and using 16 MHz Q.
Tested these shields tested against different Arduini UNO and MEGA 2560.

Everything works fine.

Checked against Garmin GPS plotter with nmea2000 network and also tested against a Microchip CAN development box.

It is only the NiRem boards that will not work !
 
Title: Re: Can not receive CAN DATA from Arduino UNO with MCP2515 Module.
Post by: coryjfowler on Dec 23, 2017, 05:33 pm
Using the Cory Fowler library.
I forgot to say that the 8MHz "NiRem" board Initialize correct.
But there is nothing transmitted on the CAN bus.
Correct.  I have seen this from others before you.  I purchased a few of those boards a year ago and they did work for me.  I do not know what is going on with the other boards until I get my hands on some, but I suspect a bad, possibly counterfeit, part.

Today I tested 3 other CAN shields. The 1.2 version from SEEED, Sparcfun CAN bus shild and also a shield from ElecFreaks in China. All three with the same formfactor and using 16 MHz Q.
Tested these shields tested against different Arduini UNO and MEGA 2560.

Everything works fine.
That's great!  Glad those are working fine.

Checked against Garmin GPS plotter with nmea2000 network and also tested against a Microchip CAN development box.
Oh thats nice... I need to borrow one of those so I can figure out the plotter turns GLONASS on in the GPS I have.  They will not give me any information on their NMEA 2K GPS, its pretty silly.  I have a sketch decoding the output of the GPS otherwise.

It is only the NiRem boards that will not work !
I'm as baffled as you are until I can investigate further.
Title: Re: Can not receive CAN DATA from Arduino UNO with MCP2515 Module.
Post by: Christer_A on Dec 31, 2017, 12:38 pm
Problem solved !
Thanks Cory Fowler for support.
The main problem was some bad cables between the Arduino and the NiRem board !
Stupid problem.  I tried several boards but I did not change the cables.

When digging into this I could not resist to build my own CAN BUS "shield" on a breadboard.
Jpg attached. The local electronics shop here in my town stores MCP2515, MCP2551 and also 8 and 16 MHz Quarz. I did not expect this. This breadboard shield worked directly, and was very stable.
Easy to change between 8 and 16 MHz Quarz.
I also added two LEDs with resistors for TXD and RXD so I could get indication of something transmitted and received.

I now have 3 NiRem boards here and 2 of them works perfectly. The third one is not stable. When moving my finger on the PCB it could stop working or start working.
Title: Re: Can not receive CAN DATA from Arduino UNO with MCP2515 Module.
Post by: rrdesign on Feb 13, 2018, 11:48 am
i am using the elekfreaks shield with Arduino UNO and SparkFun Can Library. Everything's working fine. I tried to use coryjfowler's can Lib because i need dual can support. I connected 2 shield to Arduino, one shield with INT 2 and CS 10 and the other with INT 3 and CS 9. both CAN: Init OK Baudrate Successful and Configuration Mode Successful. i can see data incoming. The RX Led is blinking but nothing is being printed on the serial console. I tried the receive example with one shield attached only. But same problem. Everything is been initialized ok but i am not receiving anything. The shield is running on 16 Mhz. With the same setup i can start the receive example script from spark fun library and its working fine. (without changing any wires)  what could be the problem?

Code: [Select]
// Demo: Dual CAN-BUS Shields, Data Pass-through
// Written by: Cory J. Fowler
// January 31st 2014
// This examples the ability of this library to support more than one MCP2515 based CAN interface.


#include <mcp_can.h>
#include <SPI.h>

unsigned long rxId;
byte len;
byte rxBuf[8];

byte txBuf0[] = {};
byte txBuf1[] = {};

MCP_CAN CAN0(10);                              // CAN0 interface usins CS on digital pin 10
MCP_CAN CAN1(9);                               // CAN1 interface using CS on digital pin 9

void setup()
{
  Serial.begin(115200);
 
  // init CAN0 bus, baudrate: 250k@16MHz
  if(CAN0.begin(MCP_ANY, CAN_100KBPS, MCP_16MHZ) == CAN_OK){
  Serial.print("CAN0: Init OK!\r\n");
  CAN0.setMode(MCP_NORMAL);
   pinMode(2, INPUT); 
  } else Serial.print("CAN0: Init Fail!!!\r\n");
 
  // init CAN1 bus, baudrate: 250k@16MHz
  if(CAN1.begin(MCP_ANY, CAN_100KBPS, MCP_16MHZ) == CAN_OK){
  Serial.print("CAN1: Init OK!\r\n");
  CAN1.setMode(MCP_NORMAL);
   pinMode(3, INPUT); 
  } else Serial.print("CAN1: Init Fail!!!\r\n");
 
  SPI.setClockDivider(SPI_CLOCK_DIV2);         // Set SPI to run at 8MHz (16MHz / 2 = 8 MHz)
}

void loop(){ 
  if(!digitalRead(2)){                         // If pin 2 is low, read CAN0 receive buffer
    CAN0.readMsgBuf(&rxId, &len, rxBuf);       // Read data: len = data length, buf = data byte(s)
    if(rxId == 0x130)
    {
      Serial.println("0x130 empfangen");
      byte rxBuf[5] = {0x45,0x41,0x21,0x8F,0x57};
      CAN1.sendMsgBuf(rxId, 0, len, rxBuf);
    }
    else       
      CAN1.sendMsgBuf(rxId, 0, len, rxBuf);      // Immediately send message out CAN1 interface
  } 
  if(!digitalRead(3)){                         // If pin 3 is low, read CAN1 receive buffer
    CAN1.readMsgBuf(&rxId, &len, rxBuf);       // Read data: len = data length, buf = data byte(s)
    Serial.print("ID: ");
    Serial.print(rxId,HEX);
    Serial.print(", ");
    Serial.print("Data: ");
    for(int i=0;i<len;i++)
    {
      Serial.print(rxBuf[i],HEX);
      Serial.print(" ");
    }
    Serial.println("");
  }
}

/*********************************************************************************************************
  END FILE
*********************************************************************************************************/
Title: Re: Can not receive CAN DATA from Arduino UNO with MCP2515 Module.
Post by: kenzcode on Mar 08, 2018, 04:54 am
Having just about wasted the whole day trying to get a simple send/receive working, using two Nano v3.0s and two NiRen MCP2515 modules. (Using Corys wonderfull library with crystal set to 8Mhz)

The problem turned out to be that Nano V3.0 powered from it's USB port does not provide enough voltage to allow the NiRen modules to function correctly....

They look like they're working and initialise OK but sending fails and nothing is received...

Power every thing from a separate 5v power supply and everything works as expected :-)

Hope this saves someone a bit of time!

Cheers
Ken

Title: Re: Can not receive CAN DATA from Arduino UNO with MCP2515 Module.
Post by: Malaga on Jun 15, 2018, 03:05 pm
Hi,

I have meet the same problem.

I use Arduino Uno and Niren MCP2515(8 Mhz) Modul, I also use a CAN Generator that creates CAN BUS signals.

MCP_CAN_LIB source files: https://github.com/Seeed-Studio/CAN_BUS_Shield

And the code is very simple with send and receive functions just as the Library.

BUT the digitalRead(CAN_INT) ist always HIGH and I can receive nothing. I habe tried all the receive code examples in the library and no one works.

Has anyone got this problem? What can I do to solve it?
I wasted fast a week.

Code: [Select]
// CAN Send Example
//
#include <SPI.h>
#include <avr/wdt.h>


#include "mcp_can.h"
#include "Arduino.h"

//initial all parametrs
const int CAN_INT=2;
const int SPI_CS_PIN=10;

long unsigned int rxId;
unsigned char len = 0;
unsigned char rxBuf[8];

byte data[] = {0xAA, 0x55, 0x01, 0x10, 0xFF, 0x12, 0x34, 0x56};


MCP_CAN CAN(SPI_CS_PIN);     // Set CS to pin 10


void setup()
{
    // Pins definieren
  pinMode(SPI_CS_PIN, OUTPUT);
  pinMode(CAN_INT, INPUT); // CAN_INT set to 2
 
  Serial.begin(115200);
  Serial.print("Starting CAN-Bus: ");
  // Initialize MCP2515 running at 8MHz with a baudrate of 500kb/s and the masks and filters disabled.
 while (CAN_OK != CAN.begin(MCP_STDEXT, CAN_500KBPS, MCP_8MHZ))    // init can bus : baudrate = 500k
    {
        Serial.println("CAN BUS Shield init fail");
        Serial.println(" Init CAN BUS Shield again");
        delay(100);
    }
    Serial.println("CAN BUS Shield init ok!");

    /*
     * set mask, set both the mask to 0x3ff
     */
    CAN.init_Mask(0, 0, 0x000);                         // there are 2 mask in mcp2515, you need to set both of them
    CAN.init_Mask(1, 0, 0xfff);


    /*
     * set filter, we can receive id from 0x04 ~ 0x09
     */
    CAN.init_Filt(0, 0, 0x04);                          // there are 6 filter in mcp2515
    CAN.init_Filt(1, 0, 0x05);                          // there are 6 filter in mcp2515

    CAN.init_Filt(2, 0, 0x06);                          // there are 6 filter in mcp2515
    CAN.init_Filt(3, 0, 0x07);                          // there are 6 filter in mcp2515
    CAN.init_Filt(4, 0, 0x08);                          // there are 6 filter in mcp2515
    CAN.init_Filt(5, 0, 0x09);                          // there are 6 filter in mcp2515
   
   CAN.setMode(MCP_NORMAL);
}

void loop()
{
    Serial.println("Start receiving Data:");
   
    if(!digitalRead(CAN_INT))
  {
    CAN.readMsgBuf(&rxId, &len, rxBuf);   // read data,  len: data length, buf: data buf
    Serial.print("rxID: ");
    Serial.println(rxId);
    Serial.print("Readdetails:   ");
    for(int i=0;i<sizeof(rxBuf);i++)
    {
      Serial.print("0x");
      Serial.print(rxBuf[i],HEX);
      Serial.print("  ");
    }
  }
  else
  {
    Serial.println("Error receiving Message...");
  }
    Serial.println();
   
    Serial.println("Start sending Data:");
    CAN.sendMsgBuf(0x100, 0, 8, data);
    delay(10000);
}
Title: Re: Can not receive CAN DATA from Arduino UNO with MCP2515 Module.
Post by: ChrisBarker on Aug 07, 2018, 06:06 pm
I too have been having problems sending and receiving data using 8MHZ MCP2515 boards connected to two arduinos and using Mr Fowler's library and example sketches. The loop back sketch works fine on both arduinos but the send sketch initialises but returns an error on sending data and therefore nothing gets through to the receive sketch. I've tried all the suggestions given in previous posts, swapped over boards, checked and rechecked the wiring all to no avail.
Yesterday, having ordered some 16mhz boards, I was checking through the library files and noticed that the 8MHZ constant in the keywords file was spelt with a lowercase z, i.e 8MHz. Everywhere else it was always MHZ.  Didn't think it would matter as I would have expected a compilation error still it was a "straw" so I changed it to an uppercase Z, recompiled the sketches and WOW, my serial monitors were flooded with successful send and receive messages.
Title: Re: Can not receive CAN DATA from Arduino UNO with MCP2515 Module.
Post by: Mbuchanan on Apr 05, 2019, 02:18 am
I was wondering if anyone has been able to get this to read data back? I have checked what I am sending and it matches the code I am intending to send. I have verified that the ecu is responding back using Vector, however I only getting message successfully sent, no data
Title: Re: Can not receive CAN DATA from Arduino UNO with MCP2515 Module.
Post by: turbozob on Jul 05, 2019, 12:34 pm
So guys saying on these Nirem boards 8MHz Q should be replaced with 16MHz Q and then it should work?
I can get the communication running between two arduino uno's but not with the car. Thanks for reply
Title: Re: Can not receive CAN DATA from Arduino UNO with MCP2515 Module.
Post by: noiasca on Jul 05, 2019, 06:46 pm
you should just use the proper initializer - either with 8MHz or 16MHz depending on your module.

while (CAN_OK != CAN.begin(MCP_STDEXT, CAN_250KBPS, MCP_16MHZ)) 

vs

while (CAN_OK != CAN.begin(MCP_STDEXT, CAN_250KBPS, MCP_8MHZ)) 

if you do it right - it should work
Title: Re: Can not receive CAN DATA from Arduino UNO with MCP2515 Module.
Post by: turbozob on Jul 15, 2019, 06:33 pm
Sorry for late reply, forgot to subscribe to topic. I used MCP_8MHZ but nothing comes from the car, guess I am doing something else wrong. Has anyone successfully connected with the car over OBD2 with this Nirem board?
Title: Re: Can not receive CAN DATA from Arduino UNO with MCP2515 Module.
Post by: coryjfowler on Jul 18, 2019, 01:55 am
Sorry for late reply, forgot to subscribe to topic. I used MCP_8MHZ but nothing comes from the car, guess I am doing something else wrong. Has anyone successfully connected with the car over OBD2 with this Nirem board?
Can you try changing
Code: [Select]
8MHz to
Code: [Select]
8MHZ in the keywords file?  I just changed it on github per this message (https://forum.arduino.cc/index.php?topic=402018.msg3833439#msg3833439) above and I am curious if that has been the issue plaguing some users.
Title: Re: Can not receive CAN DATA from Arduino UNO with MCP2515 Module.
Post by: turbozob on Jul 18, 2019, 03:02 pm
Command 8MHZ works, while 8MHz not ('MCP_8MHz' was not declared in this scope)

Eventually I got it working but not in the car but on a bench with ECU(EDC15VM+) from scrapyard which is the same as in my car. It seems like my car does not support CAN, although the CAN wires are present at the OBD2 connector (pins 6,14) tested with oscilloscope.

So what I did on the bench:

- Wired "Nirem" with Arduino
- Wired CAN H&L ECU to "Nirem"
- Connected power to ECU and trimmers for sensor simulation
- Opened "CAN Receive Example" from your library  "MCP_CAN Library (https://github.com/coryjfowler/MCP_CAN_lib)"
- Setup MCP to 8MHZ
- Upload to Arduino and open Serial
- Data traffic seen from engine ECU with different IDs
- Decode data with oscilloscope

Later I modified code for readable value calculation as temperature, acc pedal sensor with the help of ecu documentation and useful forum posts. Compared data from diagnostic tool VCDS and recieved from Arduino were almost the same.
Title: Re: Can not receive CAN DATA from Arduino UNO with MCP2515 Module.
Post by: laoadam on Dec 04, 2019, 04:09 am
The code should work with a MCP2510, MCP2515, and an MCP25625, but I have only confirmed it on the latter two ICs.  Additionally, I have tested the library with that very module you linked to and recently infact. 

When you tried the receive example, did you have it connected to the vehicle with the key-switch ON (engine OFF)?
There is mention message of reply the topic or a new one, my question is exactly here so.

Thank you coryjfowler  to confirm the use of the code, my question is if the code only works for CAN BUS shield made by MCP2515 and MCP2510 or MCP25625? Can the code work for the CAN BUS shield made by MCP2515 and TJA1050 like oasis's post mentioned?

I used Arduino+MCP2515+TJA1050 + ELM327 unit without an ECU.

I guess this is the point, because that's two kinds of CAN BUS shield. and McNeight posted at: https://forum.arduino.cc/index.php?topic=228758.0 

[ No, the MCP2551 (or MCP2515) won't work with ELM327 protocol ].

seems the code doesn't work for the CAN BUS shield mentioned, if not how to modify?

Thanks
Adam



Title: Re: Can not receive CAN DATA from Arduino UNO with MCP2515 Module.
Post by: coryjfowler on Dec 05, 2019, 04:13 pm
seems the code doesn't work for the CAN BUS shield mentioned, if not how to modify?

If the board has an MCP2515, MCP25625, or MCP2510, the library should work for those protocol controllers.

The TJA1050 is a common CAN transceiver and is only used to translate the CAN_RX and CAN_TX into CAN_H and CAN_L for use on an actual bus.


While I have not tried it, an ELM327 acting as a second CAN device may work.  Regardless, any CAN testing needs to have at least two active devices.  If the ELM327 does not actively participate on CAN, it might cause an erroneous send failure.

I do not recommend ELM products outside of explicit OBD-II applications, it is a horrible CAN interface...
Title: Re: Can not receive CAN DATA from Arduino UNO with MCP2515 Module.
Post by: laoadam on Dec 08, 2019, 08:55 am
If the board has an MCP2515, MCP25625, or MCP2510, the library should work for those protocol controllers.

The TJA1050 is a common CAN transceiver and is only used to translate the CAN_RX and CAN_TX into CAN_H and CAN_L for use on an actual bus.
Thank you coryjfowler for your reply.
Yes like you said the ELM327 USB1.5 seems a surplus if do the diagnosis to a car. I used it here only try to get the communication between ELM327 USB1.5 and MCP2515+TJA1050 module. I have some novice questions need help please, sorry about.
1. Should I set the ELM327 USB1.5's Baudrate same as the other device , guess YES, do you know how to do it? it was default set 38400 bps.

2. If it is hard to set ELM327's Baudrate, may easy to set the other device say MCP2515+TLA1050 can module, I modified the mcp_can.cpp and mcp_can_dfs.h added 38k4BPS 3 lines into the library used, still not work. I'll attached the modifications below. Maybe cause of the 38k4BPS s not a standard number, it doesn't like the other numbers say 250/500 change the color in the sketch.

3. The error "'CAN_38K4BPS' was not declared in this scope" , why?

4. I saw your advice about the ELM327, the purpose I'm doing this is try to make a ECU simulator with the Arduino+MCP2515 module work as a fake ECU, sure refer to Techthink.

5. I also tried the sketch you posted on #11 to reynard80, I got the same result with Arduino and MCP2515+TJA1050 MODULE, I tested it on two separately two sets of, all Error sending message ... , is it possibly to run the sketch without a real ECU unit connected ?

Thanks

Adam
Title: Re: Can not receive CAN DATA from Arduino UNO with MCP2515 Module.
Post by: coryjfowler on Dec 09, 2019, 02:16 pm
Thank you coryjfowler for your reply.
Yes like you said the ELM327 USB1.5 seems a surplus if do the diagnosis to a car. I used it here only try to get the communication between ELM327 USB1.5 and MCP2515+TJA1050 module. I have some novice questions need help please, sorry about.
1. Should I set the ELM327 USB1.5's Baudrate same as the other device , guess YES, do you know how to do it? it was default set 38400 bps.
If this is the CAN baud, yes.  If this is the serial interface baud, no.  I have not used any ELM stuff, that is on you to figure out.

2. If it is hard to set ELM327's Baudrate, may easy to set the other device say MCP2515+TLA1050 can module, I modified the mcp_can.cpp and mcp_can_dfs.h added 38k4BPS 3 lines into the library used, still not work. I'll attached the modifications below. Maybe cause of the 38k4BPS s not a standard number, it doesn't like the other numbers say 250/500 change the color in the sketch.
I feel like 38,400 baud is the ELM's serial link.  OBD-II CAN spec is 250 or 500.

3. The error "'CAN_38K4BPS' was not declared in this scope" , why?
Looks like you missed adding 'CAN_38K4BPS' to the enum.

4. I saw your advice about the ELM327, the purpose I'm doing this is try to make a ECU simulator with the Arduino+MCP2515 module work as a fake ECU, sure refer to Techthink.
In that regard, you should set the Arduino with CAN to 500k, and have it listen for the OBD-II functional ID (0x7DF).  When it receives that ID, the Arduino should transmit using one of the ECM's IDs (0x7E8).

5. I also tried the sketch you posted on #11 to reynard80, I got the same result with Arduino and MCP2515+TJA1050 MODULE, I tested it on two separately two sets of, all Error sending message ... , is it possibly to run the sketch without a real ECU unit connected ?
No, CAN needs at least TWO active devices or you will have an error sending.
Title: Re: Can not receive CAN DATA from Arduino UNO with MCP2515 Module.
Post by: laoadam on Dec 11, 2019, 04:01 am
Thank you for your patience coryjfowler.

1. Firstly I would say I may misunderstand the Baudrate from the ELM327 manufacture default of 38400bps, this number should be the Baudrate for the USB communicate to computer?  and the ELM327 is just a physics converter convert the received CAN DATE into USB compatible, am I right? same as you answered at #2 ?

Because if the 38400bps is a CAN BUS Baudrate, how can the ELM327 take a 500kbps?

2. I modified the library files and the 38k4bps compiling errors disappeared . The ELM327 and MCP2515+TJA1050 module still can't communicate.

3. at answer #5 you said "CAN needs at least TWO active devices", that means the ELM327 is not a  active devices itself, right? I have tried two sets of Arduino+MCP2515 connected together and sending / receiving well. 

4. Here what I'm doing is let the computer read date from Arduino+MCP2515 through the ELM327,  the ELM327 just works as a CAN interface, and the Original project used SeeedStudio CAN-BUS shield which made up by MCP2515+MCP2551, and it was succeed.
What's the key difference between TLA1050 and MCP2551? any solution on sketch?

Best
Adam

 

Title: Re: Can not receive CAN DATA from Arduino UNO with MCP2515 Module.
Post by: coryjfowler on Dec 12, 2019, 09:08 pm
What's the key difference between TLA1050 and MCP2551? any solution on sketch?
The vendor for starters.  Do both boards have terminations enabled when you are testing this?
Title: Re: Can not receive CAN DATA from Arduino UNO with MCP2515 Module.
Post by: hugo_a_garcia on Dec 19, 2019, 07:40 pm
Hi

I am responding to this post since at some point many of your have tested various CAN boards.

I am not having success with the JOY-IT CAN Module:

https://joy-it.net/en/products/SBC-CAN01

Corey's loopback works well but the send/receive example is failing with sending message error. The board has a 16MHz crystal. I have tried various baud rates and also turning on/off the 120 ohm resistor on both boards.

The setup is [ UNO - CAN - CAN - MEGA ]

Comments, suggestions or questions are welcome.

-H
Title: Re: Can not receive CAN DATA from Arduino UNO with MCP2515 Module.
Post by: turbozob on Dec 19, 2019, 08:02 pm
hugo,

your board has MCP2515 controller, so I it not any different from other boards with the same controller. I guess you have a wiring or code issue.
Title: Re: Can not receive CAN DATA from Arduino UNO with MCP2515 Module.
Post by: hugo_a_garcia on Dec 19, 2019, 08:27 pm
hugo,

your board has MCP2515 controller, so I it not any different from other boards with the same controller. I guess you have a wiring or code issue.
I did connectivity test with a multimeter on the CAN H/L [ H -> H, L -> L] and it is OK. I have not checked the individual wires for connectivity but I assumed the loopback program would not work if the SPI wires are not all working properly???

Also, both boards have their own independent power supply.

The program is the example from:

https://github.com/coryjfowler/MCP_CAN_lib


which has worked for others on thread.

-H
Title: Re: Can not receive CAN DATA from Arduino UNO with MCP2515 Module.
Post by: coryjfowler on Dec 19, 2019, 10:39 pm
I assumed the loopback program would not work if the SPI wires are not all working properly???
You would be correct with that assumption, the loopback sketch would test SPI and /INT connectivity.


The link you provided for the Joy-It module suggests the crystal is 8MHz, did you replace this or confirm that it is running at 16MHz as you suggest earlier?

Are the CAN boards both Joy-It modules or is one a Seeed Studio shield?  Have you tried connecting grounds between the two?  What sketches are you testing with?

If both microcontroller setups work with the loopback program, there is no good reason that going on bus would not work assuming the hardware is good.
Title: Re: Can not receive CAN DATA from Arduino UNO with MCP2515 Module.
Post by: hugo_a_garcia on Dec 23, 2019, 04:06 pm
You would be correct with that assumption, the loopback sketch would test SPI and /INT connectivity.


The link you provided for the Joy-It module suggests the crystal is 8MHz, did you replace this or confirm that it is running at 16MHz as you suggest earlier?

Are the CAN boards both Joy-It modules or is one a Seeed Studio shield?  Have you tried connecting grounds between the two?  What sketches are you testing with?

If both microcontroller setups work with the loopback program, there is no good reason that going on bus would not work assuming the hardware is good.
I am using your example sender and reader from github with 8MHX set as the clock.

Boyj boards are Joy-iy and at least electrically, the CAN bus is set up properly.

I agree is should work so maybe the hardware is faulty.

---

I opened a ticket with Joy-it. I also, have an extra board so... myabe test that one too. Will do an update when possible.

Thanks for comments

-H
Title: Re: Can not receive CAN DATA from Arduino UNO with MCP2515 Module.
Post by: hugo_a_garcia on Jan 09, 2020, 04:59 pm
Small update on the Joy-It board:

The company has confirmed that the crystal on the board is 16MHz.

-H
Title: Re: Can not receive CAN DATA from Arduino UNO with MCP2515 Module.
Post by: turbozob on Jan 09, 2020, 08:49 pm
I remember that loopback worked even if wrong MHz was selected. Did you make any progress?
Title: Re: Can not receive CAN DATA from Arduino UNO with MCP2515 Module.
Post by: johnstylez on Jan 20, 2020, 03:43 am
question, i am trying to use mcp2515 + coryjfowler's library with nano, i was able to send fuel level request to my 2019 toyota obd can bus, and i have checked it with another usb can analyzer , but i wasn't able to get any response from the car can bus. however when i send request using the usb can analyzer i was able to get the response.