mcp_can::begin(int) Error

Hello,

I am fairly new to Arduino coding and trying to make a piece of code work to adjust the voltage of my project power supply, using CAN BUS.

The code has been used by a lot of people over the years and confirmed working however I am getting an error message when I try and verify the code in the Arduino IDE.

I am using a Hobby Tronics Leonardo CAN BUS board - Leonardo CAN BUS board

I have downloaded MCP_CAN.h files and looked for this error code previously on the forum however I am still not able to solve my problem. Please see my included code.

The error code I am receiving is - "No matching function for call to "MCP_CAN::begin(int)"

Am I missing something glaringly obvious?

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

const int SPI_CS_PIN = 10;                                                          // Set CS pin to pin 10 (could be 9 for other CANshields)
MCP_CAN CAN(SPI_CS_PIN);                                                            // Set CS pin for CANBUS shield

void setup()                                                                        // Initialisation routine
{

START_INIT:

    if(CAN_OK == CAN.begin(CAN_125KBPS))                                            // init can bus : baudrate = 125k !!
    {
    }
    else
    {
    delay(100);
    goto START_INIT;
    }
    unsigned char login[8] = {0x14, 0x14, 0x71, 0x11, 0x08, 0x20, 0x00, 0x00};     //this is the serial number of the unit + 2 added bytes of 00 each, sernr on the unit reads 141471110820)
    CAN.sendMsgBuf(0x05004804, 1, 8, login);                                       //send message to log in and assign ID=1 (last 04 means ID=1, for ID=2 use 05004808 ) 

    unsigned char setdefaultvolt[5] = {0x29, 0x15, 0x00, 0xC0, 0x12};              //this is the command for setting the default output voltage (Last two bytes, LSB first). 16 80 is the maximum voltage of 57.6 V
    CAN.sendMsgBuf(0x05019C00, 1, 5, setdefaultvolt);                              //send message to set ouput voltage to all chargers connected to the CAN-bus
}

void loop()                                                                        // main program (LOOP)
{                                                                                  // nothing to do :)
}

/*********************************************************************************************************
  END FILE
  Voltage settings 
  80 16 => 1680 HEX = 57,60 Volt (= highest possible voltage
  E6 14 => 14E6 HEX = 53,50 Volt (= factory set voltage)
  FE 10 => 10FE HEX = 43,50 Volt (= lowest possible voltage)
  C0 12 => 12C0 HEX = 48,00 Volt (= optimum voltage)
*********************************************************************************************************/

You didn't provide a link to the library you downloaded. But, let's assume you did so from here: GitHub - Seeed-Studio/Seeed_Arduino_CAN: Seeed Arduino CAN-BUS library - MCP2518FD&MCP2515&MCP2551

If you open up MCP_CAN.h, you'll see:

virtual byte begin(uint32_t speedset, const byte clockset) = 0;                     // init can

So, the begin() function requires 2 arguments and you're only providing one.

Thank you for your response, my apologies, I downloaded the library from here - GitHub - coryjfowler/MCP_CAN_lib: MCP_CAN Library

As mentioned I am fairly new to Arduino programming. Would you be able to advise me on how to rectify the problem in relation to the code I have posted?

reptilemarine:
Thank you for your response, my apologies, I downloaded the library from here - GitHub - coryjfowler/MCP_CAN_lib: MCP_CAN Library

As mentioned I am fairly new to Arduino programming. Would you be able to advise me on how to rectify the problem in relation to the code I have posted?

OK, at that location, the relevant line in mcp_can.h is:

INT8U begin(INT8U idmodeset, INT8U speedset, INT8U clockset);       // Initialize controller parameters

So, the function want 3 arguments and you're only supplying 1. That makes the compiler unhappy. I'm not familiar with that library (nor have I used CAN bus in any of my projects), so I can't tell you what those arguments need to be. I can only say that you need 3 of them. Your best bet would be to study the examples that come with the library.

Thank you for your help, I shall keep researching and learning.

reptilemarine:
The code has been used by a lot of people over the years and confirmed working...

Is it possible that this code you've found was intended to work with a different CAN library? Here's one whose begin() function only takes one argument:

Hello,

I have just found that resource and have got the scripts to verify. Thank you for your help. My next issue is loading the program onto the Leonardo style board, windows sees the com port and when I go to upload the script the com port drops out. I have spent a few hours trying to find a solution. Another issue for another day I think. I appreciate your help.

Thread may now be closed as a reference to anyone else having the same issue as me.

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