arduino / arduino/ArduinoCore-renesas
Wire::setClock() only allows exact values of 100kHz, 400kHz, and 1 MHz
- Dominant language
- C
- Stars
- 193
- Forks
- 112
- PR merge metrics
- No merged PRs in 30d
Description
The case statements in void `TwoWire::setClock(uint32_t freq)` are at odds with the Wire from the "Arduino AVR Boards" platform. "Arduino AVR Boards" platform's library allows a range of clock values:
```cpp
// Probably R3 should be range checked.
void TwoWire::setClock(uint32_t clock)
{
twi_setFrequency(clock);
}
void twi_setFrequency(uint32_t frequency)
{
TWBR = ((F_CPU / frequency) - 16) / 2;
}
```
The R4 boards only allow values in this enum:
https://github.com/arduino/ArduinoCore-renesas/blob/424e86eff92d37f72123c2b641dd8bbf06a38b47/variants/UNOWIFIR4/includes/ra/fsp/inc/api/r_i2c_master_api.h#L62-L68
The [I2C standard](https://www.nxp.com/docs/en/user-guide/UM10204.pdf) suggest you should allow the best match possible to the requested clock.
> The I2C clock can be 0 Hz to 100 kHz, 0 Hz to 400 kHz, 0 Hz to 1 MHz and 0 Hz to 3.4 MHz, depending on the mode. This means that an I2C-bus running at less than 10 kHz is not SMBus compliant since the SMBus devices may time-out.
Contributor guide
No contributing guide indexed for this repository
Research direction
Locate the implementation of TwoWire::setClock(uint32_t freq) and compare its accepted values with the Arduino AVR Boards behavior and the referenced Renesas I2C API enum. Check how clock configuration is passed to the underlying peripheral; done means supported requested frequencies are handled by the best available match rather than only exact enum values.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- embedded-iot
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 52/100