Skip to content

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

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
velechit opened this issue Dec 15, 2023 · 2 comments
Open

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

velechit opened this issue Dec 15, 2023 · 2 comments
Labels

Comments

@velechit
Copy link

velechit commented Dec 15, 2023

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.

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

=> gives data as 0xFF

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?

@per1234 per1234 added the bug label Jan 7, 2024
@zerovijay
Copy link

zerovijay commented Jan 29, 2024

0xFF is one byte (0b11111111) in binary it's mean correct.
can i get more information about the issue.

@ItsMe6666
Copy link

ItsMe6666 commented Jun 3, 2024

Wire.requestFrom(SLAVE_ADDRESS, 1);
while(Wire.available()) { // slave may send less than requested
  data0 = Wire.read();
  Serial.print(data0); 
}

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants