I2C3 On Imx6sl

cancel
Showing results for 
Search instead for 
Did you mean: 

I2C3 On Imx6sl

292 Views
sandeepajesh
Contributor III

Hi Experts,

We have an sensor connected to I2c3 of the IMx6sl board. I have to use i2c3 in master mode and sensor in Slave mode.I have made the necessary changes to dtb file and i can see device being probed.

root@imx6slzbha:~/system_init# cat /sys/class/i2c-dev/i2c-0/name
21a8000.i2c
mailto:root@imx6slzbha:~/system_init#

My Test Code:-

#define SLAVE_ADDR 0xD6 
#define I2C_DEVICE "/dev/i2c-0" 

int main(int argc,char **argv) {

int dev;
unsigned char res,res2;
int temperature ;
if ((dev = open(I2C_DEVICE, O_RDWR)) < 0){
perror("open failed");
exit(1);
}

if (ioctl(dev, I2C_SLAVE, SLAVE_ADDR) < 0){
perror("ioctl failed");
close(dev);
exit(1);
}
res = i2c_smbus_read_byte_data(dev, WHO_AM_I_M);
printf("Result= %d\n\r\n\r", res);
close(dev);
exit(0);;
}

I am getting error :- ioctl failed: Invalid argument

Can someone please guide me where I am wrong .

Regards

Sandeep S

Labels (1)
Tags (1)
2 Replies

112 Views
igorpadykov
NXP TechSupport
NXP TechSupport

Hi Sandeep

one can try to debug it, which function and what argument causes such error using

Chapter 35 Inter-IC (I2C) Driver attached Linux Manual.

Best regards
igor
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

112 Views
sandeepajesh
Contributor III

Thanks Igor.

I was able to debug it and found my mistake . I was using wrong Slave address. 

Regards

Sandeep S

0 Kudos