title: I am trying to use i2c on the beagle bone black with c++ but I keep getting 0x00 returned
body: <p>Hi I am trying to read and write data from the i2c bus on the beagle bone black. But I keep reading 0x00 whenever I try to access the Who Am I register on a MMA84152 (or any other register for that matter), which is a constant register which means its value does not change. I am trying to read i2c-1 character driver located in /dev and I connect the sda and scl of the MMA852 lines to pins 19 and 20 on the p9 header. The sda and scl lines are both pulled high with 10 k resistors. Both pin 19 and pin 20 show 00000073 for their pin mux which means it is set for i2c functionality and slew control is slow, reciever is active, the pin is using  a pull up resistor, and pull up is enabled. I ran i2cdetect -r 1 and my device shows up as 0x1d which is its correct address. I also ran i2cdump 1 0x1d and 0x2a shows up under 0x0d which is the register I am trying to read from my device and contains the correct value according to the datasheet. But when I read it it returns 0x00 for me. I am also running the latest angstrom distribution and I am logged in under root so no need for sudo.I'm lost now. Here is the code:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;unistd.h&gt;
  #include &lt;linux/i2c-dev.h&gt;
  #include &lt;linux/i2c.h&gt;
  #include &lt;sys/ioctl.h&gt;
  #include &lt;sys/types.h&gt;
  #include &lt;sys/stat.h&gt;
  #include &lt;fcntl.h&gt;
  #include &lt;string&gt;
  
  using namespace std;
  
  int main(int argc, char **argv){
      int X_orientation=0;
      char buffer1[256];
      string i2cDeviceDriver="/dev/i2c-1";
      int fileHandler;
  
      if((fileHandler=open(i2cDeviceDriver.c_str(),O_RDWR))&lt;0){
          perror("Failed To Open i2c-1 Bus");
          exit(1);
      }
      if(ioctl(fileHandler,I2C_SLAVE,0x1d)&lt;0){
          perror("Failed to acquire i2c bus access and talk to slave");
          exit(1);
      }
  
      char buffer[1]={0x0D};
      if(write(fileHandler,buffer,1)!=1){                 
          perror("Failed to write byte to accelerometer");
          exit(1);
      }
  
      if(read(fileHandler,buffer1,1)!=1){                 
          perror("Failed to read byte from accelerometer");
          exit(1);
      }
      printf("Contents of WHO AM I is 0x%02X\n",buffer1[0]);
  }
  </code></pre>