Hi,
I'm trying to receive CAN DATA from Arduino UNO with MCP2515 Module.
I'm not using CAN-BUS Shield and am only using MCP2515 Module(MCP2515 CAN Controller with TJA1050 CAN transceiver. (Attachment #2))
http://www.aliexpress.com/item/MCP2515-CAN-Bus-Module-Board-TJA1050-Receiver-SPI-For-51-MCU-ARM-Controller-NEW/32581650373.html?spm=2114.01010208.8.8.aabjPj
I think that even though I do not use CAN-BUS Shield, I should be able to receive CAN DATA through the MCP2515 module because it includes MCP2515 CAN controller and TJA1050 CAN transceiver.. Is it right?
Here is my test environments:
-
Arduino setting: Attachment #1
OBD2 16pin cable => 6pin(CAN HIGH) and 14pin(CAN LOW) => MCP2515 CAN Module => Arduino UNO -
CAN Module: Attachment #2
MCP2515 CAN Controller with TJA1050 CAN transceiver.
http://www.aliexpress.com/item/MCP2515-CAN-Bus-Module-Board-TJA1050-Receiver-SPI-For-51-MCU-ARM-Controller-NEW/32581650373.html?spm=2114.01010208.8.8.aabjPj -
Vehicle : VW Tiguan
I connected several pins between with Arduino and MCP2515 module like below:
Arduino MPC2515 module
5V VCC
GND GND
13 SCK
12 SO
11 SI
10 CS
2 INT
I downloaded MCP_CAN_LIB source files.
And I opened a "receive" example of MCP_CAN_LIB from Arduino IDE and initialized like "CAN0.begin(CAN_500KBPS, MCP_8MHz)" because my chinese clone MCP2515 moudule is using 8 Mhz crystal.
But I could not receive any CAN DATA.
The function "digitalRead(2)" always returns HIGH..
Has anyone got this problem?
// demo: CAN-BUS Shield, receive data
#include <mcp_can.h>
#include <SPI.h>
long unsigned int rxId;
unsigned char len = 0;
unsigned char rxBuf[8];
MCP_CAN CAN0(10); // Set CS to pin 10
void setup()
{
Serial.begin(115200);
CAN0.begin(CAN_500KBPS, MCP_8MHz); // init can bus : baudrate = 500k
pinMode(2, INPUT); // Setting pin 2 for /INT input
Serial.println("MCP2515 Library Receive Example...");
}
void loop()
{
if(!digitalRead(2)) // If pin 2 is low, read receive buffer
{
CAN0.readMsgBuf(&len, rxBuf); // Read data: len = data length, buf = data byte(s)
rxId = CAN0.getCanId(); // Get message ID
Serial.print("ID: ");
Serial.print(rxId, HEX);
Serial.print(" Data: ");
for(int i = 0; i<len; i++) // Print each byte of the data
{
if(rxBuf[i] < 0x10) // If data byte is less than 0x10, add a leading zero
{
Serial.print("0");
}
Serial.print(rxBuf[i], HEX);
Serial.print(" ");
}
Serial.println();
}
}