Hey guys,
Im new to I2C/SMBus stuff in linux. I am trying to interface an IR sensor
to the system (MLX90614). I read in the datasheet that the device is SMBus
compatible, but only with the READ WORD and WRITE WORD functions.
I have the following code:
//Open i2c bus
file = open("/dev/i2c/0", 0);
if(file < 0) {
exit(1);
}
/* Set Slave Address */
if(ioctl(file, I2C_SLAVE, 0x5A) < 0)
{
if(errno == EBUSY)
{
printf("UU ");
}
else
{
fprintf(stderr, "Error: could not set address to 0x%02x: %s\n",
0x01, strerror(errno));
return -1;
}
}
if( ioctl( file, I2C_PEC, 1) < 0)
{
fprintf( stderr, "Failed to enable PEC\n");
return -1;
}
__uint8_t reg = 0x07; /* Device register to access */
int dataH = i2c_smbus_read_word_data(file, reg);
usleep(100);
printf("DataH: %X\n", dataH);
Now, this code works! ...once. Upon a fresh boot, i can run a program with
this code and get the correct data from register 0x07. If I try to run it
again, it may or may not work. I get SMBus timeouts waiting for bus to be
idle followed by failures to get the bus.
What am I not doing correctly here?? Am I missing some steps? Thanks for
the help!
-Ryan
SMBus usage with Tiny6410-SDK
I should also mention that I do not get these problems when I use READ BYTE or WRITE BYTE functions, however, since they are not supported, the data bytes I receive are 0xFF.

