title: Wrong Return Value for I2C_SLAVE and I2C_RDWR on Raspberry pi
body: <p>I am using Raspberry pi for I2C communication to a chip.</p>
  
  <p>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.</p>
  
  <p>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. 
  `</p>
  
  <pre><code>int file;
  file = open(i2c_adapt, O_RDWR);
  if (file == -1)
    {
      perror("Check I2C Bus");
      exit(1);
    }
  </code></pre>
  
  <p>`</p>
  
  <p>Then I saw there are two functions I can use to define the chip address. I2C_SLAVE and I2C_RDWR. </p>
  
  <p>I want to check if the chip address is correct or not but both of them return same values. </p>
  
  <p>I printed their return value to check.</p>
  
  <p>`</p>
  
  <pre><code>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));
  </code></pre>
  
  <p><code>
  </code></p>
  
  <p>When I run these commands I get the following values:</p>
  
  <p>The file value when Mux0 is 4
  The file value of random bus is -1</p>
  
  <p>so I can use if statement to see if I'm using wrong bus</p>
  
  <p>The i2c_Slave value when Mux0 is 0
  The i2c_Slave value random address is 0</p>
  
  <p>The i2c_RDRW value when Mux0 is -1
  The i2c_RDRW value  of random address is -1<a href="https://i.stack.imgur.com/G9fux.png" rel="nofollow noreferrer">enter image description here</a></p>
  
  <p>Can someone tell me why I'm getting same value for wrong chip as well?</p>