computer communication. introduction mechanisms applied in communicating between a computer and...

54
Computer communication

Upload: oliver-lindsey

Post on 23-Dec-2015

215 views

Category:

Documents


0 download

TRANSCRIPT

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

Computer communication

Page 2: Computer communication. 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

Page 3: Computer communication. 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

Page 4: Computer communication. 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

Page 5: Computer communication. 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.

Page 6: Computer communication. 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 (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

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

Asynchronous communication

Page 8: Computer communication. 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.

Page 9: Computer communication. 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).

Page 10: Computer communication. 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.

Page 11: Computer communication. 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

Page 12: Computer communication. 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

Page 13: Computer communication. 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.

Page 14: Computer communication. 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

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

Configure the serial communication port under WindowsXP

Page 16: Computer communication. 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

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

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

Page 18: Computer communication. 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

Page 19: Computer communication. 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.

Page 20: Computer communication. 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

Page 21: Computer communication. 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.

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

Hardware configuration

UART built-in

Page 23: Computer communication. 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

Communication is via the RS232 soPC sends charactersto the ADuC832PC may send a ‘1’’0’to represent 10% duty cycle

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

USB to serial converter

Modern computer (especially notebook) has only USB Connectors

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

Page 25: Computer communication. 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

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

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

Page 27: Computer communication. 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

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

USB hub architecture

Root hub

Page 29: Computer communication. 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.

Page 30: Computer communication. 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

Page 31: Computer communication. 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’

Page 32: Computer communication. 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

Page 33: Computer communication. 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

Page 34: Computer communication. 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

Page 35: Computer communication. 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

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

Flow chart for NRZI

Data beingsent

Page 37: Computer communication. 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.

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

Packet format

Page 39: Computer communication. 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.

Page 40: Computer communication. 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

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

Packet format

Page 42: Computer communication. 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

Page 43: Computer communication. 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

Page 44: Computer communication. 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+1

P = 11000000000000101

Page 45: Computer communication. 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

Page 46: Computer communication. 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!!!!)

Page 47: Computer communication. 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 0

Page 48: Computer communication. 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.

Page 49: Computer communication. 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

Page 50: Computer communication. 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

Page 51: Computer communication. 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

Page 52: Computer communication. 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.

Page 53: Computer communication. 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

Page 54: Computer communication. 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