cancel
Showing results for 
Search instead for 
Did you mean: 

How to read or write via I2C with slave 16 bits register adress

Sdrid.1
Associate II

How can i modify this part of code to can send the register address of 16 bits 

/* Implementation of I2C read for 16-bit values */
int32_t mlx90632_i2c_read(uint16_t Reg, uint16_t *value)
{
	uint8_t data[2];
	int32_t ret;
	ret = I2C_TxRx1(MLX_I2C_Adress,&Reg, data, sizeof(data));
	//Endianness
	*value = data[1]|(data[0]<<8);
	return ret;
}

this is the I2C_TxRx1 funcion function  

/* Only for MLX90632 Temperature Sensor */ 
ADI_HAL_STATUS_t I2C_TxRx1(uint32_t address,uint16_t *regAddr, uint8_t *anRxData, uint8_t size)
{
    if (adi_i2c_SetSlaveAddress(i2CDevice, address))  // bottom-end
    {
         //DEBUG_MESSAGE("couldn't set slave device address");
    }
    tran.pPrologue=regAddr;      /*!< Prologue pointer.                      */
    tran.nPrologueSize=2;;  /*!< Prologue byte count.                   */
    tran.pData=anRxData;     /*!< Data pointer.                          */
    tran.nDataSize=size;      /*!< Data byte count.                       */
    tran.bReadNotWrite=true;  /*!< Read/write flag.                       */
    tran.bRepeatStart=true;   /*!< Repeat start flag.                     */
    ADI_HAL_STATUS_t ret=0;
    uint32_t hwErrors;
    adi_i2c_ReadWrite(i2CDevice,&tran,&hwErrors);
    return ret;
}

And this the i2C DEVICE Command/Data Transaction Structure 

  *****************************************************************************/
typedef struct {
    uint8_t    *pPrologue;      /*!< Prologue pointer.                      */
    uint16_t    nPrologueSize;  /*!< Prologue byte count.                   */
    uint8_t    *pData;          /*!< Data pointer.                          */
    uint16_t    nDataSize;      /*!< Data byte count.                       */
    bool        bReadNotWrite;  /*!< Read/write flag.                       */
    bool        bRepeatStart;   /*!< Repeat start flag.                     */
} ADI_I2C_TRANSACTION;

0 REPLIES 0