# Design calculations for robust I2C communications

^{2}C bus for internal communications between devices, such as microprocessors, microcontrollers, memories, and other digitally-controlled devices. This bus topology relies on correctly sized resistance pull-ups for reliable, robust communications. Incorrectly sizing these resistors can lead to erroneous bus conditions and transmission errors caused by noise or changes in temperature and operating voltages, and by variations between devices.

I

^{2}C is a two-wire synchronous bus with the SCL line used as a clock, produced by the bus master. The SDA line is used for bi-directional data transfer. The data line is modified while the clock is in specific states, to indicate the start and stop of transmissions, and avoid additional lines.

The I

^{2}C bus is built around open-collector outputs, where a device can pull a line low through a transistor to ground, as shown in Figure 1. This allows easy arbitration over control of the bus, enabling the implementation of bi-directional communications on a single data line and multi-master support. As shown in Figure 1, each line has an external resistor to Vdd, which pulls the line high when released or idle.

**Figure 1: I**

^{2}C Bus topology.The three considerations when determining the pull-up resistor values (Rp) are:

- Supply voltage (Vdd)
- Total bus capacitance (C
_{BUS}) - Total high-level input current (I
_{IH})

Calculating the ideal pull-up resistor values for the following example conditions:

- Supply voltage (Vdd) of 5V
- Clock frequency of 400 KHz
- Bus capacitance of 100 pF

**Supply Voltage (Vdd)**

The I

^{2}C specification defines a voltage below V

_{IL}, or 30% of the supply voltage, as a logical low and, likewise, above V

_{IH}, or 70% of the supply voltage, as a logical high, as shown in Figure 2. A voltage between these two levels leads to an undefined logic level. In reality, the pin will read either logical high or low in this range, but it may vary between devices, with temperatures, voltages, noise sources and other environmental factors influencing the logic levels.

**Figure 2: Specified voltage levels for logical High and Low.**

The supply voltage limits the minimum Rp value for which the bus can be pulled low. A strong pull-up will prevent a device from being able to bring the line sufficiently low, to ensure a logical low is detected. This is caused by the potential divider formed between the pull-up resistor and the on-resistance of the transistor to ground, as shown in Figure 3.

The on resistance of the transistor is not typically specified. Instead, a maximum sink current (I

_{OL}) is given for which the voltage drop across the transistor is below the output logical low-voltage level (V

_{OL}). Applying Ohm's Law yields Equation 1.

**Figure 3: Open-collector topology and equivalent circuit.**

For Microchip's I

^{2}C EEPROM devices, the V

_{OL}specification is a maximum of 0.4V at an I

_{OL}of 3 mA, with other manufacturers devices in a similar range.

Equation 1: Minimum pull-up resistance, allowing the bus to be pulled low.

For multiple devices on the bus, the minimum Rp is determined by the device with the lowest sink current.

**Total Bus Capacitance (C**

_{BUS})On the SCL and SDA lines, the capacitance includes all pins, connections, PCB traces and wire. Combined, this is referred to as the bus capacitance and, for long traces and cabling, this can be significant. The open-collector topology requires the external resistor to pull the line high when released.

The pull-up resistor, coupled with the bus capacitance, has an RC time constant, which limits the rise time. This becomes significant with increasing clock frequencies, as less time is available for the line to rise. If the selected resistor value is too high, the line may not rise to a logical high before it is next pulled low. This is an important consideration for designs that feature many devices on a single bus, which often have higher bus capacitance.

**Figure 4: Charge time for transition between logical Low to High.**

Bus capacitance can be calculated from PCB trace lengths and published pin capacitance, or measured using capacitance probes or smart tweezers. If a precise calculation or measurement of the bus capacitance is not possible, an overestimated worst-case reading should provide a safe maximum-resistance value.

Equation 2 is the general equation used to determine the voltage across a charging capacitive load, as a function of time. This allows for the calculation of the time required for the bus voltage to rise to a particular value, for a specific pull-up resistance and bus capacitance.

Equation 2: General equation of charging a capacitor through a resistor.

We can then calculate the time (T

_{1}) for the voltage to rise to V

_{IL}; the time (T

_{2}) to rise to V

_{IH}; and, critically, the time between these two levels (T

_{R}), as shown in Figure 4. Since both V

_{IL}and V

_{IH}are products of Vdd, the equation is independent of supply voltage, since the Vdd terms cancel out.

The maximum rise time for a variety of operating voltages is specified by the I

^{2}C standard, and is determined by the pull-up resistance. From this time and the bus capacitance, we can calculate the maximum allowable pull-up resistance (Rp). For a 400 kHz clock frequency at 5V, the specified maximum rise time, (T

_{R}), is 300 ns, given the bus capacitance C

_{BUS}of 100 pF.

Equation 3: Minimum pull-up resistance value to meet I

^{2}C rise-time standard.

**Total High-Level Input Current (I**

_{IH})Even when no device is pulling down the line and it is a logical high, current continues to flow through the pull-up resistors. This current is caused by the leakage of the digital inputs of the devices on the bus, from low quality PCB materials and possibly from soldering residues. Some of these cannot be foreseen, but, assuming quality materials and good manufacturing practices, the input pin leakage is dominant.

From Figure 2, the line needs to be above V

_{IH}to be regarded as logical high, when there are no devices pulling the bus low. The leakage current limits the maximum value of Rp, such that the voltage drop across it does not prevent the line from being pulled above V

_{IH}.

It is also prudent to allow some guard margin on the V

_{IH}specification, to prevent noise spikes from bringing the voltage below the V

_{IH}level. For robust operation in a high-noise environment, the I

^{2}C specification recommends 0.2 Vdd as a suitable margin above V

_{IH}.

Equation 4: Additional margin over logical high input level.

The leakage of digital inputs is normally given in the datasheet of devices and, for Microchip's I

^{2}C EEPROM devices, the maximum input leakage current (I

_{lIEE}) is 1 µA. The minimum components for a system are a microcontroller I

^{2}C master and an I

^{2}C slave device. For this example, assuming a microcontroller with 1 µA input leakage (I

_{lIMCU}) and four I

^{2}C EEPROM devices, and allowing 100% margin, I

_{IH}is 10 µA.

Equation 5. Leakage current due to pin leakages for defined bus.

Applying Ohm's law, we can determine the maximum value for Rp that will meet these specifications Equation 6: Minimum pull-up resistance value to ensure logical high.

**Resistor Value Calculation**

From the supply voltage, the bus capacitance and the leakage calculations, we have a range of values for RP.

The 50 KΩ maximum caused by the leakage current can be discarded, since the bus capacitance dominates. As a result, the range of acceptable resistor values is

Designers should choose a value near the middle of the range, to provide as much guard banding as possible. For this example, a 2.2 KΩ pull-up resistor would be ideal.

**Bus Speed vs. Power Consumption**

The pull-up resistors must be reduced in size, when increasing the bus speed or when there is significant bus capacitance. The lower-value resistors cause increased current draw, as each logical low on the bus creates a path to ground, negatively impacting power consumption.

The bus speed can become a trade-off between completing tasks quickly and returning a system to a low-power idle state, versus the additional current draw created by the higher bus speed requirements. For applications with very low power budgets, SPI may be a better-suited bus protocol, since it uses driven lines, instead of open collectors.

System level design and integration challenges with multiple ADCs on single chip

Understanding the basics of setup and hold time

Product How-to: Digital isolators offer easy-to-use isolated USB option

Managing noise in the signal chain, Part 2: Noise and distortion in data converters

War of currents: Tesla vs Edison

Simple reverse-polarity-protection circuit has no voltage drop

Control an LM317T with a PWM signal

Start with the right op amp when driving SAR ADCs

Design second- and third-order Sallen-Key filters with one op amp

555-based class-D headphone driver makes great practice amp

PSoC microcontroller and LVDT measure position

Digital transmission of analog signals through a long distance I2C bus

On the ball in sports with electronics sensor and wireless charging technology