I2C Protocol in Fpga Using VHDL: Main Project Interim Report As A Partial Fullment of The Curriculum
I2C Protocol in Fpga Using VHDL: Main Project Interim Report As A Partial Fullment of The Curriculum
I2C Protocol in Fpga Using VHDL: Main Project Interim Report As A Partial Fullment of The Curriculum
Department of Electronics & Communication Engineering NSS College OF Engineering, Palakkad September 2012
INTRODUCTION
For 8-bit oriented digital control applications, such as those requiring microcontrollers, certain design criteria can be established:
A complete system usually consists of at least one microcontroller and other periph-
The cost of connecting the various devices within the system must be minimized A system that performs a control function does not require high-speed data transfer. Overall eciency depends on the devices chosen and the nature of the interconnect-
To produce a system to satisfy these criteria, a serial bus structure is needed. Although serial buses do not have the throughput capability of parallel buses, they do require less wiring and fewer IC connecting pins. However, a bus is not merely an interconnecting wire; it embodies all the formats and procedures for communication within the system. Devices communicating with each other on a serial bus must have some form of protocol which avoids all possibilities of confusion, data loss and blockage of information. Fast devices must be able to communicate with slow devices. The system must not be dependent on the devices connected to it, otherwise modications or improvements would be impossible. A procedure has also to be devised to decide which device will be in control of the bus and when. And, if dierent devices with dierent clock speeds are connected to the bus, the bus clock source must be dened. All these criteria are involved in the specication of the I2C-bus.
ii
iv
the SDA line Low during the acknowledge bit, this indicates that the Slave-receiver was unable to accept the data and the Master can then generate a STOP condition to abort the transfer. If the Master-receiver does not generate an acknowledge, this indicates to the Slave-transmitter that this byte was the last byte of the transfer. Standard communication on the bus between a Master and a Slave is composed of four parts: START, Slave address, data transfer, and STOP. The I2C protocol denes a data transfer format for both 7-bit and 10-bit addressing. The implementation of the I2C controller supports the seven-bit address format. After the START condition, a Slave address is sent. This address is seven bits long followed by an eighth-bit which is the read/write bit. A 1 indicates a request for data (read) and a 0 indicates a data transmission (write). Only the Slave with the calling address that matches the address transmitted by the Master responds by sending back an acknowledge bit by pulling the SDA line Low on the ninth clock. Once successful Slave addressing is achieved, the data transfer can proceed byte-bybyte as specied by the read/write bit. The Master can terminate the communication by generating a STOP signal to free the bus. However, the Master may generate a START signal without generating a STOP signal rst. This is called a repeated START. MASTERS AND SLAVES The I2C-bus is a multi-master bus. This means that more than one device capable of controlling the bus can be connected to it. To avoid the chaos that might ensue from such an event , an arbitration procedure has been developed. This procedure relies on the wired-AND connection of all I2C interfaces to the I2C-bus. If two or more masters try to put information onto the bus, the rst to produce a one when the other produces a zero will lose the arbitration. The clock signals during arbitration are a synchronized combination of the clocks generated by the masters using the wired-AND connection to v
the SCL line. Generation of clock signals on the I2C-bus is always the responsibility of master devices; each master generates its own clock signals when transferring data on the bus. Bus clock signals from a master can only be altered when they are stretched by a slow-slave device holding-down the clock line or by another master when arbitration occurs. BIT TRANSFER The data on the SDA line must be stable during the HIGH period of the clock. The HIGH or LOW state of the data line can only change when the clock signal on the SCL line is LOW. START AND STOP CONDITIONS Within the procedure of the I2C-bus, unique situations arise which are dened as START (S) and STOP (P) conditions. A HIGH to LOW transition on the SDA line while SCL is HIGH is one such unique case. This situation indicates a START condition. A LOW to HIGH transition on the SDA line while SCL is HIGH denes a STOP condition. START and STOP conditions are always generated by the master. The bus is considered to be busy after the START condition. The bus is considered to be free again a certain time after the STOP condition. The bus stays busy if a repeated START (Sr) is generated instead of a STOP condition. In this respect, the START (S) and repeated START (Sr) conditions are functionally identical.
vi
TRANSFERING DATA BYTE FORMAT Every byte put on the SDA line must be 8-bits long. The number of bytes that can be transmitted per transfer is unrestricted. Each byte has to be followed by an acknowledge bit. Data is transferred with the most signicant bit (MSB) rst. If a slave can not receive or transmit another complete byte of data until it has performed some other function, for example servicing an internal interrupt, it can hold the clock line SCL LOW to force the master into a wait state. Data transfer then continues when the slave is ready for another byte of data and releases clock line SCL. ACKNOWLEDGE Data transfer with acknowledge is obligatory. The acknowledge-related clock pulse is generated by the master. The transmitter releases the SDA line (HIGH) during the acknowledge clock pulse. The receiver must pull down the SDA line during the acknowledge clock pulse so that it remains stable LOW during the HIGH period of this clock pulse. Usually, a receiver which has been addressed is obliged to generate an acknowledge after each byte has been received. When a slave does not acknowledge the slave address (for example, it is unable to receive or transmit because it is performing some real-time function), the data line must be left HIGH by the slave. The master can then generate either a STOP condition to abort the transfer, or a repeated START condition to start a new transfer. If a slave-receiver does acknowledge the slave address but, some time later in the transfer cannot receive any more data bytes, the master must again abort the transfer. This is indicated by the slave generating the not-acknowledge on the rst byte to follow. The slave leaves the data line HIGH and the master generates a STOP or a repeated START condition. If a masterreceiver is involved in a transfer, it must signal the end of data to the slave- transmitter vii
by not generating an acknowledge on the last byte that was clocked out of the slave. The slave-transmitter must release the data line to allow the master to generate a STOP or repeated START condition.begingure
ARBITRATION AND CLOCK GENERATION SYNCHRONIZATION All masters generate their own clock on the SCL line to transfer messages on the I2Cviii
bus. Data is only valid during the HIGH period of the clock. A dened clock is therefore needed for the bit-by-bit arbitration procedure to take place. Clock synchronization is performed using the wired-AND connection of I2C interfaces to the SCL line. This means that a HIGH to LOW transition on the SCL line will cause the devices concerned to start counting o their LOW period and, once a device clock has gone LOW, it will hold the SCL line in that state until the clock HIGH state is reached (see Fig.8). However, the LOW to HIGH transition of this clock may not change the state of the SCL line if another clock is still within its LOW period. The SCL line will therefore be held LOW by the device with the longest LOW period. Devices with shorter LOW periods enter a HIGH wait-state during this time. When all devices concerned have counted o their LOW period, the clock line will be released and go HIGH. There will then be no dierence between the device clocks and the state of the SCL line, and all the devices will start counting their HIGH periods. The rst device to complete its HIGH period will again pull the SCL line LOW. In this way, a synchronized SCL clock is generated with its LOW period determined by the device with the longest clock LOW period, and its HIGH period determined by the one with the shortest clock HIGH period.When all devices concerned have counted o their LOW period, the clock line will be released and go HIGH. There will then be no dierence between the device clocks and the state of the SCL line, and all the devices will start counting their HIGH periods. The rst device to complete its HIGH period will again pull the SCL line LOW. In this way, a synchronized SCL clock is generated with its LOW period determined by the device with the longest clock LOW period, and its HIGH period determined by the one with the shortest clock HIGH period. ARBITRATION A master may start a transfer only if the bus is free. Two or more masters may ix
generate a START condition within the minimum hold time of the START condition which results in a dened START condition to the bus. Arbitration takes place on the SDA line, while the SCL line is at the HIGH level, in such a way that the master which transmits a HIGH level, while another master is transmitting a LOW level will switch o its DATA output stage because the level on the bus doesnot correspond to its own level. Arbitration can continue for many bits. Its rst stage is comparison of the address bits. If the masters are each trying to address the same device, arbitration continues with comparison of the data-bits if they are master-transmitter, or acknowledge-bits if they are master-receiver. Because address and data information on the I2C-bus is determined by the winning master, no information is lost during the arbitration process. A master that loses the arbitration can generate clock pulses until the end of the byte in which it loses the arbitration. If a master also incorporates a slave function and it loses arbitration during the addressing stage, it is possible that the winning master is trying to address it. The losing master must therefore switch over immediately to its slave mode. Figure shows the arbitration procedure for two masters. Of course, more may be involved (depending on how many masters are connected to the bus). The moment there is a dierence between the internal data level of the master generating DATA 1 and the actual level on the SDA line, its data output is switched o, which means that a HIGH output level is then connected to the bus. This will not aect the data transfer initiated by the winning master. Since control of the I2C-bus is decided solely on the address or master code and data sent by competing masters, there is no central master, nor any order of priority on the bus. Special attention must be paid if, during a serial transfer, the arbitration procedure is still in progress at the moment when a repeated START condition or a STOP condition is transmitted to the I2C-bus.If it is possible for such a situation to occur, the masters involved must send this repeated START condition or STOP condition at the same position in the format frame. In other words, arbitration is not allowed between:
A repeated START condition and a data bit A STOP condition and a data bit A repeated START condition and a STOP condition.
Slaves are not involved in the arbitration procedure. USE OF THE CLOCK SYNCHRONIZING AS A HANDSHAKE In addition to being used during the arbitration procedure, the clock synchronization mechanism can be used to enable receivers to cope with fast data transfers, on either a byte level or a bit level. On the byte level, a device may be able to receive bytes of data at a fast rate, but needs more time to store a received byte or prepare another byte to be transmitted. Slaves can then hold the SCL line LOW after reception and acknowledgment of a byte to force the master into a wait state until the slave is ready for the next byte transfer in a type of handshake procedure. On the bit level, a device such as a microcontroller with or without limited hardware for the I2C-bus can slow down the bus clock by extending each clock LOW period. The speed of any master is thereby adapted to the internal operating rate of this device. ADRESSING BY 7 BITS Data transfers follow the format shown in Figure. After the START condition (S), a slave address is sent. This address is 7 bits long followed by an eighth bit which is a data direction bit (R/W) - a zero indicates a transmission (WRITE), a one indicates a request for data (READ). A data transfer is always terminated by a STOP condition (P) generated by the master. However, if a master still wishes to communicate on the bus, it can generate a repeated START condition (Sr) and address another slave without rst generating a STOP condition. Various combinations of read/write formats are then possible within such a transfer. Possible data transfer formats are:
Master-transmitter transmits to slave-receiver. The transfer direction is not changed. Master reads slave immediately after rst byte. At the moment of the rst acknowl-
edge, the master- transmitter becomes a master- receiver and the slave-receiver becomes a slave-transmitter. This rst acknowledge is still generated by the slave. The STOP condition is generated by the master, which has previously sent a notacknowledge (A). xi
Combined format: During a change of direction within a transfer, the START con-
dition and the slave address are both repeated, but with the R/W bit reversed. If a master receiver sends a repeated START condition, it has previously sent a not-acknowledge.
xii
ADVANTAGES
Simple Well Known Universally accepted Plug Play Cost Eective Large Portfolio
DISADVANTAGES
APPLICATIONS
For adding UART / IrDA Functionality Cordless telephone Digital media adapters LCD display MP3 Players
ARCHITECTURE (DESIGN) OF I2C CONTROLLER The I2C Controller design contains a microcontroller (mC) interface and provides I2C Master/Slave capability. It is intended to be used with a microcontroller (mC) or microprocessor (mP). xiii
xiv
xv
MICROCONTROLLER LOGIC
xvi
xvii