Function for read with I2C

this is the first time that I work on the ADUCM3029 microntroller, I wrote this function to read the data of the slave (Temperature Sensor), I hope if someone who has a little more experience with this MCU correct me this function
int32_t mlx90632_i2c_read(int16_t register_address, uint16_t *value){
      int32_t ret = 0;
      uint8_t reg_addr[2];
      uint16_t register_addr = (uint16_t)register_address;
      register_addr = reg_addr[1]|(reg_addr[0]<<8);
      uint8_t data[2];
      *value = data[1]|(data[0]<<8);
  /* set slave address to MLX90632 default 0x48 without read0/write1 bits */
    if (adi_i2c_SetSlaveAddress(i2CDevice, MLX90632_REG_I2C_ADDR))  // bottom-end
         //DEBUG_MESSAGE("couldn't set slave device address");
    Direction control for data phase. If "true", data phase is a read (from the slave), 
    if "false", data phase is a write (to the slave). 
    Pertains only to the data phase. Any prologue data (addressing/command phase) 
    is always transmitted (written to the slave) prior to the data phase.
    tran.pPrologue = reg_addr;      /*!< Prologue pointer.                      */
    tran.nPrologueSize=2;  /*!< Prologue byte count.                   */
    tran.pData=data;     /*!< Data pointer.                          */
    tran.nDataSize=sizeof(data);      /*!< Data byte count.                       */
    /* false to write*/
    tran.bReadNotWrite=true;  /*!< Read/write flag.                       */
    tran.bRepeatStart=true;   /*!< Repeat start flag.                     */
    return ret;

Top Replies