If anyone else has the same problem, this worked;
#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);
if(CAN0.begin(MCP_STDEXT, CAN_500KBPS, MCP_8MHZ) == CAN_OK) Serial.print("MCP2515 Init Okay!!\r\n");
else Serial.print("MCP2515 Init Failed!!\r\n");
pinMode(2, INPUT); // Setting pin 2 for /INT input
CAN0.init_Mask( 0, 0, 280 | 288 ); // Init first mask...
CAN0.init_Filt( 0, 0, 280 ); // Init 1st filter...
CAN0.init_Filt( 1, 0, 288 ); // Init 2nd filter...
CAN0.init_Mask( 1, 0, 280 | 288 ); // Init first mask...
CAN0.init_Filt( 2, 0, 280 ); // Init 1st filter...
CAN0.init_Filt( 3, 0, 288 ); // Init 2nd filter...
CAN0.init_Filt( 4, 0, 280 ); // Init 1st filter...
CAN0.init_Filt( 5, 0, 288 ); // Init 2nd filter...
Serial.println("MCP2515 Library Mask & Filter Example...");
CAN0.setMode(MCP_NORMAL); // Change to normal mode to allow messages to be transmitted
}
void loop()
{
if(!digitalRead(2)) // If pin 2 is low, read receive buffer
{
CAN0.readMsgBuf(&rxId, &len, rxBuf); // Read data: len = data length, buf = data byte(s)
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();
}
}