I am having trouble with getting the MCP-2515 to send data. I had it working but now it does not appear to be sending messages.
#include <mcp_can.h>
#include <SPI.h>
#define CAN0_INT 18
MCP_CAN CAN0(10); // Set CS to pin 10
void setup()
{
Serial.begin(115200);
delay(3000);
// Initialize MCP2515 running at 16MHz with a baudrate of 500kb/s and the masks and filters disabled.
if(CAN0.begin(MCP_ANY, CAN_500KBPS, MCP_16MHZ) == CAN_OK) Serial.println("MCP2515 Initialized Successfully!");
else Serial.println("Error Initializing MCP2515...");
CAN0.setMode(MCP_NORMAL); // Change to normal mode to allow messages to be transmitted
//CAN0.abortTX();
pinMode(CAN0_INT, INPUT);
delay(1000);
}
byte data[8] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07};
void loop()
{
// send data: ID = 0x100, Standard CAN Frame, Data length = 8 bytes, 'data' = array of data bytes to send
byte sndStat = CAN0.sendMsgBuf(0x100, 0, 8, data);
if(sndStat == CAN_OK){
Serial.println("Message Sent Successfully!");
} else {
Serial.println("Error Sending Message...");
}
delay(1000); // send data per 100ms
}
/*********************************************************************************************************
END FILE
*********************************************************************************************************/>
In the monitor I get --08:01:19.774 -> Entering Configuration Mode Successful!
08:01:19.774 -> Setting Baudrate Successful!
08:01:19.774 -> MCP2515 Initialized Successfully!
08:01:20.754 -> Error Sending Message...
08:01:21.758 -> Error Sending Message...
If I uncomment the line -- //CAN0.abortTX(); and run the program
I get the following in the monitor but I don't think the messages are actually being sent --07:55:22.266 -> Entering Configuration Mode Successful!
07:55:22.266 -> Setting Baudrate Successful!
07:55:22.341 -> MCP2515 Initialized Successfully!
07:55:23.311 -> Message Sent Successfully!
07:55:24.311 -> Message Sent Successfully!
I have used a new MCP-2515 board and the same thing happens. I think it is a software problem. I must have corrupted something. There does not seem to be a reset function to correct this. My board has an 8.000 on the crystal and I tried the MCP_8MHZ in the 'begin' function but that did not help.
Any Thoughts would be appreciated.



