How to configure pull-up resistors for i2c?

Posted on
  • Hi,
    I'm using the temperature and humidity I²C sensor HTU21D in my current experiments. The bought Sparkfun HTU21D breakout had no prewired pull-up resistors on SCL or SDA. They are on the board but initial not connected. To enable I could bridge a solder jumper. Ok, long background...

    I would prefer to use the MCU-internal pull-ups and tried the following code which does not work:

    pinMode( B8, "input_pullup" );
    pinMode( B9, "input_pullup" );
    I2C1.setup( {scl: B8, sda: B9 } );
    

    Is this possible to use the MCU-internal pull-ups with i2c or can they only be used for simple input pins?

  • The MCU internal pullups are not nearly as strong as is specified by the I2C spec. (The same is true on Arduino - it's not as far off, but it's still out of spec).

    You might be able to get the desired behavior by setting the appropriate registers with poke - but as I said above, I don't expect it would work.

    I always use external pullups when working with I2C.

  • If you accept to set up a reduced I2C speed, such as <10kHz, the internal pull-ups should work well. Anyway, as @DrAzzy said, the best solution is by far, connecting external pull-ups, as you don't want to encounter I2C errors, they are rather boring to handle.
    Be careful by using the poke method (http://www.espruino.com/Reference#l__glo­bal_poke32), this is not safe at all...

  • I remember having some trouble with the internal pullups for I2C, and not being able to get it to work (but that could have been on the F1-based original Espruino, not the Pico).

    If you wanted to try it, you'd have to use poke to change the value in the pin's registers though, as I believe I2c needs to be in af_opendrain mode, but pinMode won't do that while also providing a pullup.

    poke itself isn't desperately dangerous - you can crash Espruino so it needs a reboot, but it would be quite hard to cause physical damage.

    ... but in short, I'd say external pullups are easier - especially if it's just a solder jumper!

  • Thank you for the hints. First I thought it would be an Espruino/JavaScript API question and totally forgot to think about the electrical part.

    The I²C specification says that the minimal pull-up is a little less than 1k with Vdd=3.3V and the maximum value depends on bus capacitance. Many breakouts have 4.7k so it's possible to use four devices (with pullups) in parallel without breaking the spec.

    There is detailed application note from TI: http://www.ti.com/lit/an/slva689/slva689­.pdf

    On the other side I have to use a much lower value than the typical 40k MCU-internal resistors for 400kHz - I understand now.

    So I found my stability problem with the MCP9808 http://www.espruino.com/MCP9808. My sentence

    The sensor can handle bitrates up to 400000 but I had stability problems with this.

    can be removed from the documentation.

    BTW: Why are there "°"s instead of ° on the website?

    Again, thanks for the Tips.

  • take a look at this test results with different pull up resistors

    http://dsscircuits.com/articles/effects-­of-varying-i2c-pull-up-resistors

  • Glad you got it sorted!

    I've just filed a bug for the strange degree symbol - I think it's a UTF-8 issue on the website.

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

How to configure pull-up resistors for i2c?

Posted by Avatar for luwar @luwar

Actions