title: Cannot read i2c device properly
body: <p>I am trying to write an embedded qt application that reads the specific i2c rtc device. Here is my code to init i2c:</p>
  
  <pre><code>int addr = 0x68;        // The I2C address of the RTC
  
  sprintf(filename,I2C_FILE_NAME);
  if ((file = open(filename,O_RDWR)) &lt; 0)
  {
      qDebug()&lt;&lt;"Failed to open the bus.";
      return;
  }
  
  if (ioctl(file,I2C_SLAVE_FORCE,addr) &lt; 0)
  {
      qDebug()&lt;&lt;"Failed to acquire bus access and/or talk to slave.\n";
      return;
  }
  </code></pre>
  
  <p>To read from device:</p>
  
  <pre><code>unsigned char addr = 0x68;
  unsigned char reg = 0x00;
  unsigned char inbuf[2], outbuf;
  
  struct i2c_rdwr_ioctl_data packets;
  struct i2c_msg messages[2];
  
  /*
  * In order to read a register, we first do a "dummy write" by writing
  * 0 bytes to the register we want to read from.  This is similar to
  * the packet in set_i2c_register, except it's 1 byte rather than 2.
  */
  outbuf = reg;
  messages[0].addr  = addr;
  messages[0].flags = 0;
  messages[0].len   = sizeof(outbuf);
  messages[0].buf   = &amp;outbuf;
  /* The data will get returned in this structure */
  messages[1].addr  = addr;
  messages[1].flags = I2C_M_RD/* | I2C_M_NOSTART*/;
  messages[1].len   = 2;
  messages[1].buf   = inbuf;
  /* Send the request to the kernel and get the result back */
  packets.msgs      = messages;
  packets.nmsgs     = 2;
  if(ioctl(file, I2C_RDWR, &amp;packets) &lt; 0)
  {
      qDebug()&lt;&lt;"Unable to send data";
      return;
  }
  qDebug() &lt;&lt; inbuf[0];
  </code></pre>
  
  <p>What I am trying to do is just read rtc device's register that holds the "seconds". What I get is some numbers but those numbers looks good at first but there is some weird incrementation. Like, <code>55,56,56,57</code> then it jumps to <code>64</code>? then it is going up to <code>89</code> then <code>0</code>? I don't know why this happens or what is wrong with my code?</p>