Hi, I'm trying to read can using Arduino Mega and mcp2515.
Mcp_2515 example has been used but is not read
The wiring is
Sck - 52
Si - 51
So - 50
Cs - 53
Int - 20
And set to
500Kbps, 8MHz
#include <mcp_can.h>
#include <SPI.h>
long unsigned int rxId;
unsigned char len = 0;
unsigned char rxBuf[8];
MCP_CAN CAN0(53);
void setup() {
Serial.begin(115200);
if (CAN0.begin(MCP_ANY, CAN_500KBPS, MCP_20MHZ) == CAN_OK) {
Serial.println("CAN Success");
} else {
Serial.println("CAN Fail");
while (1);
}
pinMode(20, INPUT);
Serial.println("MCP2515 Library Receive Example...");
}
void loop() {
if (!digitalRead(20)) {
CAN0.readMsgBuf(&rxId, &len, rxBuf);
Serial.print("ID: ");
Serial.print(rxId, HEX);
Serial.print(" Data: ");
for (int i = 0; i < len; i++) {
if (rxBuf[i] < 0x10) {
Serial.print("0");
}
Serial.print(rxBuf[i], HEX);
Serial.print(" ");
}
Serial.println();
}
}