Understanding I2C Bus
Understanding I2C Bus
Understanding I2C Bus
The I C bus is a very popular and powerful bus used for communication between a master (or multiple
masters) and a single or multiple slave devices. Figure 1 illustrates how many different peripherals may
share a bus which is connected to a processor through only 2 wires, which is one of the largest benefits
that the I2C bus can give when compared to other interfaces.
This application note is aimed at helping users understand how the I2C bus works.
Figure 1 shows a typical I2C bus for an embedded system, where multiple slave devices are used. The
microcontroller represents the I2C master, and controls the IO expanders, various sensors, EEPROM,
ADCs/DACs, and much more. All of which are controlled with only 2 pins from the master.
VCC
VCC
VCC
I/O
Expanders
RP
SCL
Microcontroller
or Processor
SDA
LED
Blinkers
I/O
Expanders
Hub
Repeater
Buffer
SCL0
SDA0
VCC
Multiplexer /
Switch
SCL1
SDA1
Data
Converter
EEPROM
LCD Driver
Temperature
Sensor
Electrical Characteristics
www.ti.com
Electrical Characteristics
I2C uses an open-drain/open-collector with an input buffer on the same line, which allows a single data line
to be used for bidirectional data flow.
1.1
Logic
SDA/SCL
Slave or Master
RPU
VBUS
VBUS
Logic
Time
I2C Interface
www.ti.com
1.1.2
SDA/SCL
Slave or Master
RPU
VBUS
VBUS
Logic
Time
I2C Interface
2.1
I2C Interface
2.1.1
www.ti.com
I C communication with this device is initiated by the master sending a START condition and terminated
by the master sending a STOP condition. A high-to-low transition on the SDA line while the SCL is high
defines a START condition. A low-to-high transition on the SDA line while the SCL is high defines a STOP
condition.
SCL
SDA
START
Condition
Data Transfer
STOP
Condition
2.1.2
2.2
I2C Interface
www.ti.com
SCL
1
ACK
MSB
Bit
Bit
Bit
Bit
Bit
Bit
LSB
ACK
SDA
2.3
I2C Data
www.ti.com
SCL
D6
D5
D4
D3
D2
D1
LSB
D0
NACK
SDA
MSB
D7
STOP
Condition
Data Byte N
I2C Data
Data must be sent and received to or from the slave devices, but the way that this is accomplished is by
reading or writing to or from registers in the slave device.
Registers are locations in the slave's memory which contain information, whether it be the configuration
information, or some sampled data to send back to the master. The master must write information into
these registers in order to instruct the slave device to perform a task.
While it is common to have registers in I2C slaves, please note that not all slave devices will have
registers. Some devices are simple and contain only 1 register, which may be written directly to by
sending the register data immediately after the slave address, instead of addressing a register. An
example of a single-register device would be an 8-bit I2C switch, which is controlled via I2C commands.
Since it has 1 bit to enable or disable a channel, there is only 1 register needed, and the master merely
writes the register data after the slave address, skipping the register number.
I2C Data
www.ti.com
3.1
To write on the I2C bus, the master will send a start condition on the bus with the slave's address, as well
as the last bit (the R/W bit) set to 0, which signifies a write. After the slave sends the acknowledge bit, the
master will then send the register address of the register it wishes to write to. The slave will acknowledge
again, letting the master know it is ready. After this, the master will start sending the register data to the
slave, until the master has sent all the data it needs to (sometimes this is only a single byte), and the
master will terminate the transmission with a STOP condition.
Figure 8 shows an example of writing a single byte to a slave register.
A6 A5 A4 A3 A2 A1 A0
START
B7 B6 B5 B4 B3 B2 B1 B0
R/W = 0 ACK
D7 D6 D5 D4 D3 D2 D1 D0
ACK
ACK
STOP
3.2
Reading from a slave is very similar to writing, but with some extra steps. In order to read from a slave,
the master must first instruct the slave which register it wishes to read from. This is done by the master
starting off the transmission in a similar fashion as the write, by sending the address with the R/W bit
equal to 0 (signifying a write), followed by the register address it wishes to read from. Once the slave
acknowledges this register address, the master will send a START condition again, followed by the slave
address with the R/W bit set to 1 (signifying a read). This time, the slave will acknowledge the read
request, and the master releases the SDA bus, but will continue supplying the clock to the slave. During
this part of the transaction, the master will become the master-receiver, and the slave will become the
slave-transmitter.
The master will continue sending out the clock pulses, but will release the SDA line, so that the slave can
transmit data. At the end of every byte of data, the master will send an ACK to the slave, letting the slave
know that it is ready for more data. Once the master has received the number of bytes it is expecting, it
will send a NACK, signaling to the slave to halt communications and release the bus. The master will
follow this up with a STOP condition.
Figure 9 shows an example of reading a single byte from a slave register.
A6 A5 A4 A3 A2 A1 A0
START
B7 B6 B5 B4 B3 B2 B1 B0
R/W = 0 ACK
ACK
Sr
A6 A5 A4 A3 A2 A1 A0
Repeated START
D7 D6 D5 D4 D3 D2 D1 D0 NA
R/W = 1 ACK
NACK
STOP
IMPORTANT NOTICE
Texas Instruments Incorporated and its subsidiaries (TI) reserve the right to make corrections, enhancements, improvements and other
changes to its semiconductor products and services per JESD46, latest issue, and to discontinue any product or service per JESD48, latest
issue. Buyers should obtain the latest relevant information before placing orders and should verify that such information is current and
complete. All semiconductor products (also referred to herein as components) are sold subject to TIs terms and conditions of sale
supplied at the time of order acknowledgment.
TI warrants performance of its components to the specifications applicable at the time of sale, in accordance with the warranty in TIs terms
and conditions of sale of semiconductor products. Testing and other quality control techniques are used to the extent TI deems necessary
to support this warranty. Except where mandated by applicable law, testing of all parameters of each component is not necessarily
performed.
TI assumes no liability for applications assistance or the design of Buyers products. Buyers are responsible for their products and
applications using TI components. To minimize the risks associated with Buyers products and applications, Buyers should provide
adequate design and operating safeguards.
TI does not warrant or represent that any license, either express or implied, is granted under any patent right, copyright, mask work right, or
other intellectual property right relating to any combination, machine, or process in which TI components or services are used. Information
published by TI regarding third-party products or services does not constitute a license to use such products or services or a warranty or
endorsement thereof. Use of such information may require a license from a third party under the patents or other intellectual property of the
third party, or a license from TI under the patents or other intellectual property of TI.
Reproduction of significant portions of TI information in TI data books or data sheets is permissible only if reproduction is without alteration
and is accompanied by all associated warranties, conditions, limitations, and notices. TI is not responsible or liable for such altered
documentation. Information of third parties may be subject to additional restrictions.
Resale of TI components or services with statements different from or beyond the parameters stated by TI for that component or service
voids all express and any implied warranties for the associated TI component or service and is an unfair and deceptive business practice.
TI is not responsible or liable for any such statements.
Buyer acknowledges and agrees that it is solely responsible for compliance with all legal, regulatory and safety-related requirements
concerning its products, and any use of TI components in its applications, notwithstanding any applications-related information or support
that may be provided by TI. Buyer represents and agrees that it has all the necessary expertise to create and implement safeguards which
anticipate dangerous consequences of failures, monitor failures and their consequences, lessen the likelihood of failures that might cause
harm and take appropriate remedial actions. Buyer will fully indemnify TI and its representatives against any damages arising out of the use
of any TI components in safety-critical applications.
In some cases, TI components may be promoted specifically to facilitate safety-related applications. With such components, TIs goal is to
help enable customers to design and create their own end-product solutions that meet applicable functional safety standards and
requirements. Nonetheless, such components are subject to these terms.
No TI components are authorized for use in FDA Class III (or similar life-critical medical equipment) unless authorized officers of the parties
have executed a special agreement specifically governing such use.
Only those TI components which TI has specifically designated as military grade or enhanced plastic are designed and intended for use in
military/aerospace applications or environments. Buyer acknowledges and agrees that any military or aerospace use of TI components
which have not been so designated is solely at the Buyer's risk, and that Buyer is solely responsible for compliance with all legal and
regulatory requirements in connection with such use.
TI has specifically designated certain components as meeting ISO/TS16949 requirements, mainly for automotive use. In any case of use of
non-designated products, TI will not be responsible for any failure to meet ISO/TS16949.
Products
Applications
Audio
www.ti.com/audio
www.ti.com/automotive
Amplifiers
amplifier.ti.com
www.ti.com/communications
Data Converters
dataconverter.ti.com
www.ti.com/computers
DLP Products
www.dlp.com
Consumer Electronics
www.ti.com/consumer-apps
DSP
dsp.ti.com
www.ti.com/energy
www.ti.com/clocks
Industrial
www.ti.com/industrial
Interface
interface.ti.com
Medical
www.ti.com/medical
Logic
logic.ti.com
Security
www.ti.com/security
Power Mgmt
power.ti.com
www.ti.com/space-avionics-defense
Microcontrollers
microcontroller.ti.com
www.ti.com/video
RFID
www.ti-rfid.com
www.ti.com/omap
TI E2E Community
e2e.ti.com
Wireless Connectivity
www.ti.com/wirelessconnectivity
Mailing Address: Texas Instruments, Post Office Box 655303, Dallas, Texas 75265
Copyright 2015, Texas Instruments Incorporated