title: Reading 2 bytes through I2C
body: <p>I was writing since I am trying to implement an I2C communication protocol that reads 2 registers (or more) and receives a byte from each register. As far as I know, the writing part is done correctly according to the logic analyzer. The problem is that I only receive one byte repeated twice instead of a byte per register. It's my first LPC/I2C program and I guess there must be some small error somewhere. I attach the read function, the main and the logic analyzer output. I want to read registers 0x28 and 0x29 and receive the acceleration (LSM9DS0 IMU).</p>
  <p>I am using LPC1549 Xpresso</p>
  <p>Thanks in advance for the help and your time.</p>
  <p>READING FUNCTION:</p>
  <pre><code>uint32_t E2PROM_Read(uint8_t slave_address, uint16_t read_address, uint16_t   bytes_to_read, uint8_t * in_buffer)
  {
  uint8_t out_buffer[2];
  out_buffer[0]=0x0000;
  out_buffer[1]=0x0000;
  
  //out_buffer[0] high address
  //out_buffer[1] low address
  I2CM_XFER_T  i2cmXferRec;
  
  out_buffer[0] = (uint8_t)(read_address);
  out_buffer[1] = (uint8_t)(read_address + 0x01);
  
  
  i2cmXferRec.slaveAddr = slave_address;
  i2cmXferRec.status    = 0;
  i2cmXferRec.txSz      = 2;
  i2cmXferRec.txBuff    = out_buffer;
  i2cmXferRec.rxSz      = bytes_to_read;
  i2cmXferRec.rxBuff    = in_buffer;
  
  
  
  
  //* Test for valid operation */
          if (i2cmXferRec.status == I2CM_STATUS_OK) {
              /* Output acc. */
              DEBUGOUT(&quot;acceleration read over I2C is: \n %d \n %d &quot;,
              (int) in_buffer[0], (int) in_buffer[1] );
  
  Chip_I2CM_XferBlocking(LPC_I2C0, &amp;i2cmXferRec);
  
  
  
  return i2cmXferRec.status;
  // .status = 0 if ok
      }
          else {
                  DEBUGOUT(&quot;Error %d reading temperature.\r\n&quot;, i2cmXferRec.status );
              }
  }
  </code></pre>
  <p>Call to the function:</p>
  <pre><code>uint8_t in_buffer[10];
  uint8_t read_address=0x28;
  E2PROM_Write(I2C_TEMP_ADDR_7BIT, 0x20, 2, out_buffer1);
  
  E2PROM_Write(I2C_TEMP_ADDR_7BIT, 0x21, 2, out_buffer2);
  /* Loop forever, toggle LED on board */
  while (1) {
  
      /* Sleep until a state change occurs in SysTick */
      while (lastState == state) {
          __WFI();
      }
  
  
      E2PROM_Read(I2C_TEMP_ADDR_7BIT, read_address, 2, in_buffer);
  </code></pre>
  <p>This is what I get from the logic analyzer, I write both addresses correctly, but receive the same byte instead of two different bytes (one for each address).</p>
  <p><a href="https://i.stack.imgur.com/oOjFm.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/oOjFm.jpg" alt="enter image description here" /></a></p>