CAN BUS debug sent data

Hi,
I recently brought CAN-BUS shield for my arduino and tried to get some data from my car. It works perfectly and I have little log file with message id’s and its content. Now I want to send this messages back to multifunctional display in my car and there is a problem I can’t even get backlight on :confused:
Is there any way to debug sent message? Something like that I sent message(sendMsgBuf)()) and somehow even get it back(readMsgBuf()) without second CAN-BUS shield?

I’ve made simple program in Java which communicates with arduino through serial port and I’m sending messages in fromat

messageId,dataLength,1-8*data -> 1,8,255,255,255,255,255,255,255,255

and then in parsing and send in arduino with this code. I know it messy for now as I did not refactor it

String readString;
INT32U messageId = 0x00;
INT8U byteArrayLength = 0;
unsigned char len = 0;
unsigned char buf[8];
.
.
.
INT8U comaPosition = readString.indexOf(",");
messageId = readString.substring(0, comaPosition).toInt();
readString = readString.substring(comaPosition+1);
comaPosition = readString.indexOf(",");
byteArrayLength = readString.substring(0, comaPosition).toInt();
readString = readString.substring(comaPosition+1);
        
unsigned char data[byteArrayLength];
for(int i = 0; i < byteArrayLength; i++){
  comaPosition = readString.indexOf(",");
  data[i] = char(readString.substring(0,comaPosition).toInt());
  readString = readString.substring(comaPosition+1);
}
CAN.sendMsgBuf(messageId, 0, byteArrayLength, data);

Is it good way to send data throught CAN-BUS shield? Are they in good format? As I said with this code when I sent all messages from log file I can’t even get backlight on on my multifunctional display. Thanks

You could edit the library (or use the sub-development version located on my GitHub) to put the MCP2515 in loopback mode. Nothing will be transmitted onto the bus, but it will allow you to receive what was transmitted from the MCP2515.

Hi,

I am completely new to CAN and Arduino while for a project I am using Your library and examples to start with. I am trying to edit library to use my CAN BUS in loopback mode for testing but its not working. I tried to set mode to LOOPBACK for which I used mcp2515_setCANCTRL_Mode(MODE_LOOPBACK) API and for that I added the API to Public scope inspite of Private scope. But its giving compilation error as : “error: ‘mcp2515_setCANCTRL_Mode’ was not declared in this scope”. It has to be done this way or there is some other method to use the library for LOOPBACK mode ?

Please help.

Did you prepend CAN0. or what you named it to the function?

CAN0.mcp2515_setCANCTRL_Mode(MODE_LOOPBACK);

Also, the sub-development branch of the library on my Github has a public function to do just this. I found it is better to start the MCP2515 up in loop-back mode as default and then go over to normal (or another) mode after initializations.