140 likes | 264 Views
Serial Communications. Sending and receiving data between devices. Serial Communications describes a general way in which two devices can send or receive data from one another. To send or receive data, bits have to be moved around
E N D
Serial Communications Sending and receiving data between devices CE-2810 Dr. Mark L. Hornick
Serial Communications describes a general way in which two devices can send or receive data from one another To send or receive data, bits have to be moved around The term Serialindicates that the data bits are transmitted sequentially, one bit at a time Conversely, in parallel communication, multiple bits are transmitted simultaneously CE-2810 Dr. Mark L. Hornick
The physical signaling of serial data takes many forms • USB (Universal Serial Bus) • Firewire • Bluetooth • IR • Ethernet • RS-232 • RS-422 • RS-485 • WiFi CS-280 Dr. Mark L. Hornick
Atmel Atmega32USART Subsystem CS-280 Dr. Mark L. Hornick
USART overlaps PortD pins • RXD pin is used to receive serial data • Enabling the USART receiver overrides PD0 function • TXD pin is used to transmit serial data • Enabling the USART transmitter overrides PD1 function CE-2810 Dr. Mark L. Hornick
RS-232 on the SunRom board • The SunRom board includes a RS-232 converter chip that converts the low-level signals of TXD/RXD to RS-232 voltages • TXD/RXD: 0 to +5v • RS-232: -15 to +15v • The converter chipinterfaces theAtmega32 to the 15-pin D-shell connector CE-2810 Dr. Mark L. Hornick
TTL vs RS-232 voltage levels • TTL (transistor logic) signals • v < 2 = logical 0 • v > 3 = logical 1 • 2 < v < 3 = undefined • RS-232 signals • -15 < v < -3 = logical 1 • +3 < v < +15 = logical 0 • -3 < v < +3 = undefined Note that logic values appear to be inverted if RS-232 signals are viewed on an oscilloscope CS-280 Dr. Mark L. Hornick
Only 3 lines on the 15-pin connector are used for RS-232; Tx(2), Rx(3), and Ground(5) CS-280 Dr. Mark L. Hornick
Connection between two communicating serial devices The Tx (transmit) line of one device is connected to the Rx (receive) line of the second device Tx Tx Rx Rx CS-280 Dr. Mark L. Hornick
Asynchronous vs Synchronous • In synchronous communications, the two communicating devices must keep their respective clock signals synchronized • Even when no data is being sent, the two devices continuously exchange “sync” characters • In asynchronous communications, the two devices maintain their own clocks • Nothing is transmitted when there is nothing to send • But a “handshake” has to be established whenever data needs to be transmitted – extra overhead The USART subsystem of the Atmega32 supports bothmodes, but we’ll only use the asynchronous mode. CE-2810 Dr. Mark L. Hornick
Asynchronous transmission of a byte of data • Each byte of data is surrounded by “framing” bits, inserted by the USART LSB MSB 5,6,7,8, or 9 data bits Parity bit can be disabled (no parity bit) 1 or 2 stop bits CS-280 Dr. Mark L. Hornick
The Parity bit is an error checking mechanism used to detect data corruption Equal to 1 if the number of non-zero data bits is odd,(#data bits + parity bit = even number of bits) Equal to 1 if the number of non-zero data bits is even, (#data bits + parity bit = odd number of bits) The Parity is computed first on the transmitting end, and included as the Parity bit in the frame. The Parity is then recomputed on the receiving end, and the result is compared to the Parity bit value. If the Parity calculation on the receiving end does not match, the receiver knows data corruption occurred.This allows errors to be DETECTED, but does not provide a means of CORRECTION. CS-280 Dr. Mark L. Hornick
RS-232 signal transmission of the letter ‘K’ (ASCII 0x4C) CS-280 Dr. Mark L. Hornick
Speed metrics • The speed of serial transmission is usually measured in bits-per-second • This is called the baud rate • Because of the overhead bits used in each frame, 2400 baud is NOT the same as 300 characters per second • Since each character takes >8 bits to transmit • The Atmega32 USART can be configured to operate between 2400 and 1M baud CS-280 Dr. Mark L. Hornick