Design calculations for robust I2C communications
I2C 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 I2C 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: I2C Bus topology.
The three considerations when determining the pull-up resistor values (Rp) are:
- Supply voltage (Vdd)
- Total bus capacitance (CBUS)
- Total high-level input current (IIH)
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 I2C specification defines a voltage below VIL, or 30% of the supply voltage, as a logical low and, likewise, above VIH, 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 (IOL) is given for which the voltage drop across the transistor is below the output logical low-voltage level (VOL). Applying Ohm's Law yields Equation 1.
Figure 3: Open-collector topology and equivalent circuit.
For Microchip's I2C EEPROM devices, the VOL specification is a maximum of 0.4V at an IOL 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 (CBUS)
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 (T1) for the voltage to rise to VIL; the time (T2) to rise to VIH; and, critically, the time between these two levels (TR), as shown in Figure 4. Since both VIL and VIH 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 I2C 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, (TR), is 300 ns, given the bus capacitance CBUS of 100 pF.
Equation 3: Minimum pull-up resistance value to meet I2C rise-time standard.
Total High-Level Input Current (IIH)
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 VIH 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 VIH.
It is also prudent to allow some guard margin on the VIH specification, to prevent noise spikes from bringing the voltage below the VIH level. For robust operation in a high-noise environment, the I2C specification recommends 0.2 Vdd as a suitable margin above VIH.
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 I2C EEPROM devices, the maximum input leakage current (IlIEE) is 1 µA. The minimum components for a system are a microcontroller I2C master and an I2C slave device. For this example, assuming a microcontroller with 1 µA input leakage (IlIMCU) and four I2C EEPROM devices, and allowing 100% margin, IIH 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.