kriswiner/VEML6040

Wire.requestFrom() should not be followed by a Wire.endTransmission().

Opened this issue · 2 comments

In the file "VEML6040.ino", the Wire.requestFrom() is followed by a Wire.endTransmission(). You may remove that last Wire.endTransmission() from the getRGBWdata() function.

I'm sorry, but it is just plain wrong. It is a bug.

When writing data to a sensor, it is with three functions: Wire.beginTransmission - Wire.write - Wire.endTransmission.
The number of Wire.write can be zero to the maximum of the buffer of the Wire library.

When reading data from a sensor, it is with one function: Wire.requestFrom.
The Wire.requestFrom does the start, send the address, read the data, store it in a buffer, does a stop. After that the Wire.read and/or Wire.available can be used. The Wire.read and Wire.available don't use the I2C bus, they only operate on the buffer inside the Wire library.

Using a Wire.endTransmission on its own (without Wire.beginTransmission) is a bug. It depends on the used Wire library what will happen and if something goes wrong. I can tell you for the Wire library for AVR microcontrollers what will happen, but I don't know what will happen with other Wire libraries.