Microprocessors & Interfacing
Total Page:16
File Type:pdf, Size:1020Kb
Lecture Overview Microprocessors & Interfacing • Serial Communication – Concepts – Standards • USART in AVR Serial Input/Output Lecturer : Dr. Annie Guo S2, 2008 COMP9032 Week10 1 S2, 2008 COMP9032 Week10 2 Serial Communication System Why Serial I/O? Structure • Problems with Parallel I/O: – Needs a wire for each bit. Data From Source Data To Destination – When the source and destination are more than a n n few feet the parallel cable can be bulky and expensive. Transmit Data Received Data Buffer Buffer – Susceptible to reflections and induced noises for long distance communication. Serial Data R Tclock Parallel In/Serial Serial In/Parallel clock • Serial I/O overcomes these problems. Out Shift Register Out Shift Register TRANSMITTER RECEIVER S2, 2008 COMP9032 Week10 3 S2, 2008 COMP9032 Week10 4 Serial Communication System Serial Communication System Structure (cont.) Structure (cont.) • At the communication source: • At the communication destination: – The parallel interface transfers data from the –Rclock shifts each bit received into the Serial In source to the transmit data buffer. Parallel Out (SIPO) register. – The data is loaded into the Parallel In Serial Out – After all data bits have been shifted in, they are (PISO) register and Tclock shifts the data bits out transferred to the received data buffer. from the shift register to the receiver. – The data in the received data buffer can be read by an input operation via the parallel interface. S2, 2008 COMP9032 Week10 5 S2, 2008 COMP9032 Week10 6 Serial Communication Synchronous VS Asynchronous • There are two basic types of serial • Synchronous communications – Transmitter and receiver are synchronized – synchronous • Need extra hardware for clock synchronization – asynchronous – Having faster data transfer rate • Asynchronous – Transmitter and receiver use different clocks. No clock synchronization is required. – Used in many applications such as keyboards, mice, modems – The rest of this lecture focuses on Asynchronous communication S2, 2008 COMP9032 Week10 7 S2, 2008 COMP9032 Week10 8 UART UART Structure • The device that implements both transmitter and receiver in a single integrated circuit is called a UART (Universal Asynchronous Receiver/Transmitter). • UART uses least significant first order Tclock1 Rclock2 Transmitter Receiver – The least significant bit of data is transferred first Data Bus Data Bus • Data are transmitted asynchronously. Rclock1 Tclock2 – Clocks on both sides are not synchronized Receiver Transmitter – But receivers have a way to synchronise the data receiving operation with data transmission operation • UART is the basis for most serial communication UART UART hardware. S2, 2008 COMP9032 Week10 9 S2, 2008 COMP9032 Week10 10 UART Data Formats UART Data Formats (cont.) • Before transmission, data should be encoded • Typical bits in data transmission: – Many encoding schemes, such as ASCII – Start bit: When the transmitter has data to send, it first changes the line from the mark to the space level for one bit • Each encoded data is encapsulated with two bits time. This synchronises the receiver with transmitter. When – Start bit and stop bit the receiver detects the start bit, it knows to start clocking in the serial data bits. • Mark and space : the logic one and zero levels are – Data bits: representing a data, such as a character called mark and space. – Parity bit: used to detect errors in the data – When the transmitter is not sending anything, it holds the • For odd parity: the bit makes the total number of 1s in the data line at mark level, also called idle level. odd Optional Stop • For even parity: the bit makes the total number of 1s in the data Least Significant even. Parity Bit Bit Bit – Stop bit: added at the end of data bits. It gives one bit-time Mark between successive data. Some systems require more than one stop bit. Space Start Data Bits S2, 2008Bit COMP9032 Week10 11 S2, 2008 COMP9032 Week10 12 Data Transmission Rate Communication System Types • The rate at which bits are transmitted is called • Three ways that data can be sent in serial baud rate . communication system: • It is given in bits per second – Simplex system • Standard data rates – Baud: – Full-duplex (FDX) system 110, 150, 300, 600, 900, 1200, 2400, 4800, 9600, – Half-duplex (HDX) system 14400, 19200, 38400, 57800 S2, 2008 COMP9032 Week10 13 S2, 2008 COMP9032 Week10 14 Simplex System Full-Duplex (FDX) System – Data are sent in one direction only – Data are transmitted in two directions. • For example, computer to a serial printer. – It is called four-wire system, although only two – Simple signal wires and a common ground are sufficient. • If the computer does not send data faster than the printer can accept it, no handshaking signals are required. – Two signal wires are needed for this system. Terminal Computer Computer Printer S2, 2008 COMP9032 Week10 15 S2, 2008 COMP9032 Week10 16 Standards for the Serial I/O Half-Duplex (HDX) System Interface – Data are transmitted in two directions with only • Interface standards are needed to allow one pair of signal lines. different manufacturers’ equipment to be – Additional hardware and handshaking signals interconnected must be added to an HDX system. • Must define the following elements: – Handshaking signals – Direction of data flow Computer Computer – Types of communication devices. – Connectors and interface mechanical considerations. – Electrical signal levels. S2, 2008 COMP9032 Week10 17 S2, 2008 COMP9032 Week10 18 Standards for the Serial I/O Two RS232-C Connectors Interface (cont.) • Popular standards include RS-232-C, RS- 422, RS-423 and RS-485. – RS-232-C standard is used in most serial interface. – If the signals must be transmitted farther than 50 feet or greater than 20 Kbits/second, another DE9 pin assignments electrical interface standard such as RS-422, RS- 423 or RS-485 should be chosen. – For RS-422, RS-423 and RS-485, handshaking, direction of signal flow, and the types of communication devices are based on the RS-232- C standard. DB25 pin assignments S2, 2008 COMP9032 Week10 19 S2, 2008 COMP9032 Week10 20 RS-232-C Signal Definitions RS-232-C Signal Definitions (cont.) DE9 DB25 Signal Purpose DE9 DB25 Signal Purpose 1 PG Protective ground : this is actually the shield 8 5 CTS Clear to send : Sourced by DCE, received in a shielded cable. It is designed to be by DTE. CTS must be asserted before the connected to the equipment frame and may DTE can transmit data. be connected to external grounds. 3 2 TxD Transmitted data : Sourced by DTE and 6 6 DSR Data set ready : Sourced by DCE and received by DCE. Data terminal equipment received by DTE. Indicates that the DCE cannot send unless RTS, CTS, DSR and has made a connection on the telephone DTR are asserted. line and is ready to receive data from the terminal. The DTE must see this asserted 2 3 RxD Received data : Received by DTE, sourced before it can transmit data. by DCE. 7 4 RTS Request to send : Sourced by DTE, received 5 7 SG Signal ground : Ground reference for this by DCE. RTS is asserted by the DTE when signal is separate from pin 1, protective it wants to send data. The DCE responds by ground. asserting CTS. S2, 2008 COMP9032 Week10 21 S2, 2008 COMP9032 Week10 22 RS-232-C Signal Definitions (cont.) RS-232-C Interconnections DE9 DB25 Signal Purpose • When two serial ports are connected, the data rate, the number of data bits, whether parity is used, the 1 8 DCD Data carrier detect : Sourced by DCE, type of parity, and the number of stop bits must be received by DTE. Indicates that a DCE has set properly and identically on each UART . detected the carrier on the telephone line. Originally it was used in half-duplex • Proper cables must be used. There are four kinds of systems but can be used in full-duplex cables from which to choose, depending on the types systems, too. of devices to be interconnected. 4 20 DTR Data terminal ready : Sourced by DTE and – Full DTE – DCE cable received by DCE. Indicates that DTE is – Minimal DTE – DCE cable ready to send or receive data. – DTE – DTE null modem cable 9 22 RI Ring indicator : Sourced by DCE and – Minimal null modem cable received by DTE. Indicates that a ringing signal is detected. S2, 2008 COMP9032 Week10 23 S2, 2008 COMP9032 Week10 24 RS-232-C Interconnections (cont.) RS-232-C Interconnections (cont.) DE9 DB25 DB25 DE9 DE9 DB25 DB25 DE9 DTE DTE DCE DCE DTE DTE DCE DCE TxD 3 2 2 3 TxD TxD 3 2 2 3 TxD RxD 2 3 3 2 RxD RxD 2 3 3 2 RxD SG 5 7 7 5 SG SG 5 7 7 5 SG RTS 7 4 4 7 RTS RTS 7 4 4 7 RTS CTS 8 5 5 8 CTS CTS 8 5 5 8 CTS DCD 1 8 8 1 DCD DCD 1 8 8 1 DCD DSR 6 6 6 6 DSR DSR 6 6 6 6 DSR DTR 4 20 20 4 DTR DTR 4 20 20 4 DTR Full DTE – DCE cable Minimal DTE-DCE cable S2, 2008 COMP9032 Week10 25 S2, 2008 COMP9032 Week10 26 RS-232-C Interconnections (cont.) RS-232-C Interconnections (cont.) DE9 DB25 DB25 DE9 DE9 DB25 DB25 DE9 DTE DTE DTE DTE DTE DTE DTE DTE TxD 3 2 2 3 TxD TxD 3 2 2 3 TxD RxD 2 3 3 2 RxD RxD 2 3 3 2 RxD SG 5 7 7 5 SG SG 5 7 7 5 SG RTS 7 4 4 7 RTS RTS 7 4 4 7 RTS CTS 8 5 5 8 CTS CTS 8 5 5 8 CTS DCD 1 8 8 1 DCD DCD 1 8 8 1 DCD DSR 6 6 6 6 DSR DSR 6 6 6 6 DSR DTR 4 20 20 4 DTR DTR 4 20 20 4 DTR DTE – DTE null modem cable Minimal null modem cable S2, 2008 COMP9032 Week10 27 S2, 2008 COMP9032 Week10 28 RS-232-C Interface RS-423 Standard • Also a single ended system.