Hardware Reference
In-Depth Information
Making the Connection: The Lower Layers
You're already familiar with one example of serial communication, between a microcon-
troller and a personal computer. In Chapter 1, you connected an Arduino module to a
personal computer through the computer's USB port. If you've worked with a different
microcontroller, such as Parallax's Basic Stamp, you probably made the connection
using a serial-to-USB converter or an older PC that still had a 9-pin RS-232 serial port.
That simple connection involved two serial protocols.
Electrical layer
The signal on Data - is always the polar opposite of what's
on Data+, so the sum of their voltages is always zero.
Because of this, a receiver can check for electrical errors
by adding the two data voltages together. If the sum isn't
zero, the receiver can disregard the signal at that point.
First, there's the protocol that the microcontroller speaks,
called TTL serial :
Physical layer
What pins is the controller using to communicate? The
Arduino module receives data on digital I/O pin 0, and
sends it out on pin 1.
Logical layer
A +5-volt signal (on Data+) or -5-volt signal (on Data-)
represents the value 1, and a 0-volt signal represents the
value 0.
Electrical layer
It uses pulses of 5 volts or 0 volts to represent bits. Some
microcontrollers use 3.3 volts instead of 5 volts.
Logical layer
A high-voltage (5 volt) signal represents the value 1, and a
0-volt signal represents the value 0.
Data layer
The data layer of USB is more complex than TTL serial.
Data can be sent at up to 480 megabits per second. Each
byte contains 8 bits, preceded by a start bit and followed
by a stop bit. Many USB devices can share the same pair
of wires, sending signals at times dictated by the control-
ling PC. This arrangement is called a bus (the B in USB). As
there can be many devices on the same bus, the operating
system gives each one its own unique address, and sees
to it that the bytes from each device on the bus go to the
applications that need them.
Data layer
Data is typically sent at 9600 bits per second. Each byte
contains 8 bits, preceded by a start bit and followed by a
stop bit (which you never have to bother with).
Application layer
At this layer, you sent one byte from the PC to the Arduino
and processed it, and the Arduino sent back one byte to
the PC.
Application layer
At the application layer, the USB-to-Serial converter on the
Arduino boards sends a few bytes to the operating system
to identify itself. The operating system then associates
the hardware with a library of driver software that other
programs can use to access data from the device.
But wait, that's not all that's involved. The 5-volt and 0-volt
pulses didn't go directly to the PC. First, they went to a
serial-to-USB chip on the board that communicates using
TTL serial on one side, and USB on the other.
Second, there's USB, the Universal Serial Bus protocol.
It differs from TTL serial in many ways:
All that control is transparent to you because the computer's
USB controller only passes you the bytes you need. The
USB-to-Serial chip on your Arduino board presents itself
to the operating system as a serial port, and it sends data
through the USB connection at the rate you choose (9600
bits per second in the example in Chapter 1).
Physical layer
USB sends data on two wires, Data+ and Data-. Every
USB connector also has a 5-volt power supply line and a
ground line.
Search WWH ::




Custom Search