|

I2C is a popular communication protocol in embedded systems. When interfacing with the slave device a pull-up resistor is needed on each bi-directional line. One common question that arises is "what size pull-up resistor should I use?". Instead of going through a bunch of theory and calculations I thought it would be easier to show what happens to the signals when different resistor values are used.
Since the Arduino is a popular micro-controller among hobbyists we'll use it for the following examples. We'll interface the Arduino to a DS3231 Real Time Clock, which is a 5 volt device. We'll also look at the effects on the signal with varying speeds of I2C (100 and 400kHz clock signals).
We'll set up our oscilloscope to measure rise time, frequency and peak voltage. Frequency? Why do we want to measure frequency, I thought the clock frequency was running at 100kHz...well let's just see what the scope says. Since the capacitance is roughly the same for the SDA (data) and SCL (clock) lines we'll only vary the resistance on the SCL line and keep a standard 4.7k ohm resistor on the SDA line. It's just easier to analyze a repetitive clock signal on the oscilloscope than a data pattern.
Let's take an initial reading using just the Arduino's internal pull-up resistors. As you can see in Figure 1 the clock signal has a very long rise and only reaches a maximum voltage of 3.76 volts before falling back to zero. While the circuit does function I wouldn't want to rely on it outside the lab. As you can see the frequency measured is closer to 87kHz due to the slow rise time. The circuit still works but if your application is time sensitive it's not generally a good idea to use the internal pull-up resistors. Anyway let's disable the Arduino's internal pull-up resistors and install our own pull-ups and see how they affect the signal. We'll start with a 68k ohm resistor followed by 47k, 33k, 10k, 6.8k,4.7k, 3.3k, 2.2k and finally 1.5k. As you can see in Figure 2, the signal eventually takes on a square shape which is what we like to see. Notice how the measured frequency approaches our desired clock frequency between 33k and 10k ohms. You can also see how the rise time decreases as our resistance decreases. As you can see, 4.7k yields a good looking signal with a rise time around 1 microsecond . You'll find that 4.7k is a pretty common resistance used in a lot of single slave setups. Of course as you add more and more devices to the lines the bus capacitance will increase and that means you'll have to start decreasing your resistance (t = RC) if you want to maintain your signal integrity. Each design will be unique and the capacitance referenced in the datasheet is not guaranteed so it's always good practice to look at the signals on an oscilloscope. So why not just use a very low resistor to start off with, shouldn't that reduce the rise time to give us the squarest signal possible? Well yes and no. The I2C standard sets some limits that need to be followed, luckily these limits help us narrow the range of resistance values. A simple formula for calculating the smallest pull-up resistor is Rp = (Vcc - 0.4)/3mA, which for a 5V system comes out to be about 1.5k ohms. The formula for calculating the largest resistor is actually based off a maximum rise time for standard mode (100kHz) which is 1 microsecond and that formula is Rp = 1us/Cb, where Cb is the total bus capacitance for one signal line. So for our example the total bus capacitance would be about 20pF (Arduino is 10pF, per the datasheet, and the DS3231 is also 10pF per the datasheet), which yields a high side value of 50k ohms. Obviously adding more DS3231 RTC's to the line will change the largest allowable resistor that we should use (1 more drops it down to 33.3k, another one drops it to 25k, etc...). It's important to note that each I2C device will have it's own capacitance so always look at the datasheet so you know what that value is.
Next, we'll use the same circuit, but this time let's switch from Standard mode to Fast mode (400kHz). As you can see is Figure 3 the rise time is very slow with respect to the clock frequency. The frequency of the clock is measured at around 171kHz, which is significantly slower than the desired 400kHz. Also notice how the peak voltage only reaches 3.28V before switching to the second half of the duty cycle. We're going to repeat the same test from above using the same resistors. Before we begin let's take a look at the calculations for determining upper and lower pull-up resistor values. The calculation for the lowest value pull-up resistor is the same as above, yielding 1.5k on the low side, however the maximum rise time for Fast mode is reduced from 1 microsecond to 300 nanoseconds. As you can see, using the formula and substituting the maximum bus capacitance of 400pF results in an upper limit resistance of 750 ohms which is actually lower than the lowest value resistor from the first calculation. For this reason the maximum recommended bus capacitance is dropped down to about 200pF with a 5 volt system. So make sure you keep close watch on the total bus capacitance as you're building your circuit. So lets install the resistors and see how they affect the signal quality (Figure 4). Notice how the measured clock frequency doesn't approach 400kHz until we transition from 6.8k to 4.7k ohms. You can also see how the signal takes on a good shape once we transition from 2.2k to 1.5k ohms.

|
Comments
this is right practice for understanding as well as design.
good informative.
good
keep it up.
Thanks,
PA
It helps a lot to he designers and embedded developers
Thanks & regards
Srinivas
Thank you for your work!
what are you doing now?
just want to know if you don't mind.
thanks again for knowledge sharing.
It is very much easy to understand..
Thanks a bunch!!
Varying pull up resistor does it effect fall time of the bus?? It will be great if you can show fall time variations also.
i become understand about what is pull up resistor effect..
if I have a Sensor that supports 400khz i2c, I should take 2,2k resistors and then its also no problem to run at slower 100khz bus speed with them ?
STM32 MCU @ 3,3V VDD.
And I would take 100ohms as series resistor.
Is that ok ?
I calculated my RP minimum is 967ohms ~ 1k.
Is it better to with 1,5k then ?
1) What version of the Wire library are you using?
2) What code was being run to generate the continuous clock (SCL)?
3) How does one "vary the speed" as you say?
I was expecting that the rise time, obviously, will increase, but that should not affect the Clock HIGH & LOW Periods
Actually the frequency decreases with an increase in R. It typically affects the clock high period. Remember, if you have a 50% duty cycle and your resistance is too high, it will take longer for the circuitry to reach the defined HIGH state before it can switch to go LOW again. Since the duty cycle on the LOW side is not compensating for increased rise time you will see a net overall decrease in frequency.
But I still have one doubt.
Ideally, the logic which drives the SCL Open-Drain/OC pads need to do only the following:
1. Let the line charge to VDD through Pull-up for a fixed amount of time- the HIGH period
2. After this fixed HIGH period is elapsed, enable the drive-down transistor for a fixed amount of time- the LOW period
-Repeat this 'n' times for n SCL cycles
-----------------
According to my above assumptions, the HIGH Period & hence, Positive duty cycle should remain same for whatever pull-up usde.
The only change to be observed is the voltage to which the SCL line is charged at the end of the HIGH Period will decrease as we go on increasing the pull-up (as rise time/RC time constant increases).
----------------------
From your explanation, it seems more like whatever logic that drives the SCL pads is sensing the voltage on the line OR in short, there is some kind of feedback to the logic as regards to the line voltage.
i.e, during the HIGH period, it (the logic) continuously senses the SCL line
And, only when it senses a voltage greater than some threshold, it ENABLES the Drive-down section of the pad.
What do you think is happening ?
RSS feed for comments to this post