title: Read a block of data from a specific register(fifo) using c/c++ and i2c in raspberry Pi
body: <p>I need to read 4 bytes of data from MAX30100 chip using c/c++ and I2C on raspberry Pi. I tried doing it with python. And it worked. But the problem was the data rate is too slow, I need to update the data at least 250 times/sec, which means the frequency of reading is >= 250Hz. So, i switched the reading from python to c/c++. </p>
  
  <p>There is no problem when just read or write one bytes with wiringPi. However, I need to read 4 bytes from fifo (address of the fifo is 0x04), wiringPi doesn't provide a function to do the block data reading. There are only read byte/word functions.</p>
  
  <p>Then, I tried use SMBus to do the block reading, which can be found here:
  <a href="https://github.com/leon-anavi/rpi-examples/blob/master/BMP180/c/smbus.c" rel="nofollow noreferrer">https://github.com/leon-anavi/rpi-examples/blob/master/BMP180/c/smbus.c</a></p>
  
  <p>But, as soon as I call the i2c_smbus_read_block_data(), my raspberry Pi freezes completely.</p>
  
  <p>Here is the read block data I added into the wiringPiI2C.c:</p>
  
  <pre><code>void i2c_smbus_read_block_data(int fd, int command, uint8_t *values, int length)
  {
      union i2c_smbus_data data;
      int i, err;
  
      err = i2c_smbus_access(fd, I2C_SMBUS_READ, command,
                     I2C_SMBUS_BLOCK_DATA, &amp;data);
      if (err &lt; 0)
          return;
      printf("test1");
      for (i = 1; i &lt;= length; i++)
          values[i-1] = data.block[i];
  }
  </code></pre>
  
  <p>The <strong>wiringPiI2C.c</strong> can be found here: <a href="https://github.com/WiringPi/WiringPi/blob/master/wiringPi/wiringPiI2C.c" rel="nofollow noreferrer">https://github.com/WiringPi/WiringPi/blob/master/wiringPi/wiringPiI2C.c</a></p>
  
  <p>Anyone knows what's going on there? Or has a better solution?</p>