This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

TWI reading the same data from registers

Hi,

The problem statement mentioned below.

What we are trying to do is Read Light value from the MAX44009 sensor on the TWI interface.

Looking at the data sheet for the MAX44009, the device freezes updates of the light value (registers 0x03 and 0x04) during an I2C action and releases them for update on seeing an I2C STOP. The data sheet suggests

If the user wants to read both the Lux High-Byte register 0x03 and Lux Low-Byte register 0x04, then the master should not send a STOP command between the reads of the two registers. Instead a Repeated START command should be used. This ensures accurate data is obtained from the I2C registers (by disabling internal updates during the read process).

 We want to use  the function nrf_drv_twi_xfer() with the flags NRF_DRV_TWI_XFER_TXRX. Is it a right approach ? . How this operation works? one read, one write followed by another read and write? or two continuous reads and two continuous writes?. Please suggest us a way to get updated value from both the registers. also Please suggest the correct flags or alternate API to achieve this functionality.

Parents
  • Hello,

    Sorry for the late reply. 

    It looks like what you are looking for is not a standard NRF_DRV_TWI_XFER_TXRX, but rather a NRF_DRV_TWI_XFER_TXRXTXRX (with no STOP signal in between). This is not supported by the driver by default.

    I can't find any mentions in the drivers regarding NO_STOP flags in TWI RX mode, only in TX, so I am not sure whether it is possible, although it looks like the TWIM peripheral supports this.

    Maybe you can give it a go to use the TWI registeres as described in the link above to see if you can get the behavior that the sensor expects.

  • Hi

    Can you give input on implementing the mentioned  Master repeated start sequence?

  • Hello,

    Sorry for the late reply. I was out of office for a couple of weeks, and we are in general a bit short staffed during the summer.

    I don't know how to do this exactly, other than using the events and tasks, as described here, and using PPI to trigger the next task based on the events. 

    The PPI may not be too  easy to get your head around. You can either use the ppi drivers that are used in the SDK\examples\peripheral\ppi, or you can use the PPI registers directly, like it is done in the example attached in my first reply in this ticket. Note that this is not TWI, but an example that uses PPI and a timer to generate PWM signals. The timer events triggers the GPIOTE tasks, so in your case, you would want the TWI events to trigger the next TWI tasks. 

Reply
  • Hello,

    Sorry for the late reply. I was out of office for a couple of weeks, and we are in general a bit short staffed during the summer.

    I don't know how to do this exactly, other than using the events and tasks, as described here, and using PPI to trigger the next task based on the events. 

    The PPI may not be too  easy to get your head around. You can either use the ppi drivers that are used in the SDK\examples\peripheral\ppi, or you can use the PPI registers directly, like it is done in the example attached in my first reply in this ticket. Note that this is not TWI, but an example that uses PPI and a timer to generate PWM signals. The timer events triggers the GPIOTE tasks, so in your case, you would want the TWI events to trigger the next TWI tasks. 

Children
No Data
Related