I2C SPI USB CAN eSPI Cable Testing View All Videos Quick Start Guides Software Downloads App Notes White Papers User Manuals Knowledge Base Sales Support About Us
Products Blog Sales Support Contact Search
How Does I2C Messaging Work?
Staff Writer

The I2C serial communication protocol was first invented by the Philips Semiconductor company, now known as NXP Semiconductors, in 1982. Now approaching its 40th anniversary, the protocol offers an effective means of short-distance intra-board communication that is ideal for embedded systems and micro-computing applications where the primary design concerns are simplicity and low manufacturing cost.

For embedded systems engineers who wish to design products that use the I2C protocol, programming in the I2C language becomes a necessary skill set. In this week's blog post, we give a basic overview of how I2C messaging works. We will cover the I2C messaging protocol along with key features of the I2C protocol that make it ideally suited for use within your embedded computing projects.

How Does I2C Messaging Work?

We can begin our discussion of I2C with a basic overview of the protocol and its necessary components.

The name I2C is an abbreviation of the term Inter-Integrated Circuit. Here, the term "integrated circuit" essentially means "computer chip". There are many types of computer chips, including those used for processing (CPU), memory (RAM, EEPROM), and other functions. The concept of an inter-integrated circuit protocol tells us that the protocol will allow these individual chips to communicate with each other. In fact, this is exactly what the I2C protocol is used for.

The I2C protocol was designed to enable multiple slave devices (e.g. memory and other peripheral chips) to communicate with one or more master devices (e.g. microcontrollers) over short distances. Importantly, the I2C communication protocol allows for precise communication between multiple slave devices and more than one master device: up to 1008 individual devices can communicate across the same bus. The protocol features that make this possible are the two-wire configuration, slave addressing, and the defined messaging protocols associated with I2C.

The I2C communication protocol conveys messages using a two-wire configuration. The Serial Clock Wire, typically abbreviated SCL, synchronizes data transfer between master and slave devices on the I2C bus by transmitting a clock signal from master device to slave device. In I2C, clock signals are always generated by the master device. The second wire in I2C is known as the Serial Data wire, or SDA. This wire permits bidirectional data transfer between master and slave devices.

Basic diagram of the I2C communication protocol, including master and slave devices, SDA and SCL lines and two-wire configuration.

 

I2C Bus Protocol

A serial communication protocol is essentially a set of rules that defines a shared language and syntax for communication between one or more electronic devices. For any device that uses I2C, data transmissions will always be initiated by a master device. This is because master devices in I2C control the clock line, which synchronizes all data transfers over the bus.

Messages that originate at a master device on the I2C bus follow a predictable format:

  1. To transmit data, the master device must generate a START condition
  2. Following the START condition, a slave address is transmitted to indicate where the message will be sent.
  3. A single bit indicates whether the master device will read or write data from the slave.
  4. An ACK bit is used after each byte of data transferred to acknowledge receipt.
  5. Data is transferred in single-byte (8-bit) blocks, followed by an ACK bit.
  6. When the message concludes, a STOP condition denotes the end of the data transfer.

Start and Stop Conditions

The purpose of a communication protocol is to enable communication between multiple master and slave devices. Communication takes place in a series of messages that are transmitted across the SDA wire. When it is time to send a message, the system must generate a START condition that indicates the beginning of a message and later a STOP condition that signals the conclusion of the message - just like saying "Hello!" and "Goodbye!" at either end of a phone call.

In the I2C protocol, communication lines are "open-drain" and must be activated using a pull-up resistor. When it is time to send a message, a START condition is created by generating a high-to-low change in the SDA line. The pull-up resistor that keeps the SDA line pulled high is released and the line is pulled low - this must be done while SCL is pulled high. In contrast, a STOP condition is generated when the SDA line goes from low to high and the SCL is pulled low.

In any device that uses I2C, pull-up resistors are used to shift the device between four basic modes of operation. While some devices utilize all four, other I2C devices can make use of just one or two. The four potential operational modes are:

  1. Master device transmitting data to a slave device
  2. Master device receiving data from a slave device
  3. Slave device transmitting data to a master device
  4. Slave device receiving data from a master device

Slave Addressing

In the I2C protocol, slave addressing ensures that the correct slave devices are identified as recipients when a master device sends a message. The I2C protocol supports two different formats for slave addressing: 7-bit addressing and 10-bit addressing.

In 7-bit addressing, the address for the slave device is transmitted in the 7 bits immediately following the START condition. An 8th bit acts as a read/write indicator where a 0 indicates that the master wants to write information to the slave and a 1 indicates that the master wants to read information from the slave. 7-bit addressing would typically allow up to 128 devices with unique slave addresses on the bus, but with sixteen 7-bit addresses reserved for special functions the number is slightly lower at 112.

In 10-bit addressing, the full range of 10-bit addresses are available, meaning that up to 1024 slave devices can be connected to the system. Here, a special reserved address is used following the START condition to indicate the presence of a 10-bit address. Following the 10-bit address indicator, the first two bits of the address will be sent, then a read/write indicator, then an ACK. Once the slave acknowledges the master, the next byte transmitted by the master will contain the rest of the slave address.

We've also seen some slave devices that use an 8-bit addressing scheme. While these devices are not following typical I2C conventions, there are still methods of communicating with 8-bit addressed slave devices using the I2C protocol.

Conclusion

As your embedded I2C device increases in complexity, it can become more difficult to streamline your I2C programming and ensure bug-free operation. At Total Phase, we build products that help streamline the error diagnostic and debugging aspects of product development. With our Beagle I2C/SPI Protocol Analyzer, embedded engineers can gain enhanced insight into the internal workings of their devices, rapidly diagnose and fix coding errors, and build better products.

Request a Demo