I'm trying to set up an MCP2515 CAN module with an Arduino UNO to read data from a vehicle's CAN bus(2006 Prius and 2023 Octavia). However, I’m not receiving any data, and I keep getting the error:
"Starting CAN failed"
This is my current setup:
Code I'm using (CAN Receive Example from sandeepmistry's library)
// Copyright (c) Sandeep Mistry. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
#include <CAN.h>
void setup() {
Serial.begin(9600);
while (!Serial);
Serial.println("CAN Receiver");
// start the CAN bus at 500 kbps
if (!CAN.begin(500E3)) {
Serial.println("Starting CAN failed!");
while (1);
}
}
void loop() {
// try to parse packet
int packetSize = CAN.parsePacket();
if (packetSize || CAN.packetId() != -1) {
// received a packet
Serial.print("Received ");
if (CAN.packetExtended()) {
Serial.print("extended ");
}
if (CAN.packetRtr()) {
// Remote transmission request, packet contains no data
Serial.print("RTR ");
}
Serial.print("packet with id 0x");
Serial.print(CAN.packetId(), HEX);
if (CAN.packetRtr()) {
Serial.print(" and requested length ");
Serial.println(CAN.packetDlc());
} else {
Serial.print(" and length ");
Serial.println(packetSize);
// only print packet data for non-RTR packets
while (CAN.available()) {
Serial.print((char)CAN.read());
}
Serial.println();
}
Serial.println();
}
}
To troubleshoot, I have tested multiple CAN speeds (125kbps, 250kbps, 500kbps), manually set the crystal frequency to 8MHz in the library, and tried different libraries. At this point, I’m wondering why the MCP2515 consistently fails to start. How can I check if the MCP2515 is even responding? Additionally, is it possible that the vehicle's CAN system is blocking communication?
Any debugging tips or suggestions would be greatly appreciated!
I am not familiar with your CAN library so you will have to do some checking. You first need to put it in loopback mode and at that point it should first be initialize. After that it will echo what you tell it to send. If it does not do that something is wrong with your setup.
I recommend you set up two units and get them talking first. Do not forget the termination jumpers. Reason for two units, CAN requires an ACK from some remote or it will error out after a bunch of tries. I use Cory Fowler's mcp can library, it comes with the send and receive code.
And I would guess the problem lays with the car connection, OBD-s etc.
Do you have a oscilloscope, how are the CAN signals?
Have you tested with CAN termination resistor enabled/disabled?
Do you have another Arduino and the Comidox MCP2515 module?
How about setting ut a send and receive example with two sets?
If you have a look at CANBED V1 - Longan Docs you can find information about terminal resistor, OBD and get data from a Vehicle.
I have already tried enabling the 120Ω termination resistor and also tested in loopback mode with coryjfowler's library, but the MCP2515 still fails to initialize. Specifically, I get:
Unfortunately, I don't have an oscilloscope to check the CAN signals directly, but I have verified my wiring multiple times.
I only have one MCP2515 module and arduino at the moment, so I haven't tested with two units yet.
To further diagnose the issue, I ran a simple test to check if the MCP2515 is responding:
The result I got was 0x00, which suggests that the MCP2515 is not responding to SPI commands. At this point, I suspect the chip might be faulty, but I want to confirm before ordering a replacement.
Does anyone have any suggestions on how to further diagnose this issue? Could this be caused by a wiring problem, or is it likely a defective module?