MCP_CAN_Lib compling error for esp8266

Hi, I'm trying to implement CAN bus to share data between arduino nano and esp8266 (Lolin (wemos) D1 mini pro). I have big trouble making this work. After some trials I'm ended up with GitHub - coryjfowler/MCP_CAN_lib: MCP_CAN Library, so with this code:

// CAN Receive Example
//

#include </home/myuser/Arduino/libraries/MCP_CAN_lib/mcp_can.h>
#include <SPI.h>

#define D0 16
#define D1 5 // I2C Bus SCL (clock)
#define D2 4 // I2C Bus SDA (data)
#define D3 0
#define D4 2 // Same as "LED_BUILTIN", but inverted logic
#define D5 14 // SPI Bus SCK (clock)
#define D6 12 // SPI Bus MISO 
#define D7 13 // SPI Bus MOSI
#define D8 15 // SPI Bus SS (CS)
#define D9 3 // RX0 (Serial console)
#define D10 1 // TX0 (Serial console)

long unsigned int rxId;
unsigned char len = 0;
unsigned char rxBuf[8];
char msgString[128];                        // Array to store serial string

#define CAN0_INT D0                             // Set INT to pin 2
MCP_CAN CAN0(D8);                               // Set CS to pin 10


void setup()
{
  Serial.begin(9600);
  
  // Initialize MCP2515 running at 8MHz with a baudrate of 500kb/s and the masks and filters disabled.
  if(CAN0.begin(MCP_ANY, CAN_500KBPS, MCP_8MHZ) == CAN_OK)
    Serial.println("MCP2515 Initialized Successfully!");
  else
    Serial.println("Error Initializing MCP2515...");
  
  CAN0.setMode(MCP_NORMAL);                     // Set operation mode to normal so the MCP2515 sends acks to received data.

  pinMode(CAN0_INT, INPUT);                            // Configuring pin for /INT input
  
  Serial.println("MCP2515 Library Receive Example...");
}

void loop()
{
  if(!digitalRead(CAN0_INT))                         // If CAN0_INT pin is low, read receive buffer
  {
    CAN0.readMsgBuf(&rxId, &len, rxBuf);      // Read data: len = data length, buf = data byte(s)
    
    if((rxId & 0x80000000) == 0x80000000)     // Determine if ID is standard (11 bits) or extended (29 bits)
      sprintf(msgString, "Extended ID: 0x%.8lX  DLC: %1d  Data:", (rxId & 0x1FFFFFFF), len);
    else
      sprintf(msgString, "Standard ID: 0x%.3lX       DLC: %1d  Data:", rxId, len);
  
    Serial.print(msgString);
  
    if((rxId & 0x40000000) == 0x40000000){    // Determine if message is a remote request frame.
      sprintf(msgString, " REMOTE REQUEST FRAME");
      Serial.print(msgString);
    } else {
      for(byte i = 0; i<len; i++){
        sprintf(msgString, " 0x%.2X", rxBuf[i]);
        Serial.print(msgString);
      }
    }
        
    Serial.println();
  }
}

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

I'm having compiling error: below first error from log.

/home/myuser/.arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/3.0.4-gcc10.3-1757bed/bin/../lib/gcc/xtensa-lx106-elf/10.3.0/../../../../xtensa-lx106-elf/bin/ld: /tmp/arduino_build_273614/sketch/CAN_receive.ino.cpp.o:(.text.setup+0x14): undefined reference to `_ZN7MCP_CAN5beginEhhh'
/home/myuser/.arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/3.0.4-gcc10.3-1757bed/bin/../lib/gcc/xtensa-lx106-elf/10.3.0/../../../../xtensa-lx106-elf/bin/ld: /tmp/arduino_build_273614/sketch/CAN_receive.ino.cpp.o:(.text.setup+0x18): undefined reference to `_ZN7MCP_CAN7setModeEh'
/home/myuser/.arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/3.0.4-gcc10.3-1757bed/bin/../lib/gcc/xtensa-lx106-elf/10.3.0/../../../../xtensa-lx106-elf/bin/ld: /tmp/arduino_build_273614/sketch/CAN_receive.ino.cpp.o: in function `setup':
/home/myuser/Arduino/libraries/MCP_CAN_lib/examples/CAN_receive/CAN_receive.ino:29: undefined reference to `_ZN7MCP_CAN5beginEhhh'
/home/myuser/.arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/3.0.4-gcc10.3-1757bed/bin/../lib/gcc/xtensa-lx106-elf/10.3.0/../../../../xtensa-lx106-elf/bin/ld: /home/salvicio/Arduino/libraries/MCP_CAN_lib/examples/CAN_receive/CAN_receive.ino:33: undefined reference to `_ZN7MCP_CAN7setModeEh'
/home/myuser/.arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/3.0.4-gcc10.3-1757bed/bin/../lib/gcc/xtensa-lx106-elf/10.3.0/../../../../xtensa-lx106-elf/bin/ld: /tmp/arduino_build_273614/sketch/CAN_receive.ino.cpp.o:(.text.loop+0x28): undefined reference to `_ZN7MCP_CAN10readMsgBufEPmPhS1_'
/home/myuser/.arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/3.0.4-gcc10.3-1757bed/bin/../lib/gcc/xtensa-lx106-elf/10.3.0/../../../../xtensa-lx106-elf/bin/ld: /tmp/arduino_build_273614/sketch/CAN_receive.ino.cpp.o: in function `loop':
/home/myuser/Arduino/libraries/MCP_CAN_lib/examples/CAN_receive/CAN_receive.ino:47: undefined reference to `_ZN7MCP_CAN10readMsgBufEPmPhS1_'

Hope for some suggestions.
Regards

I am having the same problem but with a different library. I believe my pinout is different but no success. I did not think that library was compatible with the WeMos D1 R1 which I am using. I could not find any consistency in how to connect the SPI bus. Several of the pins on mine are connected together. I will look tomorrow and see if I can find what I worked out. I have that library working without any problems on both the Nano and Uno, several of each running. My project is a home automation replacement for the existing one that is about 20 years old.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.