The loopback test is executed successfully, so I think I have proper connection.
Now when I run the code, here is what I see in serial monitor
Entering Configuration Mode Successful!
Setting Baudrate Successful!
MCP2515 Initialized Successfully!
Error register value: 1000
Transmit error counter register value: 0
Receive error counter register value: 135
Error register value: 1000
Transmit error counter register value: 0
Receive error counter register value: 135
Error register value: 1000
Transmit error counter register value: 0
Receive error counter register value: 135
Here is my code...
// demo: CAN-BUS Shield, receive data
#include <mcp_can.h>
#include <SPI.h>
long unsigned int rxId;
unsigned char len = 0;
unsigned char rxBuf[8];
char msgString[128]; // Array to store serial string
/* PINS: CS=D8, INT=D4, SCK=D5, SO=D6, SI=D7 */
MCP_CAN CAN0(15); // Set CS to pin 15 (D8) --- 4 (D2 on my NodeMCU)
#define CAN0_INT 2 // Set INT to pin 2 = D4
void setup()
{
Serial.begin(115200);
// Initialize MCP2515 running at 8MHz with a baudrate of 500kb/s and the masks and filters disabled.
if(CAN0.begin(MCP_ANY, CAN_500KBPS, MCP_8MHZ) == CAN_OK) // was MCP_ANY MCP_STDEXT
Serial.println("MCP2515 Initialized Successfully!");
else
Serial.println("Error Initializing MCP2515...");
CAN0.setMode(MCP_NORMAL); // Set operation mode to normal so the MCP2515 sends acks to received data. MCP_NORMAL
pinMode(CAN0_INT, INPUT); // Configuring pin for /INT input
}
void loop()
{
if(!digitalRead(CAN0_INT)) // If CAN0_INT pin is low, read receive buffer
{
Serial.println("pin is low");
CAN0.readMsgBuf(&rxId, &len, rxBuf); // Read data: len = data length, buf = data byte(s)
if((rxId & 0x80000000) == 0x80000000) // Determine if ID is standard (11 bits) or extended (29 bits)
sprintf(msgString, "Extended ID: 0x%.8lX DLC: %1d Data:", (rxId & 0x1FFFFFFF), len);
else
sprintf(msgString, "Standard ID: 0x%.3lX DLC: %1d Data:", rxId, len);
Serial.print(msgString);
if((rxId & 0x40000000) == 0x40000000){ // Determine if message is a remote request frame.
sprintf(msgString, " REMOTE REQUEST FRAME");
Serial.print(msgString);
} else {
for(byte i = 0; i<len; i++){
sprintf(msgString, " 0x%.2X", rxBuf[i]);
Serial.print(msgString);
}
}
Serial.println();
}
if(CAN0.checkError() == CAN_CTRLERROR){ // from https://forum.arduino.cc/index.php?topic=402018.15
Serial.print("Error register value: ");
byte tempErr = CAN0.getError() & MCP_EFLG_ERRORMASK; // We are only interested in errors, not warnings.
Serial.println(tempErr, BIN);
Serial.print("Transmit error counter register value: ");
tempErr = CAN0.errorCountTX();
Serial.println(tempErr, DEC);
Serial.print("Receive error counter register value: ");
tempErr = CAN0.errorCountRX();
Serial.println(tempErr, DEC);
//I do not have a function that clears errors and that has been added to my todo list. 04/26/17 CJF
}
}
How can I find out what is meant by
Receive error counter register value: 135 ?
Other thing I should mention is that I'm using a NodeMCU @ 5V
I am stepping down the INT line from 5V to 3.3v using a voltage divider.
Thanks!!