arduino / arduino/ArduinoCore-avr

Wire library read() returns 0xFF on reading only one byte

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

Description

I am having a weird problem with my I2C code. The problem is that when I try to read only 1 byte in the master I get 0xFF but if I read 2 bytes I get proper value of the first byte.

```cpp
Wire.requestFrom(SLAVE_ADDRESS, 1);
data = Wire.read();
```

=> gives `data` as `0xFF`

```cpp
Wire.requestFrom(SLAVE_ADDRESS, 2);
data0 = Wire.read();
data1 = Wire.read();
```

=> gives `data0` as `0xA5` (which is expected from the single byte read)

Am I doing anything wrong?

Contributor guide

No contributing guide indexed for this repository

Research direction

The issue names the Wire.requestFrom() and Wire.read() entry points but no source file or test. Reproduce the one-byte and two-byte reads first, then trace those calls through the AVR Wire implementation. Done means the differing behavior is explained and the appropriate fix or documented usage is confirmed.

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
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.