Quantcast
Channel: Active questions tagged linux-kernel - Stack Overflow
Viewing all articles
Browse latest Browse all 12368

Wrong Return Value for I2C_SLAVE and I2C_RDWR on Raspberry pi

$
0
0

I am using Raspberry pi for I2C communication to a chip.

The I2C Runs on i2c-1 and the chip I want to communicate is mux0 for which the address is specified. I used a wrong address to see what value I get from I2C_SLAVE and I2C_RDWR.

I want to check if the I'm opening correct bus or not. So I'm using the if statement and it's working fine for me. `

int file;
file = open(i2c_adapt, O_RDWR);
if (file == -1)
  {
    perror("Check I2C Bus");
    exit(1);
  }

`

Then I saw there are two functions I can use to define the chip address. I2C_SLAVE and I2C_RDWR.

I want to check if the chip address is correct or not but both of them return same values.

I printed their return value to check.

`

printf("\nThe file value when Mux0 is %d", open("/dev/i2c-1", O_RDWR));
printf("\nThe file value of random bus is %d\n", open("/dev/i2c-0", O_RDWR));
printf("\nThe i2c_Slave value when Mux0 is %d", ioctl(file, I2C_SLAVE, mux0));
printf("\nThe i2c_Slave value of random address is %d\n\n", ioctl(file, I2C_SLAVE, 0x60));
printf("\nThe I2C_RDWR value when Mux0 is %d", ioctl(file, I2C_RDWR, mux0));
printf("\nThe i2c_RDWR value of random address is %d\n\n", ioctl(file, I2C_RDWR, 0x60));

When I run these commands I get the following values:

The file value when Mux0 is 4 The file value of random bus is -1

so I can use if statement to see if I'm using wrong bus

The i2c_Slave value when Mux0 is 0 The i2c_Slave value random address is 0

The i2c_RDRW value when Mux0 is -1 The i2c_RDRW value of random address is -1enter image description here

Can someone tell me why I'm getting same value for wrong chip as well?


Viewing all articles
Browse latest Browse all 12368

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>