Data transmission between two entities plays a major role in designing embedded systems. In general the medium of data transmission can be either serial or parallel. The hardware requirement (number of I/O lines) is higher in parallel communication scheme while the number of data lines required in serial communication is much lesser. UART, SPI, TWI or USB are some of the protocols widely used in embedded systems for serial data communication. A brief summary of the aforesaid serial protocols are discussed below.
1. UART (Universal Asynchronous Receiver and transmitter):
The first chip on UART was designed in around 1971. It is one of the simplest forms of data transmission from a controller/PC. It requires a minimum of two pins (transmitter and receiver pin) and a common ground line for data communication. The UART chip is generally found inbuilt in most of the microcontrollers.
In order to communicate the controller with PC a level converter IC like MAX232/233 is needed. Moreover to establish synchronization between two entities, both the devices must transmit or receive the data at same baud rate (the baud rate must be previously known at both the ends). Because of its speed limitation, UART is not used for high speed devices..
2. SPI (Serial Peripheral Interface):
SPI was developed by MOTOROLA and it is very renowned name in data transmission. It has only three lines (i.e. MISO, MOSI and SCK) for data transmission as well as for handshake unlike UART (which requires 9 pins for full feature operations). In SPI communication there is only one MASTER controller and one SLAVE controller, and hence the slave addressing is not required. It is a full duplex serial data communication process.
The MASTER can read from MISO line while transmitting data on MOSI line. The MASTER controls the complete process of data transmission and also provides synchronization clock on the SCL line. Since the synchronization is done by the MASTER itself, the SLAVE device need not worry about the clock frequency at other end. The data size is not restricted to 8-bit data.
The main disadvantage in SPI interfacing is that it can be established only for short distance communication unlike USART. Though only three pins are required for data transmission, one additional pin (SS) is required in SLAVE device. The number of pin required for communication is more as compared to TWI.
3. USB (Universal Serial BUS):
The protocol was developed and invented by Intel. The development started in 1994 and in 2008 it became the most popular name in the field of data transmission replacing most of the serial and parallel devices. The main advantage of USB is its speed. The speed of data transmission in USB devices is very high. Many of the microcontrollers (like AT89C51/S51/ S52, ATmega16/8, etc.) don’t support USB communication. There is a wide range of controllers available in AVR too which support the USB communication.
4. TWI (Two wire interface):
The TWI / I2C (I-two-C) protocol was invented by Philips. In TWI the serial data transmission is done in asynchronous mode. This protocol uses only two wires for communicating between two or more ICs. The two bidirectional open drain lines named SDA (Serial Data) and SCL (Serial Clock) with pull up resistors are used for data transfer between devices.
One of the two devices, which controls the whole process, is known as Master and the other which responds to the queries of master is known as Slave device. The ACK (acknowledgement) signal is sent/received from both the sides after every transfer and hence reduces the error. SCL is the clock line bus used for synchronization and is controlled by the master. SDA is known as the data transfer bus.
I2C/TWI is a half duplex serial transmission and hence the data flow can be in a direction at a time. The data transfer rate depends on crystal frequency of slave controller. The rate of data transfer refers to clock frequency on SCL bus which must be 1/16th of slave frequency.
TWI (Two Wire Interface) Details:
TWI (Two wire interface) as the name suggests is based on two wires namely SDA (Serial Data) and SCL (Serial Clock). The master controls the two buses and slave always responds to the master’s queries. There can be multi master or single master mode of communication.
The master initiates the communication by sending a Start condition on the SDA and SCL line. A high to low transmission on SDA line while SCL is high is defined as a Start condition.
In return the master updates its status values. The status values are the predefined values and cover the different states that the TWI can be in after every operation of data transfer. Error detection or the faulty transmission can be detected by looking at the status values. The status values are determined by using TWSR register for AVR microcontroller
The start condition is followed by seven bit slave address and then by a data direction bits. Every slave is recognized by its address (The slave address is assigned to slave device at the time of slave initialization). The Data Direction Bit tells the direction of data flow. If the data direction bit is logic zero the master performs write operation with slave or if the data direction bit is logic one then the master performs read operation from slave. The data direction bit is also known as Read/Write Control bit.
If a particular slave device is addressed, the slave acknowledges to master by holding SDA low for one clock cycle.
Depending on the DDB (data direction bit) the master or slave transmits the data (8-bit data) on SDA pin. Receiving device then acknowledges the data. The acknowledgement signal updates the status register.
When data transmission is completed the Stop Condition is issued by master to stop the communication. A low to high transmission on SDA line while SCL is high is defined as a Stop condition.
Note: Multiple bytes can be sent in one direction without repeated start or stop condition.
AVR (ATmega32) contains some in built registers which not only reduce the level of complexity but also make the whole communication process smooth.
No comments:
Post a Comment