MCP2515 can sniffer

HI .
I have this code which should allow you to see the messages passing through the car's CAN network.
Everything is fine except that in serial I don't see anything. If instead I open canhacker 2.0 I see the messages I send but nothing more. obviously the can network is present since I can communicate with other tools. please do you have an idea what could be the problem?
I attach the code.

#include <SPI.h>
#include <mcp2515.h>

struct can_frame canMsg;
MCP2515 mcp2515(10);


void setup() {
  Serial.begin(115200);
  SPI.begin();
  
  mcp2515.reset();
  mcp2515.setBitrate(CAN_125KBPS);
  mcp2515.setNormalMode();
  
  Serial.println("------- CAN Read ----------");
  Serial.println("ID  DLC   DATA");
}

void loop() {
  
  if (mcp2515.readMessage(&canMsg) == MCP2515::ERROR_OK) {
      
    Serial.print(canMsg.can_id, HEX); // print ID
    Serial.print(" "); 
    Serial.print(canMsg.can_dlc, HEX); // print DLC
    Serial.print(" ");
    
    for (int i = 0; i<canMsg.can_dlc; i++)  {  // print the data
        
      Serial.print(canMsg.data[i],HEX);
      Serial.print(" ");

    }

    Serial.println();      
  }

}

That code looks like the receive example from the autowp library.
Have a look at the documentation page GitHub - autowp/arduino-mcp2515: Arduino MCP2515 CAN interface library

Is your bus speed 125kbps?
Are you using a 8MHz crystal? If so you need the mcp2515.setBitrate(CAN_125KBPS, MCP_8MHZ);

Are you using a 5v Arduino and powering the adaptor using 5v?

1 Like

Posting an annotated schematic would help us help you.

Hi mikb55.
My crystal is 8mhz.
My bus speed is 125kbps.

Hi gilshultz
here is the schematic

Although that is a good picture of a wiring diagram it is a long way from an annotated schematic, power sources are missing, other hardware items are not shown, pin numbers are missing etc. You can download KiCad for free, it will take you from schematic capture to a complete PCB even showing it in 3D.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.