Skip to content

Module begin() silently resets a user-set I2C clock to 100 kHz on UNO R4 #69

Description

@dcuartielles

Summary

When a sketch sets a custom I2C clock (e.g. Wire1.setClock(400000)) and then
brings up Modulino modules, the clock is silently reset to 100 kHz. The sensor
modules respond correctly but much more slowly, with no error or warning.

There are two contributing layers:

  1. ModulinoClass::begin() sets _wire->setClock(100000) itself.
  2. Each sensor module's begin() then re-initialises the bus through its underlying
    library, which calls _wire->begin(); on the Renesas core TwoWire::begin()
    unconditionally calls setClock(I2C_MASTER_RATE_STANDARD) (100 kHz). E.g.
    ModulinoMovement::begin()LSM6DSOXClass::begin()_wire->begin().

So any setClock() the user makes before the module begin() calls is undone.

How it manifests

An 8× ModulinoMovement network through a TCA9548A mux on a UNO R4 WiFi ran at
~10 Hz instead of the expected ≥30 Hz; per-sensor read latency was ~11 ms at the
unintended 100 kHz vs ~503 µs at 400 kHz (~22× slowdown). No error is reported.

Workaround (current)

Call setClock() after all module begin() calls:

Modulino.begin();
ModulinoMovement imu;
imu.begin();                 // resets clock to 100 kHz
Wire1.setClock(400000);      // re-apply AFTER begin()

Suggestions

  1. Document that setClock() must be called after all module begin() calls
    (this is non-obvious and easy to get wrong with multiple modules).
  2. Consider letting users specify a target bus clock that Modulino re-applies after
    each inner begin(), since the reset originates in the underlying libraries.
  3. The root cause is the underlying sensor libraries calling _wire->begin() in
    their begin(). Filed for the LSM6DSOX case at begin() calls Wire.begin(), silently resetting the I2C clock to 100 kHz on Renesas (UNO R4) Arduino_LSM6DSOX#53; the same
    pattern is present in Arduino_HS300x, Arduino_LTR381RGB, and
    Arduino_LPS22HB.

Environment

  • Board: Arduino UNO R4 WiFi (Renesas RA4M1), core arduino:renesas_uno 1.6.0
  • Library: Arduino_Modulino 0.8.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions