[LIBMAPLE Wire] setClock doesn't apply speed change if called after begin()

Working libraries, libraries being ported and related hardware
Post Reply
victor_pv
Posts: 1654
Joined: Mon Apr 27, 2015 12:12 pm

[LIBMAPLE Wire] setClock doesn't apply speed change if called after begin()

Post by victor_pv » Wed Sep 13, 2017 9:05 pm

I discovered a few days ago when using an i2c EEPROM library, that the method setClock does not apply a speed change to the i2c peripheral, instead only changes a configuration value in the library, and that configuration value is only applied to the peripheral during begin().
The effect is that if you call setClock(xxx) after begin(), the i2c will continue to operate at the default speed (100Khz).
Some Arduino libraries expect setClock to apply the change even if called after begin(), so I tested and sent a PR to change that.

This is the PR including the change:
https://github.com/rogerclarkmelbourne/ ... 2/pull/340

This is one example of such use:
https://github.com/PaoloP74/extEEPROM/b ... M.cpp#L107

With the changes the code will check if the port was enabled already, and if so disable it, apply the change, and enable again (without changing unrelated settings). If the port was not enabled yet, then it only changes the configuration value, and a call to begin() will enable the port with the desired speed. Please check and provide any feedback.

User avatar
RogerClark
Posts: 6917
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: [LIBMAPLE Wire] setClock doesn't apply speed change if called after begin()

Post by RogerClark » Wed Sep 13, 2017 9:56 pm

Thanks victor

I will test this and merge if it works for me...

Post Reply