Can't write/read 16 bit register addresses on npm1300 through i2c

I'm trying to demonstrate that I can write a value to a Nordic npm1300 register and read the same value back. Using the code below, I write 0x5a but read 0x0a, so the msb 5 is getting lost:

    uint8_t pmic_config[] = {0x06, 0x01, 0x5a};                                 //register followed by value
    ret = i2c_write_dt(&dev_i2c_pmic, pmic_config, 2);                              
    if (ret != 0)
    {
        printk("Failed to write pmic register %x \n", pmic_config[0]);
        return -1;
    }

    //read something from the pmic
    int myVal = 0;                                                                      //this will be returned
    uint8_t regsy[] = {0x06, 0x01};            

    ret = i2c_write_read_dt(&dev_i2c_pmic, regsy, 2, &myVal, 1);
    if (ret != 0)
    {
        printk("Failed to read pmic register %x%x \n", regsy[0], regsy[1]);
        return -1;
    }
    else
    {
        printk("pmic Register 0x%x%x is 0x%x \n", regsy[0], regsy[1], myVal);
    }
Result:
pmic Register 0x61 is 0xa 
All the solutions I saw posted here used nrf_drv_twi_tx and nrf_drv_twi_rx which seem more complex than i2c_write_read_dt(), so it would be nice if there's a simple solution involving the code I shared above.
Parents Reply Children
No Data
Related