5 Replies Latest reply on Dec 23, 2016 12:10 PM by Intel Corporation

    Read uint32_t value from four 8-bit registers using MRAA I2C class

    Thomas Kirven

      I am wondering how I can use the mraa I2C class to correctly read a uint32_t value from four consecutive 8-bit registers. The data is stored in the registers 0x22,0x23,0x24, and 0x25 in the i2c integral frame described here PX4FLOW Smart Camera - Pixhawk Flight Controller Hardware Project


      This is what I have tried


      mraa::I2c* flow;

      flow = new mraa::I2c(1);


      uint32_t dt_flow;

      for (int i=0; i<100; i++) {

        dt_flow = (uint32_t)flow->readWordReg(0x22) | (uint32_t)flow->readWordReg(0x24) << 16 ;

        printf("dt_flow = %d\n",dt_flow);




      The value is time, in microseconds, since the last I2C readout, but dt_flow remains constant throughout all the iterations, when it should be changing on each loop.


      I assume

      (uint32_t)flow->readWordReg(0x22) | (uint32_t)flow->readWordReg(0x24) << 16

      is not the correct way to read the words and combine them, but I don't know what else to try. Also I would eventually like to be able to convert the uint32_t value into a float value in terms of seconds.


      Any help would be much appreciated!