Powerpoint - HelloSam.Net
Download
Report
Transcript Powerpoint - HelloSam.Net
Robocon 2007
Electronics Quickstart!
Session 4
Communication
Prepared by
KI Chi Keung [chikeung@ust.hk]
WONG Long Sing (Sam) [sam@hellosam.net]
Robocon 2007, Hong Kong University of Science & Technology
Today’s Timeline
1.
2.
3.
4.
Communication Process
Layers of Communication
Implementation
RS232 / UART in-depth
Robocon 2007, HKUST
Communication Process
• How communication can be done?
Robocon 2007, HKUST
Parallel Communication
• At least, consist of a Data bus and a clock line
• Data line is mapped bit by bit. A Natural
expansion of CPU/MCU design.
• Example
–
–
–
–
–
–
LCD
Parallel Port
(Parallel) ATA
Floppy
SDRAM (Synchronous Dynamic Random Access Memory)
PCI Bus
Robocon 2007, HKUST
Parallel Communication
• Timing Diagram
Data
Data
Data
Data Stable
Data Stable
Synchronization
Synchronization
Clock
Robocon 2007, HKUST
Serial Communication
• Only need one data line only
• No explicit clock. Either embedded or
synchronized from time to time
• Example
–
–
–
–
–
UART
PS/2 Keyboard, Playstation Controller
USB
Ethernet
PCI Express Bus
Robocon 2007, HKUST
Serial Communication
• Timing Diagram
Data Transmitted at agreed rate
Data
Synchronization
Robocon 2007, HKUST
Bus Idle
Comparison
Serial bus is more complex and harder to
implement in nature
Parallel bus require synchronization to
slowest data line
Electrical parallel bus suffers from crosstalk
Parallel bus occupies more real estate
Robocon 2007, HKUST
CM
SS
CS
RE
Layers of Communication
• Communication, or data exchange, is a
complicated process.
• It is usually taught and understood in layers.
• OSI model describes 7 Layers
• We will focus on 3 of the 7 layers which do us
good
– Physical Layer (Layer 1)
– Data Link Layer (Layer 2)
– Application Layer (Layer 7)
Robocon 2007, HKUST
Layers of Communication
• A layer can rely on the functionality of
immediate bottom layer to facility data
exchange
• A layer is only responsible to service the
immediate upper layer
• If everything is well defined
– application can communication with application almost
without any knowledge of any bottom layer
– Layers can be interchanged
Robocon 2007, HKUST
Layers of Communication
• Application Layer (7)
– Human, Computer Application (Web, FTP, Email…)
• Many other layers (6..3)
– Human Language
– TCP / UDP / IP / Part of USB / Part of I2C…
• Data Link Layer (2)
– Human Speaking usual practice
– Ethernet’s Carrier sense multiple access with collision avoidance
(CSMA-CA) / detection (CSMA-CD)
• Physical Layer (1)
– Wired (Telephone, Modem, LAN)
– Wireless (Cell phone, Wifi)
– Sound wave (Talking, Voice Playback and Recognition)
Robocon 2007, HKUST
Physical Layer
• Describe the physical property of the
communication channel.
– Media
• Copper / Optical Fiber / Ultrasound / IR
– Meaning of Voltage / Brightness
– Modulation
• Base band / FM / AM / UHF / TDMA / OFDM
– Serial or Parallel
– Connectors
Robocon 2007, HKUST
Physical Layer
• Human voiced communication
– Media
• Air
– Meaning of Voltage / Brightness
• Loudness
– Modulation
• Longitudinal sound wave
– Serial or Parallel
• Serial
– “Connector”
• Ear and mouth
Robocon 2007, HKUST
Physical Layer
• Serial Port / RS-232
– Media
• Copper Wire
– Meaning of Voltage / Brightness
• -5V to -12V for 1 (Space), +5V to +12V for 0 (Mark)
– Modulation
• Base band
– Serial or Parallel
• Serial
– “Connector”
• Commonly seen as DB 9 Male / Female
Robocon 2007, HKUST
Data link Layer
• How the data link is established,
understood and maintain
– Master (Transmitter) / Slave (Receiver) relationship
• Or multi-hops?
– Bus sharing / arbitration
• Shared? Who has higher priority?
• CSMA/CD, CSMA/CA
– Clock rate / Order
– Acknowledgement / Error detection / Error correction
Robocon 2007, HKUST
Data link Layer
• Human voiced communication
– Master (Transmitter) / Slave (Receiver) relationship
• Single master, many slaves
– Bus sharing / arbitration
• Generally speaking, only one person talking each time. Also, the one
who speaks louder win. Also handled by upper layer (in-band or outof-band)
– Clock rate / Order
• “Reasonable” speaking speed, could be adjusted by urgency,
required attention
• Order? That really depends.
– Acknowledgement / Error detection / Error correction
• Not defined in this layer
Robocon 2007, HKUST
Data link Layer
• RS232 / UART
– Master (Transmitter) / Slave (Receiver) relationship
• Single master, many slaves
– Bus sharing / arbitration
• For each data link, the master will always be master. No sharing and
arbitration is needed.
– Clock rate / Order
• Agreed Baud rate. Commonly seen from 9600 to 115200
• Transmit LSB first, then MSB
– Acknowledgement / Error detection / Error correction
• Start / Stop bit for time frame checking. Optional parity bit for error
detection.
• Others are not defined in this layer.
Robocon 2007, HKUST
Application Layer
• Implement what you want! It’s application
dependent.
• It may implement some functions not
implemented by lower layer.
Robocon 2007, HKUST
Application Layer
• Human voiced communication
– Protocol is application dependent
• Boss ordering employees
• Conference with project partners
• Chitchat with friends
– Acknowledgement, Error checking, Error Correction
• In-band - “Would you repeat that please?”, “Did you mean
XXX?”
• Out-of-band - Waving the head, body gestures
• Undefined - As in teaching. I never know if you can receive
what I am talking about or not.
Robocon 2007, HKUST
Application Layer
• RS232 / UART
– Protocol is application dependent
• Binary?
• Text?
– Acknowledgement, Error checking, Error Correction
• In-band - Dedicate special characters as control character.
e.g. ASCII, XON/XOFF.
• Out-of-band - Use GPIO lines as control line
• Undefined - Simple ignore it! e.g. Data transmission occurs in
continuous fashion frequently anyway, like temperature
monitoring. (Or think video streaming from the Internet /
webcam)
Robocon 2007, HKUST
Implementation – Physical Layer
• If the definition is to use the basic 0-5V,
GPIO capable, then you probably don’t
need extra hardware.
– Exception: when you want to have electrical
separation with a noisy hostile circuit
• Otherwise you need transceiver
– Like phone-receiver for voiced communication
– Laser and Diode for optical fiber
Robocon 2007, HKUST
Implementation – Data Link Layer
• Either use specialized hardware interfacing
module
– Provided by microcontroller
– Or an external hardware, usually an IC with transceiver
embedded. Think of USB controller chip
• Or software defined (code it in application)
– In fact everything not fall onto physical layer can be implemented
by application code, given your CPU processing power is fast
enough.
• If you go extreme, see GNU Radio project, which demodulate (No
tuner, just Fourier transform!) the HDTV signal with CPU.
– Using software defined communication technique on serial
communication is called Bit-Banging
Robocon 2007, HKUST
Implementation – Application Layer
• Show me your code!
Robocon 2007, HKUST
RS232 / UART in-depth
• Physical Layer - Transceiver
– MAX232 by Maxim IC (Unrelated to Maxim's Catering)
• Data link
– Handled by the UART module on ATMega128
• Application
– By using the registers and optionally interrupt
Robocon 2007, HKUST
RS232 / UART in-depth
• Cable and Connector – Use your USB-toCOM cable
• Voltage conversion is taken care by
MAX232
• UART voltage is 5V (1, Space, Idle) and
0V (0, Mark, Engaged)
• RS232 voltage is ~-8V (1, Space, Idle) and
~+8V (0, Mark, Engaged)
Robocon 2007, HKUST
RS232 / UART in-depth
• Required setting
– Baud rate
– Data size
• And read the specification for more!
Robocon 2007, HKUST
RS232 / UART in-depth
• Task 1
– Send some character to your computer
• Task 2
– Store a line echo back to the computer
Robocon 2007, HKUST