TWI frequencies

Go To Last Post
20 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I want to know the general frequencies used by 100KHz, 400KHz, and 3.2MHz I2C devices in the program code. What are the best frequencies can be used for each of the above with there pull up resistance values.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The speed of the bus is limited by the slowest slave on the bus - so that's what will govern your choice.

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Sorry, I want to know if I have a device that works with 100KHz then what is the frequency for that device can be used it is equal to 100KHz or < 100. And also the pull up because it based on frequency and capacitive bus line.

In the same manner for 400KHz and 3.2MHz.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

newbie-avr wrote:
for that device can be used it is equal to 100KHz or < 100
Anything form 0Hz (though not a lot happens) up to 100kHz. The bus is synchronous so it goes as fast as the SCL pin is pulsed. The 100kHz thing is simply saying "this device may miss SCL/SDA activity if you try to go any quicker than 100kHz"

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You would have to read the datasheet for that specific device.

 

In general, "100kHz" or whatever is the maximum speed at which it can operate.

 

Because it's a synchronous interface, it can be any speed below that maximum limit (unless the particular datasheet specifically states otherwise).

 

EDIT

 

Cliff beat me to it.

 

The full I2C specification is here: https://www.nxp.com/docs/en/user-guide/UM10204.pdf

 

Note that none of this is specific to AVR.

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
Last Edited: Wed. Jul 18, 2018 - 08:38 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

If the device is rated for 100k then thats the speed you use. As far as pull up resistors go 2.2k works with any frequency I have noticed

Jim

If you want a career with a known path - become an undertaker. Dead people don't sue! - Kartman

Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB user

Last Edited: Wed. Jul 18, 2018 - 08:37 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thank you for your reply. What about pull up resistance for 400k and 3.2M?

Last Edited: Wed. Jul 18, 2018 - 08:38 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

newbie-avr wrote:
Thank you for your reply. What about pull up resistance for 400k and 3.2M?

 

What is the capacitance of your I2C lines?

 

To know this YOU must look in the datasheet for all your connected devices, all your interconnecting wires, all your interconnecting connectors, and all your PCB traces. Only YOU know the answer to these questions.

 

 

 

 

#1 This forum helps those that help themselves

#2 All grounds are not created equal

#3 How have you proved that your chip is running at xxMHz?

#4 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand." - Heater's ex-boss

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

" if I have a device that works with 100KHz then what is the frequency for that device can be used it is equal to 100KHz or < 100."

 

It is <= 100 khz in this hypotheses.

 

" And also the pull up because it based on frequency and capacitive bus line."

 

Do you have instruments to measure bus capacitance?

 

https://fr.wikipedia.org/wiki/I2... made a guess about bus capacitance, and tabulated pull up resistances.

Two things might be noticed :

* pull up resistances are common to the bus. If you have prebuilt modules (are often cheaper than separated pieces one has to solder) , often manufacturer made a wise bet about bus capacitance , and pull ups will be paralleled (eat some current; no issue with rise time)

 

* https://playground.arduino.cc/Ma... links to many avr i2c scanners, among which

 

*a) I used (and was very satisfied with its scanner) Nick Gammon's page about I2C

*b) I begin to use (maybe I ll decide wether I am satisfied or not ... within 6 months) RobTillart multispeed scanner (goes up...to 400 Khz).

 

Oh, BTW : do you really need all these speeds (SantaClaus sent you a lot of I2C circuits at different speeds? Then, the slowest one drives the clock -else, without trick, slowest could not decode adresses -even to discard-)

 

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

So you can get all hung up with a load of measurements & calculations:

Brian Fairchild wrote:
To know this YOU must look in the datasheet for all your connected devices, all your interconnecting wires, all your interconnecting connectors, and all your PCB traces. Only YOU know the answer to these questions

dbrion0606 wrote:
Do you have instruments to measure bus capacitance?

 

Or just take Jim's advice in #6:

jgmdesign wrote:
2.2k works with any frequency I have noticed

 

 

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

There are a lot of options :

 

a) buy a presoldered module (cheaper than sum of components); would even be better -cheap and useful-  if it had some use ( general I2C wiring is not a way to go to Nirvana)

 

b) look at a commercial module schema (Lady Ada, sparkfun publish them) and notice the pull out

 

c) ask wikipedia

 

d) avoid cut and pasting : is redundant, makes reading difficult (a great way to keep low level expertise and to punish people buying avrs)

 

 

No need for cut and pastology, though it gives some ..... experts some expertise in other people talents  (and commercial modules have ... more experience than #6) ; just some common sense

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The issue of pull-up resistor for TWI/I2C comes up with moderate regularity, here. Let me add a couple of observations.

 

1.Both data and clock lines idle at logic high. Thus, the pull-up resistors ONLY consume power during a transfer. If transfers are relatively infrequent, then they do NOT add much to the net energy use.

 

2. The required resistor size depends on the clock rate and the bus capacitance. The signal rise time has to be less than one half the clock period for the signals to reach full logic high. That is because the resistors are the only things pulling the line high. On the other half cycle, a transistor pulls down to ground, and that is a lot faster. As a result, the longer the trace, the fatter the trace, the more ground plane under the trace, the more devices hanging on the bus, the smaller the resistors need to be. 

 

3. Adding an oscilloscope probe or logic analyzer probe to a TWI bus adds capacitance to the bus. So, if it is fast enough as seen on one of these, then it will be even a bit faster when the probe is removed. 

 

4. It is quite difficult to estimate bus capacitance. Yes, you can say that it is "at least" some value by adding up the port capacitances of each bus device. Yes, there are tools to estimate trace capacitance, but I would consider them "approximators", at best. The "official" I2C spec sheet actually says quite a bit about this. It can be found at: https://www.nxp.com/docs/en/user...

 

5. Pull-up resistors are a balancing act. You want to make them as large as possible to reduce power consumption and you want to make them as small as possible to maximize speed. In the end, you really optimize transfer speed. However, the electron gods play a trick on you. IF the pull-ups are optimized to that the rise time is just 1/2 the clock period, a given transfer will take the same energy no matter what the clock speed! That is because a fast transfer draws current for less time. SO, choose the speed you need to accomplish the task, optimize the pull-up resistors, and be done with it all.

 

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I would just add to West Coast Jim's observations that the speed only needs to be fast enough to comfortably accomplish the task at hand, so if an I2C sensor is sampled only once per second, does it make sense to use the highest bus speed possible?   Murphy lives in the real world, plan for it and be generous with your spec's.

 

Jim

 

Click Link: Get Free Stock: Retire early!

share.robinhood.com/jamesc3274

 

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The idea of an oscilloscope is a bright idea; it is very useful for understanding (but one should have at least 2 channels, SDA and SCL).

There are however some pitfalls :

* Does OP have any knowledge in electronics? It takes some time to understand which buttons to activate.... -this seems trivial for some people, but not for a beginner

* to have nice curves, 10-15 samples per period should be taken; for a 100Khz, it means 1Msamples per second; cheap oscilloscope , like a PC soundcard + a PC sample at a much lower speed ; gabotronics mixed signal  scope,  samples at 2 Msamples per second, with an analog bandwidth of 200Khz -is a low pass-; these 2 "solutions must be avoided, if one wants to see rise/decay  times;

 

* typical rise time, with a 2 Kohm pullup ( a conservative value : sparkfuns uses 4.7 K, jgmdesign  recommands 2k)  resistor and a 100 pf capacitance (breadboards are not far from this stray capacitance) are 2E3*100E-12 == 2E-7 seconds: if one wants to describe with more accuracy the rise/decay curve, may be 5 samples should be taken within 0.2 microseconds ; this leads to 25 Msamples per second (more expensive oscilloscopes)

 

* logical analysers can sample faster than oscilloscopes (with the same price), but cannot display rise/decay curves... which is complicated when  choosing a pullup resistor.

 

If OP is a beginner, he cannot discover at the same time avr programming, oscilloscope configuring and interpreting (and maybe basic -or not- electronic).

 

Maybe best (less bad?) solution is to buy an Arduino and a I2C peripheral (there are thermometers, screens, accelerometers, barometers, ..., all are on PCB, with pullup resistors -and cheaper than sum of components-  and have demo programs ) and play with them; then he could make a working thing evolve to the "plain avr" world, which is more complicated, but the evolution could be slower and more comfortable....

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Sigh....

 

I still live in the analog scope world where you don't need to worry about sample rate. The scope transient response has a simple dominant one-pole RC characteristic (unless we are talking about 50MHz or above bandwidths). Two cascaded simple RC poles combine as the square root of the sum of the squares. Done with it all.

 

Jim

 

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Just a note to the OP.
You do not need a scope, capacitance meter or logic analyser to determine the resistor value. For most cases 4.7k and 10k will work just fine. Especially if your devices are all on the same PCB. I mentioned 2.2k only from experiences in the past where I was driving about 8 metres of connection wire in a slightly noisy environment and 2.2k provided the best performance. Since then I have always used 2.2k and never had any issues.

As long as you keep things under say 1 metre 4.7k should work for most applications. If you aren't sure then just use my suggestion of 2.2k.

Jim

If you want a career with a known path - become an undertaker. Dead people don't sue! - Kartman

Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB user

Last Edited: Wed. Jul 18, 2018 - 09:15 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

" 4.7k should work for most applications. If you aren't sure then just use my suggestion of 2.2k."

4.7k are used by Sparkfun in their presoldered cards.

To get 2.2k, a solution is to parallel 4.7k ... by buying two cards (with different functions and adresses, else it would be boring or terrible; but there are many interesting functions)

Among interesting functions, very few (monochrome screens?) need fast I2C.

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Agree -

 

The OP does not need an oscilloscope. I was trying to describe HOW one can optimize the resistor values for a TWI system in a specific system.

 

Practically, meaning "it works for most cases", jgm's suggestion is quite useful. I tend to use somewhat smaller resistors, but that is a matter of personal preference. 

 

I think that the OP was concerned about higher speeds. Simply scale the resistors in inverse proportion to the speed. That is, if you double the speed, halve the resistor values. Be aware that there is a specified MINIMUM resistor value (depending on the power supply voltage). The NXP document I linked covers these matters in exquisite detail. IT is, however, not written for the newbie, but if you have the equivalent knowledge to a first year electrical circuits class, you should be able to handle the details.

 

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I still live in the analog scope world where you don't need to worry about sample rate.

Several years ago I bought a pallet of these 4 chan digital scopes...really nice, since they include a full analog mode, with a nice noise-free trace. Includes buttons & knobs you can use. I often prefer to my higher end color Tek digital scope.