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

power optimal twi tx/rx

Hi - I am wondering what is the power optimal way to read/write with the TWI module. I do a tx and rx with the TWI interface. I have something like this, from the examples to read data from a i2c supported device:

// read from i2c device

uint16_t timeout = 10000;
nrf_drv_twi_tx();

while((!twi_tx_done) && --timeout); // twi_tx_done is in the twi_handler for NRF_DRV_TWI_XFER_TX event
twi_tx_done = false;

timeout = 10000;
nrf_drv_twi_rx();
while((!twi_rx_done) && --timeout); // twi_rx_done is in the twi_handler for NRF_DRV_TWI_XFER_RX event
twi_rx_done = false;

I am not sure if this is the most optimal way of waiting, since it's in a busy loop. Is there a better way to write this?

Parents Reply
  • Not sure what other factors may be involved?

    Common things include:

    • You might need some things to stay active/responsive while you sleep;
    • The more you shut down, the more you have to wake up again to get back into "normal operation";
    • The deeper you sleep, the longer it takes to wake again;
    • Deeper sleep options often have more limited wakeup options;
    • etc, etc, ...

    As says, many (most?) of the SDK examples illustrate sleeping while waiting for events ...

Children
Related