Is Wire.requestFrom() necessary at all?

When I wrote my own (simplistic) code for AVR I2C/TWI using ATmega328P datasheet, I can't remember setting a number of bytes MCU expected to receive from a slave device. Reading 1 byte was just [start condition] -> [(SLA)+(R)+(read ACK)] -> [(read byte)+(send NACK)]

Do I even need Wire.requestFrom() function if I need to read 1 byte only? If no, should I proceed straight to Wire.read()?

Yes, you need to. requestFrom() actually reads the bytes from the I2C, read() only reads from the internal buffer. If you don't call requestFrom() read() will never return anything.

1 Like

Looks like twi_readFrom() uses the 'length' value to determine when to send a NACK instead of an ACK on the arrival of a data byte.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.