Arduino Portenta CAN Library

Hello,
I wanted to ask if there is an official or a working third party Library for CAN bus available for Arduino Portenta H7 (Lite/Lite Connected). I just cant seem to find it anywhere.

Thanks!

Hi,

i´m also interested in CAN libary for Portenta H7

Thanks!

I would also be interested in a CAN Library for the h7. Or any information about using Can on the h7.

Same here ... Any information welcome for Portenta H7 + Portenta Breakout board. Machine control seems to be covered in the "Machine control examples".

Hi all, you can find a libary for Arduino Portenta Machine control. It works.
I didnt try it on the Portenta Breakout, but it should work also for it (!! there is no Tranceiver on Breakout !!).

*/
#include <Arduino_MachineControl.h>
#include <CAN.h>
using namespace machinecontrol;

#define DATARATE_250KB 250000

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

Serial.println("Start CAN initialization");
comm_protocols.enableCAN();
comm_protocols.can.frequency(DATARATE_250KB);
Serial.println("Initialization done");
}

int counter = 0;
unsigned char data[8];
int data_size = 8;

void loop() {

data[0] = 0x49;
data[1] = 0x32;
data[2] = 0x31;
data[3] = 0x30;
data[4] = 0x29;
data[5] = 0x28;
data[6] = 0x27;
data[7] = 0x26;

mbed::CANMessage msg = mbed::CANMessage(13ul, &data[0], data_size);
if (comm_protocols.can.write(msg)) {
Serial.println("Message sent");
} else {
Serial.println("Transmission Error: ");
Serial.println(comm_protocols.can.tderror());
comm_protocols.can.reset();
}

delay(100);
}

1 Like

Hey all,

Can anyone confirm this works with a portenta H7 given a CAN Transceiver is connected? We are currently selecting hardware for a project and if can communication doesn't work on the portenta H7 that would be a KO criterium for us.

Thanks and best regards
Daniel

Hi,
If someone has an idea of a CAN transceiver that wouls work with the Portenta Breakout, I'm interrested.
Thanks in advance.

From what I can tell, CAN is build into the mbed library, but I can't figure out the pinNames to map to.

#include <Arduino.h>
#include <mbed.h>

#include <Arduino_PortentaBreakout.h>

mbed::CAN can1(CAN0_RX, CAN0_TX);

This won't compile because CAN0_RX is type breakoutPin, and I need the pinName. I'm pulling my hair out trying to figure out the actual pins these are mapped to.

I'm trying to get one of these to work, but I'm still struggling with the H7 itself. Waveshare CAN Board

I also found this FULL pinout, which is hiding on the site. Portenta FULL pinout But I'm a bit confused by it too. It lists FD_CAN1_TX etc under different ports, but only shows 1 set of CAN_RX and TX on the J1 connector. But my breakout board has 2 sets of CAN hookups. I'm starting to think the documentation is wrong and/or just doesn't match my hardware. I saw somewhere else it pointed out that there is 4 versions, V1, V2, V3, and V4 boards, but no indication anywhere what is different. Mine is a V2 according to the box it came in.

So I'm currently staring at this and it's just not working

#include <Arduino.h>
#include <mbed.h>

mbed::CAN can1(PB_8, PH_13, 500 * 1000);

void process() {
  Serial.println("process called");
}

void setup() {
  Serial.begin(115200);
  
  can1.attach(process);
}

void loop() {
  mbed::CANMessage msg;
  msg.id = 2048;
  msg.len = 1;
  msg.data[0] = 25;

  int r = can1.write(msg);
  Serial.print("write success ?");
  Serial.println(r == 1 ? "Yup" : "Nope");
  
  if (can1.tderror() >= 248) {
    Serial.println("resetting can1");
    can1.reset();
  }
  if (can1.read(msg)) {
    printf("Message received: %d\n", msg.data[0]);
  }

  delay(1000);
  Serial.print(millis());
  Serial.print(" still going... ");
  Serial.println(can1.tderror());
  Serial.println("");
}

Hey there, I was close to giving up on this but seeing that others are also struggeling I am willing to keep on trying.
Here is what i figured out: the two can pairs on the breakout board are traced as follows:
CAN1_TX --> HD Connector 49
CAN1_RX --> HD Connector 51
CAN0_TX --> HD Connector 50
CAN0_RX --> HD Connector 52

On the portenta H7 board itself only connections for CAN1 are made:

CAN_RX and CAN_TX translate to PIN D5 and D16 of the MCU:

which should be PB8 and PH13 just as @jlaustill also figured out.

However i also cannot get it to run and at this point I tried multiple transceivers as well:

SN65HVD230 like @jlaustill
TCAN1044AEV-Q1
TI ISO1050 Isolated CAN Transceiver

all without success... tderrors just keep happening the same as if no transceiver is connected.

Did you setup the associated GPIO port and enabled the clocks for GPIOB and GPIOH? Never tried CAN but the GPIO port default register configuration might not be the one the CAN configuration requires. Default conf :
-analog mode
-push pull
-no pull up pull down
-...

Thanks for confirming what I was seeing. My project requires 2 canbus channels. I think the Portenta is dead to me. I bought a Teensy 4.1 and within 20 minutes of opening the package had canbus working sending and receiving messages, and it has 3 canbus channels, even one FDCAN. So I'm giving up and sticking the Portenta on the shelf.

"Yeaaaah": Portenta H7 is very complicated (even for me as system engineer for ARM embedded systems) and the Arudiono (mbed) API is so full of bugs...
I am also almost quitting to use Portenta H7...

Does anybody have CAN with interrupts working using the Arduino IDE and the Portenta and PMC?
I have the PORTENA with Machine Control board, but cannot get the IRQ for Rx to work.

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