Hello
i have the error 16 on each write sequence when doing this code :
if ((dev_i2c = open("/dev/i2c-2",O_RDWR)) < 0) {
printf("Failed to open the bus with error %d %s\n",errno,strerror(errno));
/* ERROR HANDLING; you can check errno to see what went wrong */
return;
}
// send out the seven bit address of the device followed by a read/write bit. The bit is set to 0 for writes and 1 for reads.
if (ioctl(dev_i2c,I2C_SLAVE,I2C_EEPROM_UCR_ADDRESS) < 0) {
printf("Failed to acquire bus access and/or talk to slave 0xAE with error %d %s\n",errno,strerror(errno));
/* ERROR HANDLING; you can check errno to see what went wrong */
}
//write test sequence
printf("write test sequence\n");
// Set address
eepromAddr = I2C_EEPROM_WRITE_ADDRESS;
//eepromAddr = I2C_EEPROM_READ_ADDRESS;
i2c_ptr[3] = (offsetAddr) & 0xAA;
i2c_ptr[2] = (offsetAddr) & 0xFF;
i2c_ptr[1] = (offsetAddr>>8) & 0xFF;
i2c_ptr[0] = eepromAddr;
if(write(dev_i2c, i2c_ptr, 4) != 1) {
printf("I2C write1 failed with error %d %s\n",errno,strerror(errno));
}
reading is OK with this code :
printf("read test sequence\n");
// Set address
eepromAddr = I2C_EEPROM_READ_ADDRESS;
i2c_ptr[0] = eepromAddr;
if(write(dev_i2c, i2c_ptr, 1) != 1) {
printf("I2C write failed\n");
}
i2c_ptr[1] = (offsetAddr) & 0xFF;
i2c_ptr[0] = (offsetAddr>>8) & 0xFF;
if(write(dev_i2c, i2c_ptr, 2) != 2) {
printf("I2C write failed\n");
}
// Read 4 bytes from device
bytesToRead=I2C_NB_BYTES_TO_READ;
bytesRead = read(dev_i2c, &i2c_buffer[0], bytesToRead);
if(bytesRead != bytesToRead)
{
printf("I2C read failed with error %d %s; nb of bytes read=%d\n",errno,strerror(errno), bytesRead);
}
else
{
for (i=0;i<bytesRead;i++)
printf("byte read = %x\n", i2c_buffer[i]);
}
my device responds on i2c2 with :~# i2cdetect -r 2 with address 57 (an M24128 device)
#define I2C_EEPROM_UCR_ADDRESS 0x57
#define I2C_EEPROM_READ_ADDRESS ( (I2C_EEPROM_UCR_ADDRESS <<1)|0x01)
#define I2C_EEPROM_WRITE_ADDRESS (I2C_EEPROM_UCR_ADDRESS <<1)
have you any idea ?
thanks
regards