in need help understanding i2c functionality

Posted on
  • I would like to interface with the atlas-scientific ezo pH sensor using the i2c bus. The data sheet(http://www.atlas-scientific.com/_files/_datasheets/_circuit/pH_EZO_datasheet.pdf?) for the pH sensor recommends the usage of a 4.7k resister for the pullup resisters. Does the microcontroller dictate the resister value or does the device you want to connect to dictate the resister value? Also, what is the functionality of pull up resisters and how do you calculate a value of a pull up resister?

  • Regarding the pull-up (or pull-downs) are used to eliminate noise on the line when the line is not pulled either down or up by any of the devices on the bus. Noise may - and most likely will - reach levels that unintentionally trigger listening inputs when not taken care of. Good info to find at: http://i2c.info or http://www.i2c-bus.org/.

    After Manual switching to I2C mode, connect it as described in posts http://www.espruino.com/MPL115A2 and http://www.espruino.com/MCP4xxx.

    The posts suggests 4.7K..10K. The lower the resistance, the more the device has to drive, the better the noise immunity, and the higher the power consumption. Both Espruino and atlas-scientific are both able to drive 4.7K, so go for it.

  • Per I2C standard, I2C devices can (well, should) only pull the I2C lines LOW themselves - this makes the parts cheaper to produce, and also makes interfacing between devices running on different voltages a bit easier. But, it also means that neither device is responsible for bringing the SDA/SCL lines high - and something's gotta do that.

    That's the role of pullup resistors.

    You need 2, one between VCC and SCL, the other between VCC and SDA. All these do is ensure that between bits, and between transfers in general, these two wires are kept around VCC, making them a logical HIGH value. (They "pull" the voltage "up", hence pull-up). The value needs to be low enough that they're effective at pulling the voltage up, but not so low that the devices have trouble overcoming them to send data. 10k and 4.7k are very commonly used, and in most cases, any value around there will work. When you need a pullup or pulldown resistor for other purposes, these are also typically good default choices.

    There are formulas that can be used to calculate the necessary value, but their use is rarely necessary for normal low-speed I2C (it becomes more relevant at higher speeds).

    Here's what I think the official ones are from the I2C spec:
    Rmin = (Vcc-0.4v)/3ma (ie, the pullup can't have such a low resistance that you have to sink more than 3ma to keep it below 0.4v, ie, logical LOW). This minimum is ~1k at 3.3v, ~1.5k at 5v.

    Rmax = 1000ns/Cbus for 100khz, 300ns/Cbus for higher speeds, where Cbus is the capacitance of the bus - counting both the inputs to devices on it, and the wires themselves (it needs to be able to overcome the capacitance of the bus and get the voltage back to a logical HIGH between bits fast enough to be ready for the next bit).

    Note also that when you buy modules with the sensor and some supporting components on it, they very often include the pullups.

  • Slightly off topic but when should I use the "input_pullup" option of pinMode? This is used in the keypad tutorial and seems to replace the need for using a physical pullup resistor. Could someone explain please.

  • You use them for the same purpose: not have open, floating inputs, (too) sensible to noise (on inputs driven by open-collector(-like) outputs of driving ICs - which all I2C senders are, or on inputs driven by (diode-)matrix-encoders (like in keypad) on scanning). I used pull-downs to clear lingering capacities before reading from resistive touch screen - see http://forum.espruino.com/conversations/256122/, in particular post http://forum.espruino.com/comments/11892295/

    For use with I2C: first of all, these pull-up (or pull-down) resistors are 30..40k. If you write you own I2C you can control the pins to use them (when reading). With low speed and short bus and limited noise it may work (see @DrAzzy 's explanations in 3rd and 2nd last paragraph).

  • input_pullup and input_pulldown are very appropriate for general purpose pullup/pulldowns.

    I'm not sure whether you can set pinMode() to input_pullup and have that replace the I2C pullups though - I'd never seen it done on the Espruino, so I was under the impression that it didn't work for some reason.

  • @DrAzzy, unfortunetly the module that I purchased didn't come with a 4.7k resister. I also forgot to ask how do I properly attach a pullup resister?

    UPDATE
    Nevermind the how to attach a pullup resister question, I found the answer at: http://www.espruino.com/MCP4xxx

  • Thanks for the answers everyone :)

    Just to clear up about input_pullup: That is when the output is a GPIO input (rather than connected to an 'alternate function' like I2C). I believe the chip itself uses the data output value to dictate whether to pull up or down, which makes it difficult (if not impossible) to use it for anything that's also an output (like I2C).

    I tried to use it for OneWire, but had very little luck getting it to work. My understanding is that the F4 chips (like the one in Pico) have separate registers for pullup/pulldown, so they may be able to use the pullups in conjunction with I2C - I need to look into that a bit more, but I don't believe this is possible with the normal Espruino board.

  • "I'm not sure whether you can set pinMode() to input_pullup and have that replace the I2C pullups though"

    The weak pullups in the chip are typically about 40k ohms so are 10 x greater that what you would want as i2c pullups, This value of 40K was taken from the STM data sheet

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

in need help understanding i2c functionality

Posted by Avatar for d0773d @d0773d

Actions