Computer communication 1. Introduction Mechanisms applied in communicating between a computer and...

66
Computer communication 1

Transcript of Computer communication 1. Introduction Mechanisms applied in communicating between a computer and...

Page 1: Computer communication 1. Introduction Mechanisms applied in communicating between a computer and another computer or with other devices. Mainly serial.

Computer communication

1

Page 2: Computer communication 1. Introduction Mechanisms applied in communicating between a computer and another computer or with other devices. Mainly serial.

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

2

Page 3: Computer communication 1. Introduction Mechanisms applied in communicating between a computer and another computer or with other devices. Mainly serial.

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

3

Page 4: Computer communication 1. Introduction Mechanisms applied in communicating between a computer and another computer or with other devices. Mainly serial.

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

4

Page 5: Computer communication 1. Introduction Mechanisms applied in communicating between a computer and another computer or with other devices. Mainly serial.

Synchronous communication• Synchronous communication needs a common clock • Transmitter first sends out synchronization characters to the

receiver at the proper clock tick (for example at the rising edge)

• Receiver reads the synchronization bit pattern and compares it to a default sync pattern

• If the sync pattern is identified, the receiver begins to read character data off the communications line

• Sync characters may be periodically resent to assure that synchronization is maintained

5

Page 6: Computer communication 1. Introduction Mechanisms applied in communicating between a computer and another computer or with other devices. Mainly serial.

Synchronous communication

• Synchronous type of communication is typically used in high-speed data transfer

• However, synchronous communication requires a common clock and this will increase the cost and less common in simple applications

6

Page 7: Computer communication 1. Introduction Mechanisms applied in communicating between a computer and another computer or with other devices. Mainly serial.

Synchronous communication

7

Page 8: Computer communication 1. Introduction Mechanisms applied in communicating between a computer and another computer or with other devices. Mainly serial.

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.

8

Page 9: Computer communication 1. Introduction Mechanisms applied in communicating between a computer and another computer or with other devices. Mainly serial.

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 (symbol 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

9

Page 10: Computer communication 1. Introduction Mechanisms applied in communicating between a computer and another computer or with other devices. Mainly serial.

Asynchronous communication

10

Page 11: Computer communication 1. Introduction Mechanisms applied in communicating between a computer and another computer or with other devices. Mainly serial.

Asynchronous communication• 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.

11

Page 12: Computer communication 1. Introduction Mechanisms applied in communicating between a computer and another computer or with other devices. Mainly serial.

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).

12

Page 13: Computer communication 1. Introduction Mechanisms applied in communicating between a computer and another computer or with other devices. Mainly serial.

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 bit3. 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.

13

Page 14: Computer communication 1. Introduction Mechanisms applied in communicating between a computer and another computer or with other devices. Mainly serial.

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

14

Page 15: Computer communication 1. Introduction Mechanisms applied in communicating between a computer and another computer or with other devices. Mainly serial.

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

15

Page 16: Computer communication 1. Introduction Mechanisms applied in communicating between a computer and another computer or with other devices. Mainly serial.

Parity for error checkingExample• 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.

16

Page 17: Computer communication 1. Introduction Mechanisms applied in communicating between a computer and another computer or with other devices. Mainly serial.

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

17

Page 18: Computer communication 1. Introduction Mechanisms applied in communicating between a computer and another computer or with other devices. Mainly serial.

Configure the serial communication port under WindowsXP

18

Page 19: Computer communication 1. Introduction Mechanisms applied in communicating between a computer and another computer or with other devices. Mainly serial.

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

19

Page 20: Computer communication 1. Introduction Mechanisms applied in communicating between a computer and another computer or with other devices. Mainly serial.

UART and USART

• Uart and Usart are devices to perform serial communication

• UART – universal asynchronous receiver/transmitter

• USART – universal synchronous/asynchronous receiver/transmitter

20

Page 21: Computer communication 1. Introduction Mechanisms applied in communicating between a computer and another computer or with other devices. Mainly serial.

UART

CPUUART UART CPU

BUSBUS

GND

From the CPU’s point of view the UART is another I/O deviceSome microprocessor (or microcontroller such as ADuC832) has built-in UART

21

Page 22: Computer communication 1. Introduction Mechanisms applied in communicating between a computer and another computer or with other devices. Mainly serial.

Uart and Usart• The major functions of UART or USART: parallel-to-serial

conversion and serial-to-parallel conversions• Automatically frame (or insert) character with start bit, parity

bit and stop bit• Check for correct parity, framing error, and overrun error• Framing error occurs when stop bits are not detected• Overrun error occurs when prior character that was received

was not read out of the USART receive data register by the microprocessor before another character was received.

22

Page 23: Computer communication 1. Introduction Mechanisms applied in communicating between a computer and another computer or with other devices. Mainly serial.

Connecting two USART

Device ComputerDSRDTR

RTS

CTSRx

Tx

Common

RTSCTS

DSR

DTRRx

Tx

Common

The RTS, CTS, DSR, DTR are handshake signals These signals can improve the communication reliability but usually not used

23

Page 24: Computer communication 1. Introduction Mechanisms applied in communicating between a computer and another computer or with other devices. Mainly serial.

Handshake of USART• When a device wants to send a data then it

will first set the RTS (Ready, or Request To Send).

• The receiving end will see DSR (Data Set Ready) active and acknowledge by setting the DTR (Data Terminal Ready) line.

• The sending end see the CTS (Clear to send) active then

• Transmission of data proceed

24

Page 25: Computer communication 1. Introduction Mechanisms applied in communicating between a computer and another computer or with other devices. Mainly serial.

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

25

Page 26: Computer communication 1. Introduction Mechanisms applied in communicating between a computer and another computer or with other devices. Mainly serial.

8251A Programmable communication interface

• The 8251A is one of the most widely used USART IC (Universal Synchronous Asynchronous Receiver/transmitter )

• Contains a full-duplex receiver and transmitter• Configurable through software (asynchronous, or

synchronous mode) sent by the host CPU• Automatically detection of parity, framing, and

overrun errors

26

Page 27: Computer communication 1. Introduction Mechanisms applied in communicating between a computer and another computer or with other devices. Mainly serial.

Command register

Similar to 8255The device must be Configured by softwareBefore it can perform itsFunctions

27

Page 28: Computer communication 1. Introduction Mechanisms applied in communicating between a computer and another computer or with other devices. Mainly serial.

8251A USART pin configuration

28

Page 29: Computer communication 1. Introduction Mechanisms applied in communicating between a computer and another computer or with other devices. Mainly serial.

29

Page 30: Computer communication 1. Introduction Mechanisms applied in communicating between a computer and another computer or with other devices. Mainly serial.

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.

30

Page 31: Computer communication 1. Introduction Mechanisms applied in communicating between a computer and another computer or with other devices. Mainly serial.

R2232C1. Incoming signal2. Incoming data3. Outgoing data4. DTR5. Ground6. DSR7. RTS8. CTS9. Ring indicator

Pin 1 and 9 are only available in Connection to a modem

31

Page 32: Computer communication 1. Introduction Mechanisms applied in communicating between a computer and another computer or with other devices. Mainly serial.

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.

32

Page 33: Computer communication 1. Introduction Mechanisms applied in communicating between a computer and another computer or with other devices. Mainly serial.

Hardware configuration

UART built-in

33

Page 34: Computer communication 1. Introduction Mechanisms applied in communicating between a computer and another computer or with other devices. Mainly serial.

Applications

PC

ADuC832

Motor

Using a PC to control a motor can be done via a ADuC832PC talks to ADuC832 via the serial communication ADuC832 control the motor using Ports (just like the lab exercise)

RS232

34

Page 35: Computer communication 1. Introduction Mechanisms applied in communicating between a computer and another computer or with other devices. Mainly serial.

USB to serial converterModern computer (especially notebook) has only USB Connectors

A USB to serial converter canconvert the USB signal to RS232 signal so traditional serialcommunication techniques canstill apply.

35

Page 36: Computer communication 1. Introduction Mechanisms applied in communicating between a computer and another computer or with other devices. Mainly serial.

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

36

Page 37: Computer communication 1. Introduction Mechanisms applied in communicating between a computer and another computer or with other devices. Mainly serial.

Basic USB• 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

37

Page 38: Computer communication 1. Introduction Mechanisms applied in communicating between a computer and another computer or with other devices. Mainly serial.

USB connection

Universal Serial Bus Many devices can connect to the bus at the same time

38

Page 39: Computer communication 1. Introduction Mechanisms applied in communicating between a computer and another computer or with other devices. Mainly serial.

USB hub architecture

Root hub

39

Page 40: Computer communication 1. Introduction Mechanisms applied in communicating between a computer and another computer or with other devices. Mainly serial.

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.

40

Page 41: Computer communication 1. Introduction Mechanisms applied in communicating between a computer and another computer or with other devices. Mainly serial.

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

41

Page 42: Computer communication 1. Introduction Mechanisms applied in communicating between a computer and another computer or with other devices. Mainly serial.

USB connector

Pin Signal

1 5.0V

2 -Data

3 +Data

4 Ground

Type B connector

+D > -D 200mv then it is a ‘1’+D< -D 200mV then it is a ‘0’

42

Page 43: Computer communication 1. Introduction Mechanisms applied in communicating between a computer and another computer or with other devices. Mainly serial.

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

43

Page 44: Computer communication 1. Introduction Mechanisms applied in communicating between a computer and another computer or with other devices. Mainly serial.

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

44

Page 45: Computer communication 1. Introduction Mechanisms applied in communicating between a computer and another computer or with other devices. Mainly serial.

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 1 1 0 1 0 0 1 1 0 0 0 1 0

1 1 1 0 0 1 0 0 0 1 0 1 1 0

45

Page 46: Computer communication 1. Introduction Mechanisms applied in communicating between a computer and another computer or with other devices. Mainly serial.

NRZI

• Example– 1001010100011 (assume idle is ‘1’)– Result 11011001101000– 0001111111101 (assume idle is ‘0’)– Result 010111111011100

Stuff bit

46

Page 47: Computer communication 1. Introduction Mechanisms applied in communicating between a computer and another computer or with other devices. Mainly serial.

Flow chart for NRZI

Data beingsent

47

Page 48: Computer communication 1. Introduction Mechanisms applied in communicating between a computer and another computer or with other devices. Mainly serial.

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.

48

Page 49: Computer communication 1. Introduction Mechanisms applied in communicating between a computer and another computer or with other devices. Mainly serial.

Packet format

49

Page 50: Computer communication 1. Introduction Mechanisms applied in communicating between a computer and another computer or with other devices. Mainly serial.

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.

50

Page 51: Computer communication 1. Introduction Mechanisms applied in communicating between a computer and another computer or with other devices. Mainly serial.

PID codesPID Name Type Description

E1H OUT Token Host -> function transaction

D2H ACK Handshake Receiver accepts packet

C3H Data0 Data Data packet PID even

A5H SOF Token Start of frame

69H IN Token Function -> host transaction

5AH NAK Handshake Receiver does not accept data

4BH Data1 Data Data packet PID odd

3CH PRE Special Host preamble

2DH Setup Token Setup command

1EH Stall Token Stalled

51

Page 52: Computer communication 1. Introduction Mechanisms applied in communicating between a computer and another computer or with other devices. Mainly serial.

Packet format

52

Page 53: Computer communication 1. Introduction Mechanisms applied in communicating between a computer and another computer or with other devices. Mainly serial.

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

53

Page 54: Computer communication 1. Introduction Mechanisms applied in communicating between a computer and another computer or with other devices. Mainly serial.

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

54

Page 55: Computer communication 1. Introduction Mechanisms applied in communicating between a computer and another computer or with other devices. Mainly serial.

CRC polynomial

• 5-bit CRC is generated by X5 + X2 + 1 polynomial; P = 1 0 0 1 0 1

• 16-bit CRC is generated by X16+X15+X2+1P = 11000000000000101

55

Page 56: Computer communication 1. Introduction Mechanisms applied in communicating between a computer and another computer or with other devices. Mainly serial.

How to determine the FCS

• FCS is the remainder of M (original data) * 2n (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 * 2n

– 10101010 0000

• Next 1010100000 / P to determine the remainder

56

Page 57: Computer communication 1. Introduction Mechanisms applied in communicating between a computer and another computer or with other devices. Mainly serial.

CRC example

• Example : original 1010001101• P is 110101 = X5+X4+X2+1 (P has 6 bits)• Appending 5 0’s get 1010001101 00000• Do the division by XOR (not by normal

division!!!!)

57

Page 58: Computer communication 1. Introduction Mechanisms applied in communicating between a computer and another computer or with other devices. Mainly serial.

110101 1 0 1 0 0 0 1 1 0 1 0 0 0 0 0

1 1 0 1 0 1

XOR 1 1 1 0 1 1 Appended 0s

1 1 0 1 0 1

XOR 1 1 1 0 1 0

1 1 0 1 0 1

1 1 1 1 1 0

1 1 0 1 0 1

1 0 1 1 0 0

1 1 0 1 0 1

1 1 0 0 1 0

1 1 0 1 0 1

0 1 1 1 058

Page 59: Computer communication 1. Introduction Mechanisms applied in communicating between a computer and another computer or with other devices. Mainly serial.

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.

59

Page 60: Computer communication 1. Introduction Mechanisms applied in communicating between a computer and another computer or with other devices. Mainly serial.

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

60

Page 61: Computer communication 1. Introduction Mechanisms applied in communicating between a computer and another computer or with other devices. Mainly serial.

CRC check process

• Receive the frame. • Divide it by P. • Check the reminder. If not zero then there is

an error in the frame

61

Page 62: Computer communication 1. Introduction Mechanisms applied in communicating between a computer and another computer or with other devices. Mainly serial.

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

62

Page 63: Computer communication 1. Introduction Mechanisms applied in communicating between a computer and another computer or with other devices. Mainly serial.

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.

63

Page 64: Computer communication 1. Introduction Mechanisms applied in communicating between a computer and another computer or with other devices. Mainly serial.

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

64

Page 65: Computer communication 1. Introduction Mechanisms applied in communicating between a computer and another computer or with other devices. Mainly serial.

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

65

Page 66: Computer communication 1. Introduction Mechanisms applied in communicating between a computer and another computer or with other devices. Mainly serial.

The USB communications protocol.

66

Like any well architected communications protocol, underlying the USB standard is a well defined set of layers. Broadly speaking, these can be represented as shown in the figure below