CAN-Shield MCP2515 initialization error

Hey Guys, im working on a bit of a challenge for me, i want my arduino to only read can messages for now. The code should be fine and working but i get 2 errors in my seriall monitor.
Entering Configuration Mode Failure...
Fehler bei der MCP2515 Initialisierung...
Maybe someone of u had this error before, would very appreciate any help!

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

// Definieren Sie den CS-Pin des MCP2515 CAN-Transceivers
const int CS_PIN = 10;

MCP_CAN CAN(CS_PIN); // Initialisieren Sie das MCP_CAN-Objekt

void setup() {
  Serial.begin(9600);
  while (!Serial);

  // Initialisieren Sie den MCP2515 CAN-Transceiver
  if (CAN.begin(MCP_ANY, CAN_500KBPS, MCP_8MHZ) == CAN_OK) {
    Serial.println("MCP2515 Initialisierung erfolgreich!");
  } else {
    Serial.println("Fehler bei der MCP2515 Initialisierung...");
  }
}

void loop() {
  // Überprüfen, ob eine Nachricht empfangen wurde
  if (CAN.checkReceive()) {
    // Lesen Sie die empfangene Nachricht
    unsigned long canId;
    byte len;
    byte buf[8];
    if (CAN.readMsgBuf(&canId, &len, buf) == CAN_OK) {
      // Drucken Sie die ID und Daten der Nachricht auf dem seriellen Monitor aus
      Serial.print("ID: 0x");
      Serial.print(canId, HEX);
      Serial.print(" Daten: ");
      for (int i = 0; i < len; i++) {
        Serial.print(buf[i], HEX);
        Serial.print(" ");
      }
      Serial.println();
    }
  }
}

Most probably a wiring error. Post a complete wiring diagram of your setup. If you use a breakout board for the MCP2515, post a link to it's schematics!

1 Like

Hey im using the seeed studios can shield
CAN-BUS Shield V2.0 | Seeed Studio Wiki

Hi, @david02ktm
Welcome to the forum.

What model Arduino are you using?

If it is a UNO, check that the USB socket case on the UNO is not shorting anything on the shield on top.

For example;

Tom... :smiley: :+1: :coffee: :australia:

Hi @TomGeorge, im using UNO yes but i already made sure that its not shorted.

HI,
As you are using SPI have to done the changes to your shield to get it into SPI mode.
From the Wiki.
image

image

Have you got the Power-OBD switch in the correct position?

Tom... :smiley: :+1: :coffee: :australia:

1 Like

Hi, i had not done the changes now its working thank u!
Did not know ih had to do it :frowning:

Hi,
Its a very informative Wiki. Seeed documentation is very good.

Tom.. :smiley: :+1: :coffee: :australia:

1 Like

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