Files
Adafruit_nRF52_Arduino/libraries
strasharo 45188a647f Wire (nRF52): add timeout to endTransmission()/requestFrom() poll loops
endTransmission() and requestFrom() both spin on unbounded while(!EVENT)
loops waiting on the TWIM peripheral. Several of these loops - notably
the EVENTS_STOPPED wait - have no EVENTS_ERROR escape at all, so if the
hardware never raises the expected event (e.g. probing an I2C address
on a bus with nothing attached and no pull-ups), the call never
returns and the whole single-threaded firmware hangs forever.

Reported in #771 with the same root cause already identified in the
issue thread. Also affects boards that probe for an optional/absent
I2C device at boot before anything else initializes - e.g. MeshCore's
Xiao_nrf52 target, which runs an RTC autodiscovery scan in radio_init()
and hangs on every cold boot when no RTC is wired up (no serial, no
BLE - see meshcore-dev/MeshCore#2068).

Adds a bounded I2C_TWIM_TIMEOUT_MS (default 100ms, overridable) to
every wait loop in both functions. A timeout that occurs before the
hardware transaction actually completed is surfaced as a proper error
return (endTransmission: 4 "other error"; requestFrom: 0 bytes read)
rather than silently falling through to a success path - a timeout on
the address/data phase must not be reported as if a device ACKed.

Tested on a Seeed XIAO nRF52840 + Wio-SX1262 board that reliably hung
at boot (via MeshCore's RTC autodiscovery probe) after every power
cycle. With this patch the same probe now completes (with a timeout)
in well under a second per address instead of hanging indefinitely,
and the board boots and runs normally.
2026-12-02 12:22:38 +01:00
..
2021-05-25 22:52:07 +07:00
2023-09-21 12:03:26 -03:00
2021-06-02 13:26:54 +07:00