Hi, altough I can see i2c-1 , i2c-2 and i2c-3 under the /dev directory, I am not able to read the eeprom via i2c-1.
In the documentations it is stated that the eeprom is attached to i2c-1. The device address of eeprom starts with 1010 and default eeprom address is stated as 000 for i2c.
So, the 8 bit address is supposed to be 0b10100001 (for reading).
However, when we use the below code, we cannot read anything, we always get Error 3.
How can we solve this?
int main()
{
int file;
char filename[20]="/dev/i2c-1";
if ((file = open(filename,I2C_SMBUS)) < 0) {
printf("Error 1\n");
}
int addr = 0x51; /* The I2C address 0b10100001*/
if (ioctl(file,I2C_SLAVE_FORCE,addr) < 0) {
printf("Error2\n");
}
__u8 register reg = 0x40; /* Device register to access */
__s32 res;
char buf[10];int i=0;
/* Using SMBus commands */
res = i2c_smbus_read_word_data(file,reg);
if (res < 0) {
/* ERROR HANDLING: i2c transaction failed */
printf("Error 3 %d\n",res);
} else {
printf("res:%s\n",res);
/* res contains the read word */
}