Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Please add uint32_t getClock() to the Wire library #11457

Copy link
Copy link
Open
@RobTillaart

Description

@RobTillaart
Issue body actions

The Wire library has a function void setClock(uint32_t frequency) to set the I2C clock frequency.

It would be useful for (library) developers to be able to read the current clock frequency so I could drive a device at maximum frequency and reset the I2C bus afterwards.

some_device_call()
{
  uint32_t prev_freq = Wire.getClock();

  Wire.setClock(_my_max_freq);
  // do my I2C thing

  Wire.setClock(prev_freq);

  return whatever;
}

The ESP32 does already support a getClock() function,

For AVR based devices it could look like

FILE: Wire.h

//  class TwoWire : public Stream
...
uint32_t getClock();

FILE: Wire.cpp

uint32_t  TwoWire::getClock()
{
 uint32_t speed = F_CPU / ((TWBR * 2) + 16);
 return speed;
}

Yes the value may not be exact what was set by setClock() but it would be the actual frequency.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Library: WireThe Wire Arduino libraryThe Wire Arduino libraryfeature requestA request to make an enhancement (not a bug fix)A request to make an enhancement (not a bug fix)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.