I2C Read instruction with unusual protocol

Hello,

I am using nRF52840 microcontroller to communicate with an external integrated circuit, through I2C peripheral.
The project is using the latest Nordic SDK: more in detail, the library used for communication is nrf_drv_twi.c/.h (TWI used as master, based on SDK examples).

I can easily communicate to the slave I2C device with write procedures.
Instead, I have difficulties performing read procedures since the protocol required by the slave device is as follows: 

I have tried using different combinations of nrf_drv_twi_rx() and nrf_drv_twi_tx() functions but I don't get a byte sequence as the one in the figure above (checked with i2c sniffer).

Do you think is possible to implement the sequence that I need using the APIs provided by the SDK?

Thanks!

  • Hello,

    The project is using the latest Nordic SDK: more in detail, the library used for communication is nrf_drv_twi.c/.h (TWI used as master, based on SDK examples).

    Which SDK example are you basing your application on?
    The TWI Scanner example uses the TWIM peripheral behind the scenes when the TWI0_USE_EASY_DMA is defined to 1 - in which case all nrf_drv_twi calls are forwarded through macros to nrfx_twim calls. If you intend on using the TWI with easyDMA I recommend that you switch to using the nrfx_twim driver directly, instead of going through the forwarding from the legacy driver. If so, you could read about the Master read sequence here, and you should instead then use the nrfx_twim_xfer function for your transfers along with the RX, TX macros for simplicity.

    I can easily communicate to the slave I2C device with write procedures.
    Instead, I have difficulties performing read procedures since the protocol required by the slave device is as follows: 

    That is peculiar. Are you using an official or third-party driver for your sensor?
    Does the driver list the registers' address twice - one for read and one for write - or only once, so that you have to indicate the read or write yourself?
    I have seen this done either way previously, unfortunately.

    I have tried using different combinations of nrf_drv_twi_rx() and nrf_drv_twi_tx() functions but I don't get a byte sequence as the one in the figure above (checked with i2c sniffer).

    Are you getting a NACK from your slave at any time, unexpectedly? If so, where in the transmission are you seeing this?
    Could you show me how your read commands currently look as seen by the sniffer?

    Best regards,
    Karl

Related