CAN-BUS Error 5 and solid INT LED

There are two way to check if the canbus shield receive data, interrupt or check by a a function: CAN.checkReceive() . When there is some data coming, this will return CAN_MSGAVAIL(no data coming is CAN_NOMSG ).

I found that when the data is too fast, such as less than 10ms, the interrupt way will cause some problem. But you can use the other way, checkReceive(). you can try the following test code:

[code]//send.ino
// demo: CAN-BUS Shield, send data
#include <mcp_can.h>
#include <SPI.h>

void setup()
{
Serial.begin(115200);
// init can bus, baudrate: 500k
if(CAN.begin(CAN_500KBPS) ==CAN_OK) Serial.print(“can init ok!!\r\n”);
else Serial.print(“Can init fail!!\r\n”);
}

unsigned char stmp[8] = {0, 1, 2, 3, 4, 5, 6, 7};
void loop()
{
// send data: id = 0x00, standrad flame, data len = 8, stmp: data buf
for(int i=0; i<10000; i++)
{
CAN.sendMsgBuf(0x00, 0, 8, stmp);
delay(1);
}

Serial.println(“send 10000 over”);
while(1);
}[/code]

//recv.ino
// demo: CAN-BUS Shield, receive data
#include "mcp_can.h"
#include <SPI.h>
#include <stdio.h>
#define INT8U unsigned char
 
INT8U Flag_Recv = 0;
INT8U len = 0;
INT8U buf[8];
char str[20];
void setup()
{
    Serial.begin(115200);
    CAN.begin(CAN_500KBPS);                   // init can bus : baudrate = 500k
    //attachInterrupt(0, MCP2515_ISR, FALLING); // start interrupt
  
}
 
/*
void MCP2515_ISR()
{
     Flag_Recv = 1;
}*/
 
long sum=0;
void loop()
{
    //if(Flag_Recv)                   // check if get data
    if(MCP_STAT_RXIF_MASK == CAN.checkReceive())
    {
       sum++;
       Serial.println(sum);
      //Flag_Recv = 0;                // clear flag
      CAN.readMsgBuf(&len, buf);    // read data,  len: data length, buf: data buf
     // Serial.println("CAN_BUS GET DATA!");
      //Serial.print("data len = ");
      //Serial.println(len);
     /* for(int i = 0; i<len; i++)    // print the data
      {
        Serial.print(buf[i]);Serial.print("\t");
      }*/
      //Serial.println();
    }
}