Download presentation
Presentation is loading. Please wait.
Published byOliver Lindsey Modified over 9 years ago
1
Computer communication
2
Introduction Mechanisms applied in communicating between a computer and another computer or with other devices. Mainly serial (bit by bit) while in the I/O interface section, we have already studied the parallel communication (byte-wise) Serial Communication and the Universal Serial Bus (USB) are the most commonly used. A brief discussion will be given
3
Serial communication Serial communication is used for connecting peripheral units, such as display, modems, to a microcomputer Serial communication is a one-to-one communication, ie. only one device is connected to the communication interface Data (8-bit) is exchanged in a bit-by-bit manner or serially Only 3 wires (send, receive, and ground) to setup a communication link between two devices For serial communication, there are two types of transfer mode – asynchronous and synchronous
4
Serial communication Synchronous – requires a clock signal to synchronize the transmitter and the receiver Asynchronous communication, without a common clock, uses pre- defined protocol to achieve the data transfer
5
Asynchronous communication Data transfer is not sent in predefined time slots because there is no common clock. Data transfer can start at any given time The hardware connector for asynchronous communication is the RS232 connector. The setup in the lab-session, the connection between the PC and the ADuC832 board is via asynchronous communication.
6
Asynchronous communication Interface consists of receive data, transmit data, and signal common (no common clock) Data are sent one character at a time (the data bit varies in different systems, but usually either 7, or 8 bits are used) Both receiver and transmitter must agree on the number of data bits, as well as the baud rate (bits per second to be transmitted) Receiver examines synchronization bits that are included at the beginning and end of each character Start bit, parity bit and stop bit are used for synchronization
7
Asynchronous communication
8
Data bits are sent with a predefined frequency - baud rate. Both the transmitter and receiver must use the same bit frequency. If the transmitter is sending at 9600 baud but the receiver is running at 19600 baud then every bit sent by the transmitter will equal to 2 bits at the receiver side!!!!! After the first bit (the start bit) is received, the receiver calculates at which moments the other data bits will be received. It will check the line voltage levels for the stop bit (a ‘1’) at those moments.
9
Example For example, if the receiver gets the first bit at time X, and the pre-defined transfer rate is 9600 baud, 8-bit per character and 1 stop bit, no parity then the stop bit should be received at X+0.9375ms (9x 1/9600).
10
Asynchronous communication operation sequence 1.A start bit is sent first – a ‘0’. Since the communication line is kept at ‘1’ when there is no data so a 1->0 transition in the line will indicate a possible start bit 2.The data bits follow the start bit 3.A stop bit is sent (stop bit has a value of ‘1’) 4.The stop bit can be detected correctly even if the previous data bit also had a value of 1, due to timing as stated previously. 5.Stop bits can be 1, 1.5, or 2 bit periods in length.
11
Operation sequence 1.The parity bit is optional. A parity bit affords a small amount of error checking, to help detect data corruption that might occur during transmission 2.Either even or odd parity can be used
12
Parity bit for error checking Parity could be even or odd When even parity is chosen, the parity bit is transmitted with a value of ‘0’ if the number of preceding `1` is an even number (i.e including the parity bit, the total data bits sent have a even number of ‘1’ if even parity is used). Even parity => no. of ‘1’ in data + parity bit = even ODD parity => no. of ‘1’ in data + parity bit = odd
13
Parity for error checking Example If the data is 10101101 (with 5 1s – odd) using even parity then the parity bit is ‘1’ so the total number of ‘1’ sent is even. However, if odd parity is used then the parity bit is ‘0’ so total number of ‘1’ sent is ODD.
14
Parity bit If the original data is 10111001 now if odd parity is used then the parity bit is ‘0’ so data being sent is 1 0 1011 1001 0 if the received data is 1 0 1111 1001 0 then comparing the received data and the parity bit “0” then you can detect possible error in the data and resending the data if necessary. But if the received data is 1001 0001 then comparing to the parity then no error can be detected. So parity bit is not a very useful technique to detect communication errors and usually not included in the data stream in order to reduce overhead
15
Configure the serial communication port under WindowsXP
16
Question A device is connected to a computer via a serial asynchronous communication link (RS232). If the device can transmit 800 characters per second. What is the possible setting of the communication port? –The baud rate is 9600, with 1 stop bit and no parity –The baud rate is 19600, with 2 stop bit and 2 parity bits –The baud rate is 9600, with 2 stop bit and 1 parity –The baud rate is 4800, with 1 stop bit and no parity
17
Serial communication Serial communication is character based You send ASCII characters not values So if you want to send 101 then you need to convert the value 101 into ‘1’’0’’1’ three characters The values being sent are 49 48 49 49 = ASCII of 1; 48 = ASCII of 0 At the receiving end, you need to convert the string back to value
18
Different kinds of communication links Simplex communication link – with one communication link and for a single direction Half-duplex – data are transmitted and received over the same line, and transmission and reception cannot take place at the same time Full duplex – with separate transmit and receive lines. Data can be transferred in both directions at the same time
19
The physical connection The serial data interface for a PC is usually via the RS232C connector. RS-232 - Recommend Standard number 232 and C is the latest revision of the standard. The serial ports on most computers use a subset of the RS-232C standard. The full RS-232C standard specifies a 25-pin "D" connector of which 22 pins are used. Most of these pins are not needed for normal PC communications, and indeed, most new PCs are equipped with male D type connectors having only 9 pins.
20
R2232C 1.Incoming signal 2.Incoming data 3.Outgoing data 4.DTR 5.Ground 6.DSR 7.RTS 8.CTS 9.Ring indicator Pin 1 and 9 are only available in Connection to a modem
21
RS232 The voltage level used to represent a ‘0’ (also called a space) is +5 to +15 for transmitter, and +3 to +25 for receiver. The voltage level for ‘1’ (or mark) is -5 to -15 on the transmitter and -3 to -25 on the receiver. The maximum transfer rate is 1.5Mbps. The maximum cable length is 50 feet. A device (such as the MAX232) is used to convert the voltage level from 0V and 5V to the +V to –V used by the RS232 standard.
22
Hardware configuration UART built-in
23
Applications PC ADuC832 Motor Using a PC to control a motor can be done via a ADuC832 PC talks to ADuC832 via the serial communication ADuC832 control the motor using Ports (just like the lab exercise) RS232 Communication is via the RS232 so PC sends characters to the ADuC832 PC may send a ‘1’’0’ to represent 10% duty cycle
24
USB to serial converter Modern computer (especially notebook) has only USB Connectors A USB to serial converter can convert the USB signal to RS232 signal so traditional serial communication techniques can still applied.
25
Universal Serial Bus (USB) The most popular interface between a computer and external devices in modern computer system Provides low to medium speed serial interface It is a bus – many devices can attach to the bus at the same time but RS232 is a one-to-one connection
26
Basic USB 2.0 Support three different communication speed: High-speed (480 Mb/s), full-speed (12Mbit/s) low-speed (1.5 Mb/s). Cable lengths are limited to 5 meters maximum for full-speed and 3 meters maximum for low-speed interface The USB uses a tiered star topology The supported devices are connected to the system host via nodes on USB hubs
27
USB connection Universal Serial Bus Many devices can connect to the bus at the same time
28
USB hub architecture Root hub
29
Basic USB Each device in a USB system is assigned an unique address when first attached to the bus. This process is called bus enumeration. As many as 127 different devices can be accommodated. When a USB device is first attached to a hub, the host assigns it with an address and establishes a connection between itself and the device. The characteristics of this connection provide speed, direction, required bandwidth, error-handling requirements, transfer type, maximum packet size. All these are referred to as a pipe.
30
USB connector There are 4-pin on the connector USB devices can be powered directly from the USB connection as long as the current drawn is less than 100mA per device The receiver defines a differential ‘1’ as D+ 200mV greater than D- and a differential ‘0’ as D+ 200mV less than D-. This is called bi-phase
31
USB connector PinSignal 15.0V 2-Data 3+Data 4Ground Type B connector +D > -D 200mv then it is a ‘1’ +D< -D 200mV then it is a ‘0’
32
USB data For RS232, there are the start bit, stop bit In USB, data transfer is more complicated and there are encoding as well as error detection, data are sent in packet Encoding - NRZI (non-return to zero inverted) data encoding for transmitting packets of data
33
NRZI NRZI – ‘1’ is represented by no change in signal level and ‘0’ is represented by a change in level. Example - a string of ‘0’ causes the NRZI data toggle at each bit time, while a string of ‘1’ causes long period with no transition in the data. When a logic 1 is transmitted for six bits in a row a sync bit is added. This is called bit- stuffing The sync bit is a logic 0
34
NRZI Example: assume idle state is ‘1’ Data: 1101001100010 NRZI : 11100100010110 Data are always transmitted beginning with the LSB first, followed by subsequent bits Data 1101001100010 11100100010110
35
NRZI Example –1001010100011 (assume idle is ‘1’) –Result 11011001101000 –0001111111101 (assume idle is ‘0’) –Result 010111111011100 Stuff bit
36
Flow chart for NRZI Data being sent
37
USB data communication USB is a one to many connection so the data transmitted is more complicated To begin communication, a sync byte (80H) is transmitted first, followed by the packet identification byte (PID) Packet contains many bytes of data but in RS232 it is character (8-bit) based The PID contains 8 bits, the rightmost 4 bits contain the type of packet that follows, if any. The left most 4 bits are complementing the rightmost 4 bits and this help detecting errors. Example: if 1000 is sent then PID is 0111 1000.
38
Packet format
39
USB packet Token, Start of Frame, Data, Handshake – are packet types Only the host can issue the token packet and the token packet will determine action to be taken in the subsequent transmission. Handshake signals are employed in order to secure the data communication.
40
PID codes PIDNameTypeDescription E1HOUTTokenHost -> function transaction D2HACKHandshakeReceiver accepts packet C3HData0DataData packet PID even A5HSOFTokenStart of frame 69HINTokenFunction -> host transaction 5AHNAKHandshakeReceiver does not accept data 4BHData1DataData packet PID odd 3CHPRESpecialHost preamble 2DHSetupTokenSetup command 1EHStallTokenStalled
41
Packet format
42
CRC –cyclic redundancy checks CRC is used for error detection A transmitted bit stream (M-bit) is appended with a n-bit FCS (frame check sequence) so that the result, the cascading, (M+n bits) divided by P (the CRC polynomial) has NO remainder P is n+1 bits – and the FCS appended to the data has n bits Two types of CRC are used in USB communication 5-bit CRC and 16-bit CRC
43
CRC Original data M bits Appended FCS n bits Total data transferred M+n bits Error check (M+n) / P with no remainder then data is correct P has n+1 bits and is called the polynomial
44
CRC polynomial 5-bit CRC is generated by X 5 + X 2 + 1 polynomial; P = 1 0 0 1 0 1 16-bit CRC is generated by X 16 +X 15 +X 2 +1 P = 11000000000000101
45
How to determine the FCS FCS is the remainder of M (original data) * 2 n (ie shift M n bits to the left and append n 0s ) divided by P For example is M is 10101010 and n is 4 Then M * 2 n –10101010 0000 Next 1010100000 / P to determine the remainder
46
CRC example Example : original 1010001101 P is 110101 = X 5 +X 4 +X 2 +1 (P has 6 bits) Appending 5 0’s get 1010001101 00000 Do the division by XOR (not by normal division!!!!)
47
110101101000110100000 110101 XOR111011Appended 0s 110101 XOR111010 110101 111110 110101 101100 110101 110010 110101 01110
48
Question Based on the concept of CRC (cyclic redundancy checks), if the original message is 1011 1010 1011 and the constant divisor is 10101. Determine the transmitted message in hexademical.
49
CRC creation process Get the raw frame or raw data Left shift the raw frame by n bits and the divide it by P (using XOR) The remainder of the last action is the FCS. Append the FCS to the raw frame. The result is the frame to transmit
50
CRC check process Receive the frame. Divide it by P. Check the reminder. If not zero then there is an error in the frame
51
Packet contents The ADDR – address field specifies which device the packet is designated for. Since USB can support up to 127 devices so ADDR is only 7 bits ENDP – endpoints which is the source or sink of data. Example, if a device can read/write then there will be 2 different endpoints Start of Frame Packet (SOF) are issued by the host at a nominal rate of once every 1ms. The SOF packet delivers two pieces of timing information and is used by “frame timing” related devices such as video/audio streaming. CRC – for error checking
52
Flow-control Token packets indicate the type of transaction to follow. There are 3 types of token packets: IN, OUT, and SETUP. IN – informs the USB device that the host wishes to read information OUT – host wishes to send information SETUP – used to begin control transfers Tokens are only sent by the host, never a device. IN and OUT tokens contain a 7-bit device address and command the device to transmit DATA packets, or receive the following DATA packets, respectively.
53
Token Packet ACK and NAK tokens are used to coordinate the transfer of data packets between the host system and the USB device. Host transfers a data packet to a USB device, the device must either transmit an ACK (acknowledge) or a NAK (not acknowledge) token back to the host. If data and CRC are received correctly then ACK is sent; if not NAK is sent If the host received the NAK then it re-transmits the data packet until the receiver finally receives it correctly. The flow control method is called stop and wait flow control. The host must wait for the client to send an ACK or NAK before transferring additional data packets
54
Flow-control 1.Host issues OUT token (host wants to send data to a device) 2.Data Packet follows (host sends the data packet) 3.Wait for Ack Handshake from device
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.