Hi,
I'm trying to communicate to OBD over CAN bus. I'm using MCP2551 and MCP2515 along with Arduino UNO. But I'm not getting any response from the ECU. I'm using seeedstudio library for CAN. I have made two identical circuits and tested the hardware using blink_receive and blink_send examples and they are working. I'm using sparkfun OBDII to DB9 cable for connecting to OBD port.
I have also tried the blink examples with the OBDII to DB9 cable, thinking that there might be some losses, but the examples are working on it. I have tried different BUS speeds too.
Below is the code that I'm using to communicate with ECU:
// demo: CAN-BUS Shield, send data
#include <mcp_can.h>
#include <SPI.h>
#include <mcp_can_dfs.h>
// the cs pin of the version after v1.1 is default to D9
// v0.9b and v1.0 is default D10
const int SPI_CS_PIN = 10;
MCP_CAN CAN(SPI_CS_PIN); // Set CS pin
void setup()
{
Serial.begin(115200);
START_INIT:
if(CAN_OK == CAN.begin(CAN_500KBPS)) // init can bus : baudrate = 500k
{
Serial.println("CAN BUS Shield init ok!");
}
else
{
Serial.println("CAN BUS Shield init fail");
Serial.println("Init CAN BUS Shield again");
delay(100);
goto START_INIT;
}
}
unsigned char stmp[8] = {0x02, 0x01, 0x00, 0, 0, 0, 0, 0};
void loop()
{
// send data: id = 0x00, standrad frame, data len = 8, stmp: data buf
CAN.sendMsgBuf(0x7DF, 0, 8, stmp);
// delay(100); // send data per 100ms
unsigned char len = 0;
unsigned char buf[8];
unsigned long currTime = millis();
while(millis() - currTime < 1000)
{
// Serial.print(CAN.checkReceive());
if(CAN_MSGAVAIL == CAN.checkReceive()) // check if data coming
{
CAN.readMsgBuf(&len, buf); // read data, len: data length, buf: data buf
unsigned char canId = CAN.getCanId();
Serial.println("-----------------------------");
Serial.println("get data from ID: ");
Serial.println(canId, HEX);
for(int i = 0; i<len; i++) // print the data
{
Serial.print(buf[i]);
Serial.print("\t");
}
Serial.println();
}
}
// Serial.println("Done");
delay(1000);
}
/*********************************************************************************************************
END FILE
*********************************************************************************************************/
I have also attached the schematic for the reference. Any help would be appreciated. Thanks in advance ![]()
