no matching function for call to 'MCP_CAN::begin(int)'.. pls help me

hello!
I am using a baorepo CAN bus shield for the arduino uno. I tried to upload a example code called(receive check) and im getting the following error (no matching function for call to ‘MCP_CAN::begin(int)’)

Can someone help me with this error? And I’ve tried everything to fix it.

Post your full code copied directly from the Arduino IDE. USE CODE TAGS.

Copy the full error message from the IDE (there's a convenient button to do this). Post it here.

// demo: CAN-BUS Shield, receive data with check mode
// send data coming to fast, such as less than 10ms, you can use this way
// loovee, 2014-6-13


#include <SPI.h>
#include "mcp_can.h"

/*SAMD core*/
#ifdef ARDUINO_SAMD_VARIANT_COMPLIANCE
    #define SERIAL SerialUSB
#else
    #define SERIAL Serial
#endif

// the cs pin of the version after v1.1 is default to D9
// v0.9b and v1.0 is default D10
const int SPI_CS_PIN = 9;

MCP_CAN CAN(SPI_CS_PIN);                                    // Set CS pin

void setup() {
    SERIAL.begin(115200);

    while (CAN_OK != CAN.begin(CAN_500KBPS)) {            // init can bus : baudrate = 500k
        SERIAL.println("CAN BUS Shield init fail");
        SERIAL.println(" Init CAN BUS Shield again");
        delay(100);
    }
    SERIAL.println("CAN BUS Shield init ok!");
}


void loop() {
    unsigned char len = 0;
    unsigned char buf[8];

    if (CAN_MSGAVAIL == CAN.checkReceive()) {         // check if data coming
        CAN.readMsgBuf(&len, buf);    // read data,  len: data length, buf: data buf

        unsigned long canId = CAN.getCanId();

        SERIAL.println("-----------------------------");
        SERIAL.print("Get data from ID: 0x");
        SERIAL.println(canId, HEX);

        for (int i = 0; i < len; i++) { // print the data
            SERIAL.print(buf[i], HEX);
            SERIAL.print("\t");
        }
        SERIAL.println();
    }
}

/*********************************************************************************************************
    END FILE
*********************************************************************************************************/

There’s the code directly form the arduino IDE
And here’s the error code directly from IDE.

Arduino: 1.8.12 (Windows 10), Board: "Arduino Uno"

D:\Programs\Arduino\libraries\CAN_BUS_Shield-master\examples\receive_check\receive_check.ino:13:0: warning: "SERIAL" redefined

     #define SERIAL Serial

 

In file included from sketch\receive_check.ino.cpp:1:0:

D:\Programs\Arduino\hardware\arduino\avr\cores\arduino/Arduino.h:54:0: note: this is the location of the previous definition

 #define SERIAL  0x0

 

D:\Programs\Arduino\libraries\CAN_BUS_Shield-master\examples\receive_check\receive_check.ino: In function 'void setup()':

receive_check:25:43: error: no matching function for call to 'MCP_CAN::begin(int)'

     while (CAN_OK != CAN.begin(CAN_500KBPS)) {            // init can bus : baudrate = 500k

                                           ^

In file included from D:\Programs\Arduino\libraries\CAN_BUS_Shield-master\examples\receive_check\receive_check.ino:7:0:

D:\Apps\Documents\Arduino\libraries\mcp_can/mcp_can.h:108:11: note: candidate: byte MCP_CAN::begin(byte, byte, byte)

     INT8U begin(INT8U idmodeset, INT8U speedset, INT8U clockset);       // Initilize controller prameters

           ^~~~~

D:\Apps\Documents\Arduino\libraries\mcp_can/mcp_can.h:108:11: note:   candidate expects 3 arguments, 1 provided

D:\Programs\Arduino\libraries\CAN_BUS_Shield-master\examples\receive_check\receive_check.ino: In function 'void loop()':

receive_check:39:33: error: no matching function for call to 'MCP_CAN::readMsgBuf(unsigned char*, unsigned char [8])'

         CAN.readMsgBuf(&len, buf);    // read data,  len: data length, buf: data buf

                                 ^

In file included from D:\Programs\Arduino\libraries\CAN_BUS_Shield-master\examples\receive_check\receive_check.ino:7:0:

D:\Apps\Documents\Arduino\libraries\mcp_can/mcp_can.h:116:11: note: candidate: byte MCP_CAN::readMsgBuf(long unsigned int*, byte*, byte*, byte*)

     INT8U readMsgBuf(INT32U *id, INT8U *ext, INT8U *len, INT8U *buf);   // Read message from receive buffer

           ^~~~~~~~~~

D:\Apps\Documents\Arduino\libraries\mcp_can/mcp_can.h:116:11: note:   candidate expects 4 arguments, 2 provided

D:\Apps\Documents\Arduino\libraries\mcp_can/mcp_can.h:117:11: note: candidate: byte MCP_CAN::readMsgBuf(long unsigned int*, byte*, byte*)

     INT8U readMsgBuf(INT32U *id, INT8U *len, INT8U *buf);               // Read message from receive buffer

           ^~~~~~~~~~

D:\Apps\Documents\Arduino\libraries\mcp_can/mcp_can.h:117:11: note:   candidate expects 3 arguments, 2 provided

receive_check:41:35: error: 'class MCP_CAN' has no member named 'getCanId'

         unsigned long canId = CAN.getCanId();

                                   ^~~~~~~~

Multiple libraries were found for "mcp_can.h"
 Used: D:\Apps\Documents\Arduino\libraries\mcp_can
 Not used: D:\Apps\Documents\Arduino\libraries\MCP_CAN_lib-master
 Not used: D:\Programs\Arduino\libraries\CAN_BUS_Shield-master
exit status 1
no matching function for call to 'MCP_CAN::begin(int)'

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

It appears you have not properly installed the (correct) library. I'd start by fixing this:

Multiple libraries were found for "mcp_can.h"
 Used: D:\Apps\Documents\Arduino\libraries\mcp_can
 Not used: D:\Apps\Documents\Arduino\libraries\MCP_CAN_lib-master
 Not used: D:\Programs\Arduino\libraries\CAN_BUS_Shield-master

Faraday Member
Posts: 4,997

Looks you'll be getting promoted soon.

PaulS:
Looks you'll be getting promoted soon.

Doesn't appear so. Just hit 5000+ and I don't feel any different :astonished: