Skip to content

Make I²C initialisation (Wire.begin()) not slow #1449

Description

@matthijskooijman

I'm running the Wire library on a G030 and noticed that initialization is super slow (Wire.begin() takes 800ms).

Digging into the code, I found i2c_computeTiming() that contains 5 (!) nested forloops and essentially seems to just bruteforce all possible timing combinations or something like that.

Note that I tested on an older version of the Wire library, but looking at the history of that file, I do not think this was fixed in the meanwhile.

Describe the solution you'd like

It seems like it should be possible to be smarter and also a lot faster about this.

Activity

  1. fpistm commented on Jul 20, 2021

    @fpistm
    Member

    Hi @matthijskooijman
    Yes it is slow mainly on small device and it is mentioned in the Wiki:
    https://github.com/stm32duino/wiki/wiki/Custom-definitions#i2c-timing
    Simply define the I2C timing to avoid call this function as explained in the Wiki.
    https://github.com/stm32duino/wiki/wiki/Custom-definitions#example-for-a-stm32f0xx-using-hsi-clock-as-i2c-clock-source-in-varianth

  2. locked and limited conversation to collaborators on Jul 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions