Can you advise on what else is needed and at which point in the code you think it should go?
I have added the serial.begin(9600) to the code as shown below, but as soon as i iopen the serial monitor, it crashes the BUS.
#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); ADDED HERE
{
CAN.begin(CAN_500KBPS);
attachInterrupt(0, MCP2515_ISR, FALLING);
}
void MCP2515_ISR()
{
Flag_Recv = 1;
}
void loop()
{
if(Flag_Recv)
{
Flag_Recv = 0;
CAN.readMsgBuf(&len, buf);
if(buf[0] == 02 && buf[1] == 01 && buf[2] == 00)
{
unsigned char b[8] = {0x06, 0x41, 0x00 ,0xbe ,0x3f ,0xa8 ,0x13 ,0x00};
unsigned char c[8] = {0x06, 0x41, 0x00 ,0x98 ,0x1e ,0x80 ,0x13 ,0x00};
CAN.sendMsgBuf(0x7e8, 0, 8, b);
CAN.sendMsgBuf(0x7e9, 0, 8, c);
}
if(buf[0] == 02 && buf[1] == 01 && buf[2] == 0x0d)
{
unsigned char a[8] = {0x03 ,0x41 ,0x0d ,0x00 ,0x00 ,0x00 ,0x00 ,0x00};
CAN.sendMsgBuf(0x7e8, 0, 8, a);
CAN.sendMsgBuf(0x7e9, 0, 8, a);
}
}
}