🛠 Monter la Due sur un bus CAN 500 kbit/s avec un transceiver externe

Arduino Due · avance · Schéma : IMG-due-avance-1-can-bus-500k-due-can.svg — signaux CAN0 (broches 68 RX / 69 TX) de l'Arduino Due reliés à un module transceiver CAN 3,3 V (TJA1050/SN65HVD230) connecté au bus CAN_H/CAN_L avec résistance de terminaison 120 Ω, mention « transceiver externe requis ».

Objectives

The SAM3X8E chip integrates TWO CAN controllers — the flagship feature of the Due for automotive and industrial applications — but the official datasheet is clear: “CAN: Yes (ext. transceiver needed)”. No transceiver is soldered onto the board. This tutorial sets up a 500 kbit/s CAN link using the due_can community library (collin80) and a small 3.3 V transceiver module, then sends and receives frames.

Hardware

Complete Code

// Emetteur CAN0 a 500 kbit/s — transceiver externe obligatoire
#include <due_can.h>

void setup {
  SerialUSB.begin(115200);
  Can0.begin(CAN_500KBPS);        // CAN0 @ 500 kbit/s
  SerialUSB.println("CAN0 pret (500 kbit/s)");
}

void loop {
  // 1) Emission periodique
  can_frame tx;
  tx.canId = 0x123;
  tx.canIdLength = ONE_BIT;
  tx.dataLength = 8;
  uint32_t t = millis;
  for (int i = 0; i < 8; i++) tx.data[i] = (t >> (i * 8)) & 0xFF;
  Can0.sendMessage(tx);           // non bloquant

  // 2) Reception eventuelle
  can_frame rx;
  if (Can0.getMessage(rx)) {
    SerialUSB.printf("Rx id=0x%X len=%u\n", rx.canId, rx.dataLength);
  }
  delay(10);
}

Expected Verification

With a second node (another Due or a USB-CAN adapter configured at 500 kbit/s), frames with ID 0x123, 8 bytes, containing millis in little-endian format, appear every 10 ms. On the USB-CAN adapter: candump displays 0123 [8] ... with an increasing counter. The two TX/RX LEDs on the transceiver blink.

Common Errors

Other tutorials for this board

Code examples for this board

← Back to the board 🛠 All tutorials