Hi ! I am currently on my 5th post on this forum and I have yet to see a reply. Oh well, I am still hoping.
I am using an Arduino Mega 2560 with a Sparkfun CAN BUS Shield: CAN-BUS Shield - DEV-13262 - SparkFun Electronics
Obviously I know it is not compatible with mega and that I cannot stack it because the mega has the SPI pins on pins 50-53, not 10-13 so I just stacked the shield over the mega without those 4 particular pins, for which I then used wires to connect to Mega's SPI pins.
I also changed the pins in the defaults.h file inside the Canbus.h library
I tried to run the example code of the canbus library(which actually worked perfectly fine for 2 days)
#include <Canbus.h>
#include <defaults.h>
#include <global.h>
#include <mcp2515.h>
#include <mcp2515_defs.h>
//********************************Setup Loop*********************************//
void setup() {
Serial.begin(9600); // For debug use
Serial.println("CAN Read - Testing receival of CAN Bus message");
delay(1000);
if(Canbus.init(CANSPEED_500)) //Initialise MCP2515 CAN controller at the specified speed
Serial.println("CAN Init ok");
else
Serial.println("Can't init CAN");
delay(1000);
}
//********************************Main Loop*********************************//
void loop(){
tCAN message;
if (mcp2515_check_message())
{
if (mcp2515_get_message(&message))
{
//if(message.id == 0x620 and message.data[2] == 0xFF) //uncomment when you want to filter
//{
Serial.print("ID: ");
Serial.print(message.id,HEX);
Serial.print(", ");
Serial.print("Data: ");
Serial.print(message.header.length,DEC);
for(int i=0;i<message.header.length;i++)
{
Serial.print(message.data[i],HEX);
Serial.print(" ");
}
Serial.println("");
//}
}}
}
My main goal for now was to see on the serial monitor "CAN init OK" which I did for 2 days.
The next day, without changing anything to the code or the boards, the serial monitor started displaying "cant init can". (I am also going to mention that If I stack the shield normally on an arduino UNO with the initial SPI pins declared in defaults.h it works perfectly fine)
I added to the code, in setup the line : pinMode(53, OUTPUT);
53 is the SS pin for Mega
After doing this the code started working again (displaying "can init ok")'
The next day however it stopped working again.
Anyone has any idea what is wrong with it ?