Understanding I2C Communication and How to Debug the I2C Protocol?

What is the I2C protocol?

History of I2C

When connecting multiple devices to a microcontroller, the address and data lines of each device were conventionally connected individually. This would take up precious pins on the microcontroller, result in a lot of traces on the PCB, and require more components to connect everything together. This made these systems expensive to produce and susceptible to interference and noise.

To solve this problem, Philips developed Inter-IC bus (inter-integrated circuit), or I2C, in the 1980s. I2C is a low-bandwidth, short distance protocol for on board communications. All devices are connected through two wires: serial data (SDA) and serial clock (SCL).

 

I2C two wire bus layout.

 

The I²C communication protocol uses only two bidirectional open collector or open drain lines, Serial Data Line (SDA) and Serial Clock Line (SCL), pull up with resistors. Traditionally, typical voltages used have been 5V or 3.3V; however, recently 2.5V, 1.8V, and 1.2V have become more common.

I2C Theory of Operation

I2C is a master/slave protocol. The master initiates the communication and the slave responds accordingly. The sequence of events is:

  1. The Master device issues a start condition. This condition informs all the slave devices to listen on the serial data line for instructions.
  2. The Master device sends the address of the target slave device and a read/write flag.
  3. The Slave device with the matching address responds with an acknowledgement (ACK) or negative acknowledgement (NACK) signal.
  4. Communication proceeds between the Master and the Slave on the data bus. Both the master and slave can receive or transmit data depending on whether the communication is a read or write. The transmitter sends 8-bits of data to the receiver which replies with a 1-bit acknowledgement.
  5. When the communication is complete, the Master issues a stop command indicating that communication is complete.

 

I2C theory of operation

 

The I2C protocol can handle up to 128 slave devices. It is a synchronous bus which means all devices on the bus are synchronized to a central clock signal. I2C is also a serial bus as opposed to a parallel bus so all data travels over a single data line and not over multiple wires.

I2C Speeds

I2C has five defined speeds: Standard, Fast Mode, Fast Mode Plus, High Speed, and Ultra-Fast Mode.

Maximum Speed:

  1. Standard = 100 kHz
  2. Fast Mode = 400 kHz
  3. Fast Mode Plus = 1 MHz
  4. High Speed = 3.4 MHz
  5. Ultra Fast Mode = 5 MHz

 

I2C is often used in camera lenses.

 

Where is the I2C Protocol Used?

Common I2C Device

Some common devices that typically run I2C are OLED displays, accelerometers, certain pressure/temperature sensors, and EEPROMs. Anywhere a relatively simple transaction occurs is a great place to use I2C. Because I2C is a two-wire bus, if space is limited I2C is a good fit because of the small footprint required to execute commands. This is obviously true when thinking of a small pressure sensor. A pressure sensor is not an extremely complex system to run and sensors are typically very small. Because of this, I2C is an excellent protocol choice.

Specific I2C Applications

I2C is used in a variety of different applications as one of the most popular serial protocols. From IoT to programming memory devices, I2C is used almost everywhere. Since I2C requires only two wires, it is well suited for boards with many interconnected devices. This helps reduce the cost and complexity of the circuit as additional devices are added to the system. Common applications include serial data transfer to/from peripherals, programming EEPROMs, and retrieving polling/receiving sensor data.

 

Digi-Key I2C search. Devices that use I2C.

 

Working with the I2C Protocol

I2C Advantages

Typically, users of the I2C protocol are also familiar with the SPI protocol. I2C and SPI are very similar in nature but act different in actual use. Both of these protocols are used on simple applications and they both provide benefits and limitations when compared to each other.

Some benefits of I2C over other serial protocols include:

  • Requires only two wires for relatively small system footprint
  • Unique device addressing
  • ACK/NAK allows for confirmation of successful transfers
  • Ability to add multiple masters and slaves for increased functionality
  • Simple master and slave relationship
  • Industry standard and widely deployed
  • Adaptable to work with both fast and slow ICs

I2C Limitations

I2C communication doesn’t have too many disadvantages. The fact that the protocol has been in use for over 30 years highlights this fact. However, it suffers from a few minor limitations.

Some of the limitations of I2C over other protocols include:

  • Possibility of address conflicts due to the many slave/master devices on the bus
  • Slower speeds when compared to faster protocols such as SPI
  • Data frame is limited to 8 bits.
  • Requires more space due to the need for pull-up resistors
Using a mac to debug embedded system

 

I2C Debugging Tools

When working with I2C it is important to have the right set of tools handy to ensure implementation of designs is done properly. The addition of oscilloscopes and logic analyzers are always helpful in the development process. However, these options can be cost prohibitive.  There are less expensive tools available, some are software based and others are hardware based.

An oscilloscope is an excellent tool to use when implementing and designing the I2C bus. A scope will provide a breadth of insight into the bus including the electrical and signal characteristics of a design. However, sometimes a scope is too expensive and out of reach for some developers. There are some great alternatives available for scopes, both in the hardware and software realm. Tools such as host adapters, programmers, protocol analyzers (hardware and software based), and logic analyzers are a few of the tools available.

The feature set of each of these devices ranges dramatically. Some tools encompass a breadth of capabilities whereas some focus on specific tasks such as only programming or sniffing.

Latest Developments in I2C

I2C has evolved in terms of speed over the past two decades. When introduced the only speed available was a standard mode maxing out at 100 kHz. As technology moved toward smaller and faster, I2C was forced to adapt. Over the years new modes were introduced and now I2C reaches speeds of up to 5 MHz.

The latest evolution of the protocol is a new bus called I3C. I3C takes what developers love about I2C and SPI and combines them in a conglomerate protocol. The I3C standard combines the advantages of the simplicity of the I2C two wire bus and the speed of SPI. The protocol is capable of speeds up to 12.5 MHz, more than doubling the speeds of the ultra-fast mode on I2C. I3C is also backwards compatible with most I2C applications.

I3C is still in the early stages of development and its applications do not range in the size and breadth of I2C or SPI. However, I3C is starting to crop up in engineering circles and making its way into future projects and implementations.

How Total Phase Interfaces with I2C

Total Phase has a variety of different tools that interface with the I2C protocol. All of the I2C tools that Total Phase offers will fall into two different categories: host adapters and protocol analyzers. Host adapters allow users to interface directly with an I2C system and program I2C data. Whereas protocol analyzers do not interact with the data but instead monitor traffic that is happening on the bus. Host adapters allow users to interact with the data while protocol analyzers allow the user to non-intrusively monitor the data in real time.

Total Phase Host Adapters

Total Phase offers two host adapters for I2C: the Promira Serial Platform and Aardvark I2C/SPI Host Adapter. Both of these tools interface with the I2C protocol with the main differentiators being in terms of speed and expandability.

Promira Serial Platform

The Aardvark I2C/SPI Host Adapter is able to act as an I2C master and slave up to 800 kHz.  If higher speeds are required, the Promira platform becomes the better option with the ability to signal at up to 3.4 MHz. With this type of speed, the Promira platform is better suited to interfacing with high-speed I2C devices.

The Promira platform also has an integrated level shifter built into the hardware allowing it to change voltage levels via software control, while the Aardvark adapter is limited to 3.3V (5V tolerant) without external accessories.  The Promira platform offers up to 12 GPIOs whereas the Aardvark adapter can enable up to 6 GPIOs.

Promira Applications Comparison Chart

 

Benefits of the Promira Serial Platform

The Promira Serial Platform is the most versatile tool Total Phase has ever made. Being a platform-based tool means that the Promira platform is never limited in capability. If more functionality is needed simply install the correct application to get the feature set needed to complete the task at hand. This is the most flexible development tool around. Some additional features that the Promira platform boasts are:

  • Integrated level shifting - work with signal voltages ranging from 0.9V - 5.0V without additional accessory boards or external cabling.
  • Remote control - run automated tasks over the Ethernet and expand the range of production and prototype units beyond interfacing multiple units to a computer via USB.
  • More target power - provide up to 200 mA to target devices, which in many cases, eliminates the need for an external power source.
  • Download new applications for the Promira Serial Platform - instantly obtain and use more features as project requirements change.

Promira Serial Platform

Benefits of the Aardvark I2C/SPI Host Adapter

The Aardvark adapter is the most popular Total Phase development tool. Engineers love the Aardvark adapter because of its low cost and high performance. When interfacing with I2C, the Aardvark adapter provides a breadth of capabilities.

  • I2C Master clock speed up to 800 kHz
  • I2C Slave clock speed up to 800 kHz
  • Support 3.3V (5V tolerant)
  • Offers up to 6 GPIO
  • Small and compact design

Aardvark I2C/SPI Host Adapter logo

Total Phase Protocol Analyzers

For bus monitoring, Total Phase offers protocol analyzers that provide in-depth information about a specific bus. For I2C, the Beagle I2C/SPI Protocol Analyzer is the perfect fit to analyze I2C data. Simply attach the Beagle I2C/SPI analyzer to an I2C bus and instantly watch as the tool streams, all of the traffic happening across the system in real time. The special thing about this bus analyzer is that it provides real-time analysis of bus data. As communication is happing on the bus the user instantly sees it in the Data Center Software.

Beagle I2C/SPI Protocol Analyzer logo .Data Center Software

Being able to analyze the I2C bus in true real time provides time-saving advantages to the engineer. Unlike many other bus sniffers that require long download times, the Beagle I2C/SPI analyzer gives the user the information as the transaction is taking place on the bus. This gives priceless insights into how the system is working giving engineers greater knowledge on how to debug their systems.

Benefits of Beagle I2C/SPI Protocol Adapter

The Beagle I2C/SPI Protocol Analyzer is a non-intrusive device that monitors the I2C bus up to 4 MHz. The versatile Beagle I2C/SPI analyzer is the ideal tool for the embedded engineer who is developing an I2C, SPI, or MDIO based product. The Beagle I2C/SPI analyzer provides a high-performance bus monitoring solution in a small, portable package. Perfect for engineers in the field and in the lab.

Beagle I2C/SPI Protocol Analyzer logo

For more information on I2C and Total Phase solutions and tools see the below linking articles.