-->
Page 1 of 1

MLX90614 alternate reads fail

PostPosted: Sat May 28, 2016 4:25 pm
by colinmeikle
Has anyone tried using the MLX90614 IR temp sensor with sming ? The sensor uses SMB protocol which is similar to i2c . From what I can see Ardiuno users have it wring using the i2c Wire interface. However in my setup every second read fails, this is consistent and my workaround is to put in a dummy read however I'd like to understand what the root cause is. Had anyone seen anything similar

here is my read function

//reads 16 bit number from bus + error byte (not used)
uint16_t MLX90614::i2cRead(uint8_t reg){

uint16_t ret;
Wire.beginTransmission(_i2cAddr); // start transmission to device
Wire.write(reg); // sends register address to read from
Wire.endTransmission(false); // end transmission

Wire.requestFrom(_i2cAddr, (uint8_t)3);// send data n-bytes read
ret = Wire.read(); // receive DATA
ret |= Wire.read() << 8; // receive DATA

//error
uint8_t pec = Wire.read();

Wire.endTransmission(true); // end transmission
return ret;
}

Re: MLX90614 alternate reads fail

PostPosted: Sun May 29, 2016 9:16 am
by hreintke
I am not very experienced with i2c but..

In other applications/libraries using i2c I do not see the use of

Wire.endTransmission(true); // end transmission

To end a

Wire.requestFrom(_i2cAddr, (uint8_t)3);// send data n-bytes read