can-boucle.ino
The GIGA's industrial DNA: its FDCAN wired to a dedicated connector. Two GIGAs linked (CANH/CANL + ground, 120 Ω at the ends) swap frames at 500 kbit/s — automation starts here.
Hardware required
An Arduino Giga R1 board (STM32H747 dual-core M7 at 480 MHz + M4, 76 I/O pins, 2 DACs, FDCAN) powered over USB-C or 5-24 V. 2 boards with CAN transceivers (or a USB-CAN adapter) + 120 Ω resistor.
Wiring
CANTX/CANR/GND on the MCU side: you NEED an SN65HVD230 transceiver between board and bus. CANH-CANH, CANL-CANL, common grounds, 120 Ω at both ends.
How it works
CAN.begin arms the FDCAN at 500 kbit/s; beginPacket/endPacket encapsulates the standard 11-bit frame. onReceive fires on interrupt per received frame. In the Arduino IDE, install the « Arduino Zephyr-based Boards » (or Mbed) platform, select « Arduino Giga R1 », then Upload. 3.3 V logic.
Going further
A home-brew protocol (ID = sensor, data = 4-byte float), or a bus to a CAN stepper driver.
can-boucle.ino
// CAN sur le connecteur CANTX/CANR/GND de la GIGA (pas de transceiver !).
// Relier CANH a CANH, CANL a CANL avec une autre carte, terminaison 120 ohms.
#include <CAN.h>
void setup() {
Serial.begin(115200);
if (!CAN.begin(500000)) {
Serial.println("FDCAN indisponible ?"); for (;;);
}
CAN.onReceive([](int packetSize) {
uint32_t id = CAN.packetId();
while (CAN.available())
Serial.printf("<%03X> %02X ", id, CAN.read());
Serial.println();
});
Serial.println("CAN 500 kbit/s pret");
}
void loop() {
static unsigned long precedent = 0;
if (millis() - precedent >= 1000) {
precedent = millis();
CAN.beginPacket(0x123);
CAN.write((uint8_t)(millis() & 0xFF)); // trame 1 octet
CAN.endPacket();
Serial.println("> 0x123 envoye");
}
}