CAN BUS MCP2515 no messages read

Hey there,

I've been trying to sniff messages from my 2011 Kia Picanto using an Arduino Uno and an MCP2515 can bus module. I've been trying for the past few days but could not read out any messages. Last year I did a similar project with a Truck and it worked perfectly. I'm really desperate at this point because this is a project for uni. Pls help. Below is a picture of the setup and the code.

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

const int SPI_CS_PIN = 10;  // Chip Select pin for MCP2515
MCP_CAN CAN(SPI_CS_PIN);    // Set CS pin for MCP_CAN instance

void setup() {
    Serial.begin(9600);
    while (!Serial);  // Wait for serial port to connect - needed for Leonardo only

    if (CAN.begin(MCP_ANY, CAN_250KBPS, MCP_8MHZ) == CAN_OK) {
        Serial.println("MCP2515 Initialized Successfully!");
    } else {
        Serial.println("Error Initializing MCP2515!");
        while (1);
    }
}

void loop() {
    unsigned long canId = 0;  // Variable to store CAN ID
    unsigned char len = 0;    // Variable to store length of the CAN message
    unsigned char buf[8];     // Data buffer to store received data

    if (CAN_MSGAVAIL == CAN.checkReceive()) {
        CAN.readMsgBuf(&canId, &len, buf);  // Read the data

        Serial.print("Message ID: ");
        Serial.print(canId, HEX);
        Serial.print(" Length: ");
        Serial.println(len);

        for (int i = 0; i < len; i++) {  // Print each byte of the data
            Serial.print(buf[i], HEX);
            Serial.print(" ");
        }
        Serial.println();
    }
}

Pinout:

MCP2515 Pin Arduino Pin
VCC => 5V
GND=> GND
CS=> D10
SO=> D12
SI=> D11
SCK=> D13
INT=> D2

I used PIN 6 for CAN H and pin 14 for CAN L as usual for the OBD port.

Does your university have an oscilloscope?
If so then check for activity on the H and L pins with respect to ground.

If you see nothing then you probably need to send a PID query to the car and then wait for a response.

1 Like

Are you following the OBDII protocol or just listing. Many vehicles do not connect the OBDII port to the internal CAN bus but pass it through a gateway. Th reason is this keeps many of the packets private and prevents external interference. Placing improper packets on the CAN bus can damage the vehicle.

Right now I'm just trying to read out ANY messages because I'm not receiving anything. Do you mean that I should send a specific PID query or sth?

There's activity on both pins. I reconfigured my arduino to read out the high and low pins over teh analog inputs and they very clearly showed dominant (1,5;3,5) and recessive bits (2,5;2,5). Would sending a direct PID query to the car solve the issue? I'm not receiving anything at all at this point.

Here's my idea. Let me know whether I understood you correctly:

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

const int SPI_CS_PIN = 10; // Set CS pin
MCP_CAN CAN(SPI_CS_PIN); // Set CS pin for MCP_CAN instance

void setup() {
  Serial.begin(115200);
  if (CAN.begin(MCP_ANY, CAN_500KBPS, MCP_8MHZ) == CAN_OK) {
    Serial.println("MCP2515 Initialized Successfully!");
  } else {
    Serial.println("Error Initializing MCP2515!");
    while (1); // Halt if initialization fails
  }
}

void loop() {
  // PID request for engine RPM (0x0C)
  byte pidRequest[] = {0x02, 0x01, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00};
  // Standard OBD-II PID request on PID 0x7DF (the diagnostic PID)
  CAN.sendMsgBuf(0x7DF, 0, 8, pidRequest);
  delay(1000); // Wait a second
  
  unsigned char len = 0;
  unsigned char buf[8];

  if (CAN_MSGAVAIL == CAN.checkReceive()) {
    CAN.readMsgBuf(&len, buf); // Read data: len = data length, buf = data byte(s)
    
    Serial.println("Received response:");
    for (int i = 0; i < len; i++) { // Print each byte of the data
      Serial.print(buf[i], HEX);
      Serial.print(" ");
    }
    Serial.println();
  }
}

Are you operating at the correct baud rate, I have no idea. The library you used has both a send and a receive modules, set up another CAN node and see if they can talk to each other first, if not they will not talk to the car. Try using mills in place of delay which is blocking.

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