usb-native.ino

Arduino Due · File : usb-native.ino · Language : Arduino · Use case : Utiliser le port USB Native pour un second port série indépendant

The Due has two USB connectors: Programming (16U2 bridge) and Native, wired straight to the SAM3X. SerialUSB is a second serial port, and while(!SerialUSB) prevents losing boot messages.

Hardware required

An Arduino Due (AT91SAM3X8E, ARM Cortex-M3 at 84 MHz) connected over USB to its « Programming » port. Caution: 3.3 V logic, never 5 V on the pins. A second USB cable (or the same PC with two ports).

Wiring

USB cable from the Native port to the computer; the Programming port can stay plugged.

How it works

The SAM3X enumerates a CDC device; SerialUSB.print writes to it. With no terminal open the wait blocks — hence the while. In the Arduino IDE, select « Arduino Due (Programming Port) » then Upload; the serial monitor runs at the speed set in the code.

Going further

Native also hosts the DFU bootloader and USB ↔ other-UART bridges for instruments.

usb-native.ino

// Le SAM3X possede un USB device natif : SerialUSB = port "Native".
// Sur le port Native, il faut attendre l'ouverture du terminal.

void setup() {
  Serial.begin(9600);      // port Programming (ATmega16U2)
  SerialUSB.begin(9600);   // port Native (SAM3X direct)
  while (!SerialUSB);      // attend qu'un terminal ouvre le port Native
}

void loop() {
  SerialUSB.println(F("Bonjour depuis l'USB natif"));
  Serial.println(F("Idem depuis le port Programming"));
  if (SerialUSB.available()) {
    Serial.write(SerialUSB.read()); // Native -> Programming
  }
  delay(1000);
}

← Back to the board