-2

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

What is the reason for the error message?

code:

#include <SPI.h> 
#include <mcp_can.h> 
#define SPI_CS_PIN 9
#define LED 8 
MCP_CAN CAN0(SPI_CS_PIN); 
void setup()
{
  Serial.begin(9600); 
  pinMode(LED,OUTPUT); 
  while (CAN_OK == CAN0.begin(MCP_ANY, CAN_500KBPS, MCP_8MHZ)) //can bus : baudrate = 500k 
  { 
    Serial.println("CAN BUS Shield Baslatmasi Basarili!");
  }
  Serial.println("CAN BUS Shield Baslatma Hatasi"); 
  Serial.println("CAN BUS Shield Tekrar Baslatiliyor…"); 
  delay(100);
}


void loop()
{ 
  unsigned char len = 0; 
  unsigned char buf[8]={0,0,0,0,0,0,0,0};
  if(CAN_MSGAVAIL == CAN0.checkReceive())
  { 
    CAN0.readMsgBuf(&len, buf);
    unsigned long canId = CAN0.getCanId(); 
    Serial.println("—————————–");
    Serial.print("Verici ID: 0x");
    Serial.println(canId, HEX);
    for(int i = 0; i<len; i++)
    {
      Serial.print(buf[i]); 
      Serial.print("\t");
      digitalWrite(LED, buf[0]);
      delay(100); 
    } 
    Serial.println(); 
  }
}

error message

    /tmp/741787960/sketch_may13a/sketch_may13a.ino: In function 'void loop()':

/tmp/741787960/sketch_may13a/sketch_may13a.ino:26:30: error: no matching function for call to 'MCP_CAN::readMsgBuf(unsigned char*, unsigned char [8])'

CAN0.readMsgBuf(&len, buf);

^

In file included from /tmp/741787960/sketch_may13a/sketch_may13a.ino:2:0:

/home/builder/opt/libraries/latest/mcp_can_1_5_0/mcp_can.h:119: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

^~~~~~~~~~

/home/builder/opt/libraries/latest/mcp_can_1_5_0/mcp_can.h:119:11: note: candidate expects 4 arguments, 2 provided

/home/builder/opt/libraries/latest/mcp_can_1_5_0/mcp_can.h:120: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

^~~~~~~~~~

/home/builder/opt/libraries/latest/mcp_can_1_5_0/mcp_can.h:120:11: note: candidate expects 3 arguments, 2 provided

/tmp/741787960/sketch_may13a/sketch_may13a.ino:27:32: error: 'class MCP_CAN' has no member named 'getCanId'; did you mean 'getGPI'?

unsigned long canId = CAN0.getCanId();

^~~~~~~~

getGPI

Error during build: exit status 1
New contributor
Muhammed Atmaca is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
2
  • 2
    it looks like you have a sketch for a different version of the library
    – Juraj
    May 13 at 17:22
  • Are you using Seeeds CAN library? If so, make sure it's properly installed. The errors are quite explicit - there isn't a matching function because the only function that the compiler can find in the library that you linked in your program requires 4 arguments and you are passing in 2. The second error is that there is no "getCanId()" method in the library that you linked. If you are still having issues after that, come back here and edit your question. Hope that helps!
    – Nick S.
    May 13 at 17:32

0

Browse other questions tagged or ask your own question.