This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

nRF52832 TWI implementation with 16-bit register addresses

We need to read/write to an I2C device that uses a 16-bit register addresses (Melexis MLX90632), and the nrf_drv_twi_tx() and nrf_drv_twi_rf() functions seem to be limited to 8-bit addresses.

How can we use the TWI module to read 16-bit addressed registers?

Thanks!

  • Here a user describes accessing a device which uses a 32 bit address, maybe the proposed configuration is interesting for you.
    In this question another user has the same question as you do - the answer contains multiple links to additional ressources learning about I2C in general and notes:

    Note that I2C itself has no notion of "registers" - that's just to do with the particular Slave you're talking to.

    As far as I2C itself is concerned, it's all just data.

    functions seem to be limited to 8-bit addresses

    Do you mean the I2C device address? I think the I2C protocol specifies 7 bit standard addresses and 10 bit addressing to expand the number of devices connected to the same bus.

    I assume you confuse the I2C device address with the "register address".

    The datasheet of the Melexis MLX90632 states (on p.22):

    "By default, the device responds to the 7-bit slave address 0x3A.
    Configuration of the 7-bit slave address is possible at EEPROM address 0x24D5.
    "

    Section 9.2 Addressed read of the datasheet (p.24) shows how to perform a read from a 16-bit address on the device.
    1. Send the 7-bit device address
    2. Send the MSB of the 16 bit address
    3. Send the LSB of the 16 bit address

    JaTi

  • I had already reviewed all those links before I submitted my question.  They were not specific enough.

    I do mean "register address", not "device address".

    My question is very specifically about the nrf_drv_twi_tx() function.  An I2C read is a two-part process: (1) I2C write register address, (2) I2C read from that address.  So a nrf_drv_twi_tx() is followed by nrf_drv_twi_rx().

    The answer to my question is to break the register address into an array of uint8_t type and write the bytes sequentially.  So a register address of 0x1234 can be written as 2 bytes:

    uint8_t reg[] = {0x12, 0x34};  //decompose 16-bit address, MSB first
    err_code = nrf_drv_twi_tx(&m_twi, DVC_I2C_ADDR, reg, 2, false);

    This simple answer hopefully will help others who ask the same question about 16-bit and 32-bit register addressing using the nrf_drv_twi_tx() question.  

Related