🛠 CAN bus between two R4 Minimas (external transceiver required)

Arduino UNO R4 Minima · intermediaire · Schéma : IMG-uno-r4-minima-intermediaire-3-can-bus-deux-cartes.svg — deux UNO R4 Minima, chacune avec un transceiver CAN (SN65HVD230) relié à ses broches CAN, bus différentiel CANH/CANL terminé par 120 Ω aux deux extrémités.

Goal

Exchange messages between two UNO R4 Minimas over CAN. The RA4M1 integrates the CAN *controller*, but the header only exposes controller-level signals: you must add an external transceiver (e.g. SN65HVD230 or MCP2551 module) to drive the differential bus.

Wiring

Per node: transceiver to the board's CAN pins (see the user manual for the exact header mapping), transceiver CANH to CANH and CANL to CANL across nodes, common GND, and 120-ohm termination at each end of the bus.

Sketch (both boards, same code)

#include <CAN.h>

void setup {
  Serial.begin(115200);
  CAN.begin(500E3);            // 500 kbit/s, both nodes identical
}

void loop {
  int packet = CAN.parsePacket;
  if (packet) {
    Serial.printf("id=0x%lX len=%d\n",
      CAN.packetId, packet);
    while (CAN.available)
      Serial.write(CAN.read);
    Serial.println;
  }
  if (millis % 1000 < 20) {   // crude 1 Hz beacon
    CAN.beginPacket(0x123);
    CAN.write('R'); CAN.write('4');
    CAN.endPacket;
  }
}

Common mistakes

Autres tutoriels pour cette carte

Exemples de code pour cette carte

← Retour à la fiche 🛠 Tous les tutoriels