🛠 Bus CAN FD : relier deux R4 avec un transceiver externe

Arduino UNO R4 WiFi · avance · Schéma : IMG-uno-r4-wifi-avance-3-ur4wifi-can-fd.svg — deux UNO R4 WiFi face à face, chacune reliée à un module transceiver CAN FD, paires de fils CANH/CANL reliant les deux modules, résistance 120 Ω aux deux extrémités, matrice LED affichant un compteur reçu.

Objectives

Move beyond point-to-point communication: the RA4M1 integrates a CAN FD (Flexible Data-rate) controller, a rare feature on an Arduino board — the official Arduino_CAN library exploits it. The RA4M1 provides the controller, but NOT the physical layer: you need an external CAN FD transceiver between the board and the bus. You will connect two boards and exchange frames at 500 kbit/s (arbitration) / 2 Mbit/s (data).

Hardware

Code (transmitter, the other board as receiver with the twin example)

#include <CANFD.h>

void setup {
  Serial.begin(115200);
  // Débit d'arbitrage 500 kbit/s, débit de données 2 Mbit/s :
  if (!CANFD.begin(CanBitRate::BR_500k_BR_2M)) {
    Serial.println(F("CAN FD init KO"));
    while (true) { }
  }
}

void loop {
  static uint8_t compteur = 0;
  CanFrame trame;
  trame.canId = 0x123;
  trame.dataLength = 1;
  trame.data[0] = compteur++;
  CANFD.transmit(trame);
  Serial.print(F("emis ")); Serial.println(trame.data[0]);
  delay(500);
}

Expected Verification

On the receiver side, the frame arrives with its ID 0x123 and an incremented counter; the receiver board's LED matrix can display the value. Diagnostic test: disconnect CANL — nothing gets through anymore; remove one termination — intermittent arbitration errors.

Common Errors

Other tutorials for this board

Code examples for this board

← Back to the board 🛠 All tutorials