🛠 Bus CAN FD : relier deux R4 avec un transceiver externe
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
- 2 Arduino UNO R4 WiFi
- 2 CAN FD transceiver modules (e.g., based on MCP2558FDT or TJA1051 for classic CAN to start — FD requires an FD-compatible transceiver)
- 120 Ω termination resistors at both ends of the bus (many modules include them, check the jumper)
- Wires: CANH↔CANH, CANL↔CANL (never crossed), grounds connected.
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
- Connecting the controller directly to a bus without a transceiver: the RA4M1 does not have the physical layer; without a transceiver, absolutely nothing happens (and you can damage the pin).
- Using a classic CAN transceiver on an FD bus: the 2 Mbit/s data rate passes poorly or not at all; use an FD-compatible transceiver (or force both rates to be identical in CAN 2.0).
- Missing terminations or placed in the middle of the bus: both physical ends must have 120 Ω, not the middle node.
- CANH/CANL crossed on a single node: total silence — this is error #1, check them first.
- Confusing CAN FD and classic CAN regarding bit rates: arbitration and data can have two different bit rates; both nodes must be configured identically.
Other tutorials for this board
- Premier Blink sur la UNO R4 WiFi : la première UNO 32 bits
- Apprivoiser la matrice LED 12x8 intégrée
- Toucher capacitif : touchRead sans composant
- Se connecter au WiFi et lire l'heure NTP (WiFiS3)
- Inclinomètre sur la matrice : l'IMU LSM6DSV16X en I²C
- Serveur web embarqué : piloter la matrice depuis le navigateur
Code examples for this board
clignotante.inoArduinobouton-poussoir.inoArduinodac-analogique.inoArduinoentree-analogique.inoArduinopwm-respiration.inoArduinoservo-balayage.inoArduino