Usb Protocol: Introduction To Mechatronics
Usb Protocol: Introduction To Mechatronics
USB PROTOCOL
USB is also faster than older ports, such as serial and parallel ports. The USB 1.1 specification
supports data transfer rates of up to 12Mb/sec and USB 2.0 has a maximum transfer rate of 480
Mbps. Though USB was introduced in 1997, the technology didn't really take off until the
introduction of the Apple iMac (in late 1998) which used USB ports exclusively. It is somewhat
ironic, considering USB was created and designed by Intel, Compaq, Digital, and IBM. Over the
past few years, USB has become a widely-used cross-platform interface for both Macs and PCs.
The data requires a standardized method of transfer over the USB interface along with a standard
format for the USB data packets. To achieve this the system has a defined the USB data transfer
protocol, data packet format, etc. that enables the data to be formatted and carried in a defined
way that provides the reliable communication.
Evolution of USB:
USB 1.0 – 1.1 is Maximum transfer rate of 12 mbps and first appeared on market in 1995 and
1998.Hi-Speed USB or USB 2.0 is released with speeds of 480 mbps and released in
2000.Super-Speed USB or USB 3.0 is predicted speeds of 5 gbps and released in 12 November
2008. Wireless USB is released with speed of 480 Mbit/s at distances up to 3 meters and
110 Mbit/s at up to 10 meters and released in 2009.
Working of Usb:
Enumeration is the computer would decide which kind of data the device uses interrupt - low
data transfer - keyboard or mouse or Bulk - large amounts of data - printer or external hard drive
or Isochronous - streamed data - microphones or speakers. Encoding is the process of recoding
or modifying information into a desired format or pattern. When the two devices communicate
and configure to which form of data transmission should be used. Transmission is convey
information from the device to another location. Can be as simple as typing a few keys on the
keyboard or transferring large amounts of data like pictures, music and the like. Receiving is
recognizes and accepts information from transition and collects the inputs and readies them for
storage. This would be where the typed keys would be displayed onto the screen or stored in a
word document. Usb is working in all these process and do reliable communication. In the
similar matter, whenever you are receiving from the slave device, you are also sending
something. Normally, when the slave device is sending you data it will ignore everything you are
sending to it.
Data Transmission
USB operational basics:
In order to understand how the data transfers and the protocol operates within the USB
environment, it is first necessary to understand how USB is physically set up and how it
appears to the system / host. For most systems using USB, the host will be some form of
computer: desktop, laptop, tablet, etc. Host is the host is the computer or item that acts as
the main element or controller for the USB system. The host has a hub contained within it
and this is called the Root Hub. Hub is the hub is a device that effectively expands the
number of ports available - it will have one connection to the upstream connection, and
several downstream. It is possible to plug one hub into another to expand the capability
and connectivity further. Port is the socket through which access to the USB network is
gained. It can be on a host, or a hub. Function these are the peripherals or items to which
the USB link is connected. Mice, keyboards, Flash memories, etc. Device is this term is
collectively used for hubs and functions.
USB Communication:
The data travels to or from Endpoints in an USB Device. The client in the USB Host stores data
in buffers, but does not have endpoints. The USB Host and the peripheral USB Device have
distinct layers between the logical connections data is transferred using Pipes.
Pipes
Message pipes have a defined USB format and are host controlled. Message pipes allow
data to flow in both directions and support Control Transfers only.
Stream pipes have no defined USB format and can either be controlled by the host or by
the device. The data stream has a predefined direction, either IN or OUT. Stream pipes
support Interrupt Transfers, Isochronous Transfers, and Bulk Transfers.
Most pipes come into existence when an USB Device has been connected to the USB
Bus and configured by the USB Host. A pipe originates from a data buffer within the
host client and terminates inside the USB Device at an Endpoint
Transfers (data flow types) can consist of one or more transactions. A pipe supports only one of
the following transfer types. Control Transfers are typically used to setup an USB device. They
always use IN/OUT Endpoint 0. Interrupt Transfers can be used where data is sent regularly, for
example for status updates. Isochronous Transfers transmit real-time data such as audio and
video. Bulk Transfers can be used to send data where timing is not important, for example to a
printer.
Endpoints
Endpoints can be described as data sources or sinks and exists in USB Devices only. The data
stored at an endpoint may either be received from or waiting for being sent to the USB Host. An
endpoint can be configured to support four transfer types defined in the USB specification
(Control Transfers, Interrupt Transfers, Isochronous Transfers, and Bulk Transfers). Within the
limits of the hardware, endpoints can be configured using the USB Middleware (e.g. limit an
endpoint to a certain transfer type).
An endpoint acts as a kind of buffer. A USB Host's client may send data to Endpoint 1 for
example. Coming from the USB Host, the data will be sent to the OUT Endpoint 1. The program
on the microcontroller will then read the data as soon as it is ready to do so. Returning data has
to be written to the IN Endpoint 1, as the program cannot access the USB bus freely (the USB
bus being controlled by the USB Host). The data in IN Endpoint 1 stays there until the host sends
an IN packet to Endpoint 1 requesting the data.
Endpoint 0 is used for control transfers only and cannot be assigned to any other function.
OUT always refers to the direction pointing from the host to the device.
The total number of endpoints and the capability of each endpoint is defined by the underlying
hardware.
USB Protocol:
USB is a polled bus, where the host initiates all data exchanges.
Transactions:
Data is transferred in so called transactions. Normally, they consist of three packets.The token
packet is the header defining the transaction type and direction, the device address, and the
endpoint. Data is transferred in a data packet. The final status of the transaction is acknowledges
in the handshake packet.
In a transaction, data is transferred either from the USB Host to an USB Device or vice-versa.
The transfer direction is specified in the token packet that is sent from the USB Host. Then, the
source sends a data packet or indicates it has no data to transfer. In general, the destination
responds with a handshake packet indicating whether the transfer was successful. Packets could
be thought of as the smallest element of data transmission. Each packet transmits an integral
number of bytes at the current transmission rate. Packets start with a synchronization pattern,
followed by the data bytes of the packet, and concluded with an End-of-Packet (EOP) signal. All
USB packet patterns are transmitted least significant bit first. Before and after the packet, the bus
is in idle state.
• ADDR: This field contains the designation address of the USB device. It is of 7 bits, this means
it can supports 27 ¬ = 127 devices.
• ENDP: This field specifies the endpoint number. It is of 4 bits, this means it can indicate
2¬¬4¬¬ ¬¬= 16 possible endpoints.
• CRC: CRC stands for Cyclic Redundancy Check. This field is used to check data in the packet
for any error using CRC process
For token packets, 5-bit CRC is used and for data packets 16-bit CRC is used
• EOP: EOP stands for End of Packet. This field signals the data lines for Single Ended
Zero(SE0) for approximately 2 bit times, followed by J state(idle state) for 1 bit time
1. Token packets: These packets are only sent by host. The packet structure contains a PID byte,
11 bits of address and a 5-bit CRC. Types of token packets:
• In – This packet notifies the USB device that host wants to read information.
• Out – This packet notifies the USB device that host wants to write information.
• Ping – Before sending OUT/DATA packet pair, this token asks the USB device if it is ready to receive
OUT/DATA packet pair.
• Split – This token is used to communicate to a low/full speed device on a high speed bus
2. Data packets: Two types of data packets are there, Data0 and Data1. The packet structure
contains a PID byte, data field and 16-bit CRC. The data field can carry 0- 1023 bytes of data.
Data must be always sent in multiple of bytes.
After USB2.0, two more types were added Data2 and MData. They are only used in high speed
transfer high bandwidth isochronous transfer when there is a need to transfer more than 1024
bytes at 8192 kB/s.
3. Handshake Packets: These packets are mostly sent in response to data packets. They simply
consist of a PID byte. There are three types of handshake packets :
• NAK – indicating that packets cannot be temporarily received or send. Also used to indicate
that there is no data to send
• STALL – indicating that the device is in error state and needs intervention from the host
Transactions:
A successful transaction consists of up-to three phases that occur in sequence. They are Token
phase, Data phase and Handshake phase.
These phases ensured secure transfer of data. There are three types of transactions:
Advantage:
Portability:
USB flash drives can be carried easily from one place to another and can be placed in your
pocket, wallet, or purse. On the contrary, in the case of other big devices, it might difficult for
you to carry them and so you would need a larger bag for them.
Storage Capacity:
USB flash drive can store a lot of our data. We can easily store 2TB or more data in a tiny
device.
Whether you have to store some important digital documents, files, images, or videos, you can
easily copy them to your USB flash drive. It does not take much time to transfer the data.
Considering the fact, it's one of the best devices to use when you want to share the data with
others.
Compatible:
It does not matter if you want to use your USB flash drive on a laptop, a desktop, or a digital
camera; it's compatible with every device. There are many devices that you can use with USB
flash drives
Durable:
Durability is always a concern when you want to choose any USB flash drive. If you drop a hard
drive, there is a chance that your hard drive will stop working, and complete data stored in it is
gone. But in the case of a USB flash drive, it will still work, and the data stored in it will remain
safe.
Easy Accessibility:
Because of the plug and play feature, USB flash drives are the best device to make use of when
they come to ease of accessibility
Affordable:
If you compare a USB devices with other external storage devices, you will find that it's more
affordable than them.
Data Security:
Thanks to the latest technology, the USB devices have security features available in them.
The versatile nature of USB removes the complexity of different connector type and hardware
requirements for each peripheral.
Auto-configuration:
The operating system of the host device only needs to install the USB device driver for once.
Later whenever the peripheral device is plugged in, the driver is automatically loaded to
configure the plugged in device.
Easy to expand:
Generally personal computers (Motherboards) have 3 or 4 USB ports. In case if more USB ports
are required, USB hubs can be used to add external ports.
Reliability:
The USB protocol can catch errors during data transfer and notify the transmitter to retransmit
the data.
The USB devices generally works on +5V and consumes current in Milliampere.
Disadvantage:
Easy To Lose:
The small size of USB flash drives does make them portable but also puts them on the risk of
easily getting misplaced. They might easily fall from your pocket or wallet, or even anyone can
steal them
Corruption Issue:
We all tend to make use of these storage devices on different computer systems and gadgets.
They could contain viruses, malware, or other such malicious programs, which can corrupt your
storage devices, and even there is a possibility of data corruption.
Rewrite Limitation:
This is one limitation with USB flash drives that the number of times you can rewrite the data is
limited. Even though this is not a bigger limitation, you can do that up to a certain number only,
and the number is roughly 100,000 times. For some people, this can be a problem, who are
regularly writing and deleting data, but for an average user, this is not a very big problem.