Problem with Seed-Studio_CAN library

Hello Everyone,

i am trying to use the CAN-Bus Shield, but i facing some issue in compiling.
Of course i follows step by step the on-line tutorial (CAN-BUS Shield V2.0 - Seeed Wiki), downloading the library from git-hub repository (GitHub - Seeed-Studio/Seeed_Arduino_CAN: Seeed Arduino CAN-BUS library - MCP2518FD&MCP2515&MCP2551).

My code is very basic. I report it in the following:

#include <SPI.h>
#include “mcp2515_can.h”

const int SPI_CS_PIN = 9;
const int CAN_INT_PIN = 2;

mcp2515_can CAN(SPI_CS_PIN);

void setup() {
SERIAL_PORT_MONITOR.begin(115200);
while(CAN_OK != CAN.begin(CAN_500KBPS)){
SERIAL_PORT_MONITOR.println(“Inizializzazione CAN - FALLITA!”);
delay(100); // ci riprova tra 100 [ms]
}
SERIAL_PORT_MONITOR.println(“Inizializzazione CAN - eseguita con SUCCESSO!”);
}

unsigned char stmp[8] = {1,2,3,4,5,6,7,8};

void loop() {
CAN.sendMsgBuf(0x100, 0, 8, stmp);
delay(100);
}

Error i face is the following:

C:\Users\paolo\Desktop\ArduinoCAN-Shield_TX\ArduinoCAN-Shield_TX.ino: In function ‘void loop()’:
ArduinoCAN-Shield_TX:21:37: error: no matching function for call to ‘mcp2515_can::sendMsgBuf(int, int, int, unsigned char [8])’
CAN.sendMsgBuf(0x100, 0, 8, stmp);
^
In file included from C:\Users\paolo\Desktop\ArduinoCAN-Shield_TX\ArduinoCAN-Shield_TX.ino:2:0:
C:\Users\paolo\OneDrive\Documenti\Arduino\libraries\Seeed_Arduino_CAN-master\src/mcp2515_can.h:93:18: note: candidate: virtual byte mcp2515_can::sendMsgBuf(byte, long unsigned int, byte, byte, byte, const volatile byte*)
virtual byte sendMsgBuf(byte status, unsigned long id, byte ext, byte rtrBit, byte len, volatile const byte *buf); // send message buf by using parsed buffer status
^~~~~~~~~~
C:\Users\paolo\OneDrive\Documenti\Arduino\libraries\Seeed_Arduino_CAN-master\src/mcp2515_can.h:93:18: note: candidate expects 6 arguments, 4 provided
C:\Users\paolo\OneDrive\Documenti\Arduino\libraries\Seeed_Arduino_CAN-master\src/mcp2515_can.h:94:18: note: candidate: virtual byte mcp2515_can::sendMsgBuf(long unsigned int, byte, byte, byte, const byte*, bool)
virtual byte sendMsgBuf(unsigned long id, byte ext, byte rtrBit, byte len, const byte *buf, bool wait_sent = true); // send buf
^~~~~~~~~~
C:\Users\paolo\OneDrive\Documenti\Arduino\libraries\Seeed_Arduino_CAN-master\src/mcp2515_can.h:94:18: note: candidate expects 6 arguments, 4 provided
exit status 1
no matching function for call to ‘mcp2515_can::sendMsgBuf(int, int, int, unsigned char [8])’

For what i understand, the problem is linked with the “sendMsgBuf()” method, which requires 6 input instead 4.
But in the example i found the usage of this function is always with 4 inputs.

It is strange because the receiving code instead have good behaviour.

Can you help me?

Thanks in advance!!

Bests,

Pierpaolo.

Good Morning Everyone,

since i solved i like to share in order to help who face the same problem in future.
Making a bit more attention t the compilation error, indeed the fact that the function prototype require more input arguments is the relevant thing.

The right sintax is the following:

CAN.sendMsgBuf(0x1AF, 0, 0, 8, stmp);

sixth argument is configured with default value (leave as it is).

where: first, second, fourth and fifth arguments are the expected (id, extended frame or not indication, dlc and data vector).

The third argument is “critical”:
if is = 0 frome the RX node you can see the 8 bytes of the data vector as you expect form TX program, instead if you set = 1 it seems as ther is a “counter” that add the value of 2^{byte-index} or 2^{byte-index + 1} (in sequence) respect what you expect.

It seems a “service” of the method to emulate changing of the data frame (like in a real vehicle).

In any case, now it works.

I strongly suggest to update the tutorial!!

Bests,

Pierpaolo.

1 Like