Arduino serial communications walkthrough?

Hi all,

I'm trying to get the hang of the communications Arduino uses. There are a lot of terms that get thrown around, and while I think I have my head around most of it, I would really appreciate some sort of walk through. Does anyone know of one that exists?

I'm trying to understand the communication protocols, and interfaces, used to go from USB -> ATmega16U2 -> ATMega328p. I'd also like to know if the ICSP pins are the same pins used from the ATMega16U2 -> MCU, or if that's a different protocol (I'm getting them mixed up). Third, I'm trying to understand how those two differ from the RX/TX serial communication off of pins 0 and 1 on the Uno.

As I said, I have a tenuous grasp on this, but I think I may be confusing some of it, and I'd really like to understand this.

Thanks!

The 16u2 on the Arduino Uno is programmed to act as a straight up USB-serial adapter (on most Arduino clones, the 16u2 is replaced with a non-reprogramable USB-serial adapter, usually a CH340G).

The 16u2 communicates with the '328p over serial (UART) - it's connected to pins 0 and 1 on the '328p (that's why you often have to disconnect things from those pins when uploading sketches). The pin on the 16u2 that's acting as the DTR pin (this is done with a GPIO pin on the 16u2 - dedicated usb serial adapters have a specific DTR pin) is connected to one side of a 0.1uf ceramic capacitor, the other end of it is on the reset pin of the '328p. Thus, when the DTR pin is brought low (and kept there) when the serial connection is opened, reset is pulsed low to start the bootloader (so you can upload a sketch without a precisely timed tap on reset).

Those are the only connections between the 16u2 and the '328p (well, plus power and ground)

The ICSP pins (same pins as SPI, except that reset is used instead of SS) are used for burning the bootloader (and can be used for uploading sketches without the bootloader) - but they are not connected to the 16u2.

Thank you, that helps a lot!

So the bootloader essentially is making it possible for you to upload a sketch via UART, rather than having to use SPI via the ICSP pins?

And, follow up question, I assume UART is hardware enabled on specific pins of the MCU, which are mapped out to Arduino pins 0 and 1? That's why on the Uno, serial can only be carried out on those two pins, but units like the Mega have additional serial connections?

Another Version of Description

Refer to the diagram of the attached file:

  1. We press the RST button of the ArduinoUN. The ATmega328 has gone to boot location
    0x3F00/0x3C00.

There is a small program (known as Boot Loader) beginning from this location;
this program checks:

(a) if there is any incoming code/data (sketch) about to come from the Host Computer for onward
fusing into the application area (application flash) of the MCU;

(b) else, the processor begins of the previously loaded application program.

  1. The User clicks on the Upload command of the Arduino IDE for transferring/fusing a new sketch
    (the application program) into the application flash of the target MCU (ATmega328 of Arduino).

  2. (a) The command, in the form of electrical activities in compliance with USB protocol, goes down to
    the ATmega16U2 chip of the Arduino.

(b) The 16U2 uses its PD7-pin and resets the ATmega328.

(c) The target MCU (ATmega328) goes to Step-1(a) and begins communication (using asynchronous
serial port, Rx/Tx) with 16U2.

  1. (a) 16u2 receives USB signals from the Host Computer and converts it into Asynchronous Serial
    Format (ASF) and vice versa. the ASF signal goes to ATmega328 via Rx/Tx pins.

(b) ATmega32 receives ASF signals from 16U2 and extracts the needed 8-bit information which is
the code/data to be fused in the application flash.

  1. The control remains with Boot Loaded Program until the ATmega32 finishes reception and fusion
    of all the bytes of the incoming sketch (the application program).

  2. Finally, the control goes to the beginning address of the application program.

ASF (1).PDF (94.1 KB)

xtraorange: And, follow up question, I assume UART is hardware enabled on specific pins of the MCU, which are mapped out to Arduino pins 0 and 1? That's why on the Uno, serial can only be carried out on those two pins, but units like the Mega have additional serial connections?

The UART is a piece of hardware (read: a few hundred (thumbsuck) transistors) in the micro and is connected to two pins on that micro to make it available externally. On the Arduino board those two pins (of the micro) are connected to (in case of the 328) pins 0 and 1 (of the board). With the Mega, you have 4 UARTS and each is connected to a set of two pins on the micro which in turn are connected to two pins on the board (0 and 1 for UART0, ...).