From https://docs.zephyrproject.org/latest/hardware/peripherals/i2c.html link, I didn't find any APIs for 16bit register address. Does Zephyr I2C APIs support 16bit register address on ncs v2.4.2?
From https://docs.zephyrproject.org/latest/hardware/peripherals/i2c.html link, I didn't find any APIs for 16bit register address. Does Zephyr I2C APIs support 16bit register address on ncs v2.4.2?
The I2C standard does not support 16-bit device addresses, and the datasheet you referred to shows a 7-bit address (+1 write bit). The second address byte is for the internal register address in the I2C slave and, from the I2C protocol's perspective, it's treated just like any other data byte.
The I2C standard does not support 16-bit device addresses, and the datasheet you referred to shows a 7-bit address (+1 write bit). The second address byte is for the internal register address in the I2C slave and, from the I2C protocol's perspective, it's treated just like any other data byte.
Thanks for your reply! I can read/write registers now.
static int _lp5861ReadReg(uint16_t regAddr, uint8_t *regVal) { printk("tca6424aReadReg(regAddr=0x%x)\n", regAddr); const uint16_t devAddr = LP5861_CHIP_ADDRESS | _lp5861GetRegAddrHigh(regAddr); const uint8_t startAddr = _lp5861GetRegAddrLow(regAddr); printk("devAddr=0x%x, startAddr=0x%x\n", devAddr, startAddr); uint8_t rbuf[2]; const int ret = i2c_burst_read(_gI2cDev, devAddr, startAddr, rbuf, sizeof(rbuf)); if (ret < 0) { printk("i2c_burst_read(0x%x) failed, ret=%d\n", regAddr, ret); return ERROR_I2C_READ_FAIL; } printk("rbuf[0]=0x%x, rbuf[1]=0x%x\n", rbuf[0], rbuf[1]); *regVal = rbuf[0]; return 0; } static int _lp5861WriteReg(uint16_t regAddr, uint8_t regVal) { printk("tca6424aWriteReg(regAddr=0x%x, regVal0x%x)\n", regAddr, regVal); const uint16_t devAddr = LP5861_CHIP_ADDRESS | _lp5861GetRegAddrHigh(regAddr); const uint8_t startAddr = _lp5861GetRegAddrLow(regAddr); printk("_lp5861GetRegAddrHigh(regAddr)=0x%x\n", _lp5861GetRegAddrHigh(regAddr)); printk("devAddr=0x%x, startAddr=0x%x\n", devAddr, startAddr); const uint8_t wbuf[2] = { regVal, 0x00}; const int ret = i2c_burst_write(_gI2cDev, devAddr, startAddr, wbuf, sizeof(wbuf)); if (ret < 0) { printk("i2c_burst_write(0x%x) failed, ret=%d\n", regAddr, ret); return ERROR_I2C_WRITE_FAIL; } return 0; }