ArduinoCore-renesas icon indicating copy to clipboard operation
ArduinoCore-renesas copied to clipboard

Reducing excessive I2C timeout

Open maidnl opened this issue 3 months ago • 3 comments

This PR takes care of issue #492 . There was a default timeout of 1000 ms in I2C communication. Timeout has been reduced to 1ms. However (although this is not a standard Wire function) a setTimeout() function has been added to Wire class so that users can tune the value.

maidnl avatar Sep 23 '25 14:09 maidnl

@per1234 I renamed the function according to the request, however please note that in the current implementation of Wire (at least in Core-Renesas) the Wire class is derived from HardwareI2C class, that is derived from Stream. And Stream has already setTimeout function. void setTimeout(unsigned long timeout); // sets maximum milliseconds to wait for stream data, default is 1 second In my opinion it is better to use setTimeout name which is in line with the current class derivation scheme.

maidnl avatar Sep 24 '25 07:09 maidnl

Stream has already setTimeout function.

That function has a different purpose from what is being implemented here.

Stream::setTimeout sets the timeout for the high level blocking functions of the Stream class (e.g., readBytes).

The function implemented here is setting a timeout for the low level communication. This is the reason why the function was intentionally given a distinct name in the AVR library, rather than shadowing the Stream class member, which would have made it impossible to set the Stream timeout.

per1234 avatar Sep 25 '25 06:09 per1234

  • setWireTimeout(0,false) should disable timeout.

  • the new PR changes the default timeout value from 1000ms to 25ms (as also my PR does). This is not fully backwards compatible. Maybe ok to keep 1000ms when setWireTimeout() is introduced, unless it is obvious that 1000ms is a bug.

  • setWireTimeout(), without parameters sets another arbitrary timeout value than the default one and it is not obvious what the default is and what the initial default value is In the full solution for setting the timeout, there are macros that could be used to show what the default value is.

  • define WIRE_DEFAULT_TIMEOUT to be the default timeout value

HanzHager avatar Oct 13 '25 12:10 HanzHager