Skip to content
This repository has been archived by the owner on Jul 23, 2020. It is now read-only.

No need to wait after Wire.requestFrom() #1

Open
Koepel opened this issue Mar 19, 2016 · 0 comments
Open

No need to wait after Wire.requestFrom() #1

Koepel opened this issue Mar 19, 2016 · 0 comments

Comments

@Koepel
Copy link

Koepel commented Mar 19, 2016

In the file flowi2chelper.cpp is some waiting with available() and delay(), that can be removed.
After Wire.requestFrom() returns, there is no need to wait for something. The I2C transmission has finished and the received data is in the buffer. The Wire.available() only returns the number of bytes in the receive buffer (a buffer inside the Wire library).

It is possible to check the return value of Wire.requestFrom() or use Wire.available() to check if the right amount of data was returns, because with a multi-master bus and collisions, they might return 0 bytes.

int n = Wire.requestFrom(i2cAddress, dataLength);
if ( n != dataLength)
  return( false);

Wire.readBytes(data, n);
return( true);
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant