UNO R4 CANBUS changing 29 bit CAN IDs to 11 bits

Hello.
Could, you, tell me how to change sending and receiving ID's from 29 to 11 bits?
CanMsg msg(can_id, sizeof(msg_data), msg_data); // HERE THERE IS NO OPTION TO CHANGE IT.
For example, in "mcp_can.h" library there is a bit responsible for ID'S extended:
CAN.sendMsgBuf(0x07B, 0, 8, canMsg);
How can I change it in UNO R4 <Arduino_CAN.h>?

1 Like

I URGENTLY second this! I use those boards in an industrial context, and was relying on the new CAN functionality to replace the existing setup with a the seed studio can shield. Our bus uses 11bit IDs

1 Like

refering to this library

the '0' implies Standard CAN ID (ie 11 bits), if '1', it means CAN ID will be set as extended (ie 29 bits)

so in summary you specify the type of the CAN ID when you send it.... don't really see what the problem is here...

This is not the library that is used for the Uno R4

With the ARDUINO_CAN library provided with Uno R4s this results in:
\AppData\Local\Arduino15\packages\arduino\hardware\renesas_uno\1.0.2\cores\arduino/api/CanMsg.h:36:3: note: candidate expects 3 arguments, 4 provided

irrelevant.

that library should be compatible IMHO...

if that file content is the same as this one, then it you can specify your CANmsg type with that library....

You can easily see the file content if you install the Arudino R4 Boards package into your IDE


Maybe something can be hacked together from different libraries that would work with the onboard CAN controller on R4 boards, but the official/validated/provided library does not seem to take 11bit CAN addresses into account, or it has some way of defining them that is not documented.

For your convenience, here is the official Arduino provided CanMsg.h as of Version 1.0.1 that does not accept an additional parameter after the ID to define ID bit length

/*
 * This file is free software; you can redistribute it and/or modify
 * it under the terms of either the GNU General Public License version 2
 * or the GNU Lesser General Public License version 2.1, both as
 * published by the Free Software Foundation.
 */

#ifndef ARDUINOCORE_API_CAN_MSG_H_
#define ARDUINOCORE_API_CAN_MSG_H_

/**************************************************************************************
 * INCLUDE
 **************************************************************************************/

#include <stdint.h>
#include <string.h>

#include <Arduino.h>

/**************************************************************************************
 * NAMESPACE
 **************************************************************************************/

namespace arduino
{

/**************************************************************************************
 * CLASS DECLARATION
 **************************************************************************************/

class CanMsg : public Printable
{
public:
  static size_t constexpr MAX_DATA_LENGTH = 8;

  CanMsg(uint32_t const can_id, uint8_t const can_data_len, uint8_t const * can_data_ptr)
  : id{can_id}
  , data_length{can_data_len}
  , data{0}
  {
    memcpy(data, can_data_ptr, min(can_data_len, MAX_DATA_LENGTH));
  }

  CanMsg() : CanMsg(0, 0, nullptr) { }

  CanMsg(CanMsg const & other)
  {
    this->id          = other.id;
    this->data_length = other.data_length;
    memcpy(this->data, other.data, this->data_length);
  }

  virtual ~CanMsg() { }

  void operator = (CanMsg const & other)
  {
    if (this == &other)
      return;

    this->id          = other.id;
    this->data_length = other.data_length;
    memcpy(this->data, other.data, this->data_length);
  }

  virtual size_t printTo(Print & p) const override
  {
    char buf[20] = {0};
    size_t len = 0;

    /* Print the header. */
    len = snprintf(buf, sizeof(buf), "[%08X] (%d) : ", (unsigned int)id, data_length);
    size_t n = p.write(buf, len);

    /* Print the data. */
    for (size_t d = 0; d < data_length; d++)
    {
      len = snprintf(buf, sizeof(buf), "%02X", data[d]);
      n += p.write(buf, len);
    }

    /* Wrap up. */
    return n;
  }

  uint32_t id;
  uint8_t  data_length;
  uint8_t  data[MAX_DATA_LENGTH];
};

/**************************************************************************************
 * NAMESPACE
 **************************************************************************************/

} /* arduino */

#endif /* ARDUINOCORE_API_CAN_MSG_H_ */

I'm not familiar with the libraries your are currently using for interfacing with the MCP2515 and will NOT delve into them for this matter.

as I have already previously stated IMHO the library I have shared offers the option you seek and is quite well establish in the arduino community if I should say so....

no one at any point wrote anything about MCP2515, and you vehemently quoting libraries from 2017 that do not work with the new boards doesn't help either

This issue is about the new Uno R4 board, with an onboard CAN controller within the SoC...
In case you have been living under a rock:

To clarify: The established libraries DO work with external CAN controllers like the one used on the seed studio shield or other CAN interface boards, but the new uno has the controller embedded in the chip, and does not use those libraries. It uses Arduinos own provided library.

my apologies for my misunderstanding then...

best bet would be to contact arduino support then. they do provide resonable support...

good luck!

No problem and thanks for actively engaging to help! There is a github issue for this already also, it is known not implemented at this time.

Thank you, guys, for discussing the topic. I use Arduino UNO R3 and MCP2515 CAN Bus controller with SPI interface for industrial CANBUS. It could be a good improvement to use the new Arduino UNO R4 with internal CANBUS. So, when you solve the problem, let me know, please

I've moved your topic to one of the dedicated R4 sections. Hope it get the attention of those in the know.

In order to make all relevant information available to any who are interested in this subject, I'll share a link to the feature request here:

Thanks. I have tested standard ID read and write on UNO R4 WIFI and it works. Earlier only CAN messages with extended IDs was read out, now standard IDs are read out and can be written too. Many thanks.

Is there any documentation on this new feature and how to change from extended ID to standard ID?

I am doing the following and still seeing ID: 00000020 on the CAN bus

static uint32_t const CAN_ID = 0x020;
CanMsg msg(CAN_ID, sizeof(msg_data), msg_data);
CAN.write(msg);

Hi @jdscholl. Have you installed the beta tester version of the "Arduino Renesas fsp Boards" platform, including the beta tester version of its arduino/ArduinoCore-API dependency, that have the added support for standard IDs?

If not, then it is expected that only extended IDs will be supported.

1 Like

Hi @ptillisch

Thank you for the help! No I have not.
I installed e2 studio and am following the README from "Arduino Renesas fsp Boards" platform

When building the project I get "**** Build of configuration Debug for project UNOR4 ****Nothing to build for project UNOR4"

and I do not see fsp_to_arduino.sh` script...

could you point me to any documentation on how to the beta tester version?

Thanks!

Hello
For Uno R4 I replaced two files,
one in C:\Users*YourUserName*\AppData\Local\Arduino15\packages\arduino\hardware\renesas_uno\1.0.2\libraries\Arduino_CAN\src
R7FA4M1_CAN.cpp
And
C:\Users*YourUserName*\AppData\Local\Arduino15\packages\arduino\hardware\renesas_uno\1.0.2\libraries\Arduino_CAN\examples\CANWrite
Downloaded them from

And

Thanks for the help!

I did that and now get the following error. "error: 'CanStandardId' was not declared in this scope"

any suggestions?

Here are all the changed files to make standard id work:

You can replace them all.
Hope this helps.