arduino / arduino/ArduinoCore-avr

Wire example i2c_scanner starts at invalid i2c address

Open
#380 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
C
Stars
1.5k
Forks
1.1k
PR merge metrics
No merged PRs in 30d

Description

The i2c_scanner example included with the Wire library starts its scan at i2c address 1.
There is no such i2c slave address.
The addresses 0 to 7 are not valid i2c slave addresses and are reserved because those addresses overlap with the timing for other i2c functions.
If you want details you can see here: https://www.i2c-bus.org/addressing/
Nick Gammon updated his version of the i2c_scanner code on his site quite a while back:
https://gammon.com.au/i2c

While not a factor for the AVR h/w, starting in the reserved space can cause a lockup on other platforms that use different i2c h/w.

--------------------

The fix is trival. Just start the scan at address 8.
It might be helpful to put in a comment about it to explain to people why the scan starts at 8
i.e. change this:
` for (byte address = 1; address < 127; ++address) {`

to something like:
```
// i2c addresses 0-7 are not valid slave addresses and are reserved for special purposes
// so start the scan at address 8
// for more on i2c addressing: // https://www.i2c-bus.org/addressing/
for (byte address = 8; address < 127; ++address) {
```

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the i2c_scanner example in the Wire library and inspect the scan loop shown in the issue. Verify that scanning begins at address 8, includes a comment explaining why addresses 0-7 are reserved, and preserves the existing upper bound of 127.

Written by the indexing model from the issue text.

Assessment

Tech stack
c
Domain
embedded-iot
Issue type
Bug
Difficulty
1/5
Estimated time
Under an hour
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.