How to enable I2C 10-bit addressing on ncs v2.4.2?

I need to use nRF5240 device to control LED driver IC through I2C interface. And I also need to use I2C 10-bit addressing. How to enable I2C 10-bit addressing on ncs v2.4.2?

Parents
  • Hello,

    From the TWI peripheral description in the nRF5340 product specification you can find that only 7-bit address is supported by the hardware:
    https://infocenter.nordicsemi.com/topic/ps_nrf5340/twim.html#register.ADDRESS 

    Looking at the screenshots you shared it may seem as it's possible to use 7-bit address to expand this to 10-bit by actually using 16-bit. We don't have any example on how to do this, however in theory (I believe) it can be possible to use the low level nrfx_twim_xfer() api directly to have more control of what bytes are sent on the bus. There are example in ncs showing the use of nrfx_twim directly that may be used as basis for this:
    https://github.com/zephyrproject-rtos/hal_nordic/tree/master/nrfx/samples/src 

    Kenneth

  • 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;
    }

Reply
  • 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;
    }

Children
No Data
Related