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

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

Open velechit opened this issue 2 years ago • 2 comments

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?

velechit avatar Dec 15 '23 04:12 velechit

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

zerovijay avatar Jan 29 '24 14:01 zerovijay

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

ItsMe6666 avatar Jun 03 '24 09:06 ItsMe6666