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:
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:
Note: I'm sure the i2c comm is working somewhat because when I change the write value, the read value also changes. For instance, changing 0x5a to 0x52 give 0x02 as a response.
uint8_t pmic_config[] = {0x06, 0x01, 0x5a}; //register followed by valueret = i2c_write_dt(&dev_i2c_pmic, pmic_config, 2);
Shouldn't it be 3 bytes in total? Not 2.
Also, what register you are writing to, and are both values 8bit? I can see many registers are less than 8bit.
Kenneth
If you look at the description of the register you are attempting to write (address 0x0601 corresponds to https://docs.nordicsemi.com/bundle/ps_npm1300/page/chapters/core_components/gpio/doc/frontpage.html#ariaid-title6), you can see that it uses only the lower 4 bits, so the msb 5 in your case is simply ignored. And yes, the number of bytes to write in the `i2c_write_dt` should be equal to the array size.
To get an idea of how to communicate with the PMIC through I2C it is worth taking a look at how the mfd_npm13xx driver implements this: github.com/.../mfd_npm13xx.c
Yes, it should have been three bytes. But as you pointed out, the underlying problem was that the register I was writing to was only four bits.
Thank you, the problem was that I was writing/reading a four bit register.