SparkFun Forums 

Where electronics enthusiasts find answers.

Have questions about a SparkFun product or board? This is the place to be.
By Fenja
#157721
Dear Triple7!!

I like your code an I've bought the same hardware as you.

Would you be so kind an post the MCP2515.h, or tell me, where I can find that one, that you used for your program?
Thank you!
By Memphomaniac
#157829
I was having trouble getting the CAB-BUS shield to play using the SKPang code and mounted to my Mega 2560. I couldn't read any data from the CAN bus.

I had already changed the wiring to support the re-located SPI bus as follows, but that wasn't enough:
Code: Select all
Mega      CAN
51        11 (SPI MOSI)
50        12 (SPI MISO)
52        13 (SPI SCK)
53        10 (SPI CS)
I did some research, and I discovered the problem. In the code from the SKPang site, you will find a file "defaults.h". This file uses port mappings for the SPI bus pins, and it was set up for the ATmega 168/328.

Here is the reference to using port manipulation: http://www.arduino.cc/en/Reference/PortManipulation

So I looked at the port mappings between the Arduino Uno and the Arduino Mega 2560. Here are the references to the 2 different port mappings:
http://arduino.cc/en/Hacking/PinMapping168
http://arduino.cc/en/Hacking/PinMapping2560

Based on this information, I made the following changes to the defaults.h file (old lines are commented out):
Code: Select all
// Arduino Uno (Atmega 168/328 pin mapping)
//#define    P_MOSI            B,3 // pin 11
//#define    P_MISO            B,4 // pin 12
//#define    P_SCK             B,5 // pin 13
//#define    MCP2515_CS        B,2 // pin 10
//#define    MCP2515_INT       D,2 // pin 2
//#define    LED2_HIGH         B,0 // pin 8
//#define    LED2_LOW          B,0 // pin 8

// Pins remapped to Arduino Mega 2560
#define    P_MOSI              B,2 // pin 51
#define    P_MISO              B,3 // pin 50
#define    P_SCK               B,1 // pin 52
#define    MCP2515_CS          B,0 // pin 53
#define    MCP2515_INT         E,4 // pin 2
#define    LED2_HIGH           H,5 // pin 8
#define    LED2_LOW            H,5 // pin 8
As so now it works. I can now get to finishing my code for my Corvette data logger :mrgreen:
By Nerdenator
#170548
I'm trying to get the OBDII readings off a car with this shield and the Mega and pair it with GPS readings. I have no problems getting the info off of the car, but the GPS (I'm using the EM-406A as suggested) is another story. I can't get it to work no matter what I do. What suggestions do you guys have? Do I need to jumper some more pins?
By JordiPin
#172752
Hello everybody. I have to make a project with a Sparkfun Can Bus Shiel, with an Arduino uno, and Pike PCAN usb drive. I try make a program (Sketch) with Arduino 1.0.5 software for read data. I'm already add Canbus shield libraries, but every taime show me an error, CAN is not type in this scope. I make this code. If something can help me I'll be very grateful. THNX ALL FOR YOUR TIME!
this is my code....
// demo: CAN-BUS Shield, receive data with check mode
// send data coming to fast, such as less than 10ms, you can use this way
// loovee, 2014-6-13


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


unsigned char Flag_Recv = 0;
unsigned char len = 0;
unsigned char buf[8];
char str[20];


MCP_CAN CAN(10); // Set CS to pin 10

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;
}
}


void loop()
{
if(CAN_MSGAVAIL == CAN.checkReceive()) // check if data coming
{
CAN.readMsgBuf(&len, buf); // read data, len: data length, buf: data buf

for(int i = 0; i<len; i++) // print the data
{
Serial.print(buf);Serial.print("\t");
}
Serial.println();
}
}