sparkfun / SparkFun_MAX3010x_Sensor_Library

An Arduino Library for the MAX3015 particle sensor and MAX30102 Pulse Ox sensor
Other
221 stars 148 forks source link

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

Closed nseidle closed 6 years ago

nseidle commented 6 years ago

From @Koepel on December 12, 2016 13:53

In the file "MAX30105.cpp" in the function "readRegister8()" there is a delay with a timeout after the Wire.requestFrom(). There is no need to wait there. The Wire.requestFrom() waits until the i2c session has completely finished. After that the data is in a buffer inside the Wire library. The Wire.available() returns the number of bytes that are in that buffer. There is no need to wait for retrieving data from that buffer, since the i2c session has already finished.

I did not check the datasheet. Some sensors do not acknowledge their i2c address when they are busy. In that case the Wire.requestFrom() should be repeated. The Wire.available() could be used once, or the return value of Wire.requestFrom() could be used to check if no data was received and a fail (zero) should be returned.

_Copied from original issue: sparkfun/MAX30105_Particle_SensorBreakout#2

nseidle commented 6 years ago

This was fixed in a previous commit.