Enclosed is an overview of my breadboard with the MCP2515 module.
This setup I have 2 times – also 2 times with the identical effect.
In this example, only one setup communicates with a Peak dongle. The Peak dongle sends every second a message, received by the MCP2515 and send back.
In this case I work with the MCP_CAN_lib
#include <mcp_can.h>
#include <SPI.h>
MCP_CAN CAN0(10); // Set CS to pin 10
unsigned int MsgCounter = 0;
unsigned long currentMillis;
void setup() {
Serial.begin(9600);
// 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
}
void loop() {
long unsigned int rxId;
unsigned char len = 0;
unsigned char rxBuf[8];
while (CAN_MSGAVAIL == CAN0.checkReceive())
{
CAN0.readMsgBuf(&rxId, &len, rxBuf); // Read data
CAN0.sendMsgBuf(rxId+1, 0, len, rxBuf); // and send echo back
currentMillis = millis();
MsgCounter++;
Serial.print(MsgCounter);
Serial.print(" ");
Serial.println(currentMillis);
}
}
Also a screenshot of the Pcan-View with the bus speed. It is only 250kbit/s and not 500 as defined in the programm. The same result I also get with my CANalyzer tool.
If a message is received, I output a time stamp on the serial interface. The difference time is 1000msek as from the peak dongle.
Do you have any idea?
Regards
Bjoern
