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 allMega 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