Hello everyone,
I have a problem with the power consumption of the NRF52 during TWI operations with tw0 HTU21DF temperature and humidity sensors.
I am using NRF52832 with SDK 15.0.0 and softdevice S132 V6.00 on a custom board.
I use 2 different twi interfaces for 2 separate sensors, and I use non blocking operations; twi readings are periodical and triggered by a timer.
All readings are correct, the callback are called normally, but the problem I get is that reading from both sensors consumes about 10 mA for 100 ms,
which in my opinion is an indication that the cpu does not go properly to sleep while waiting for the callbacks.
Here is my code for init of the twi interfaces
/**@brief Initialization of the TWI interfaces */ void twi_init (void) { ret_code_t err_code; err_code = nrf_drv_twi_init(&m_twi_one, &twi_one_config, twi_OneCallback, NULL); APP_ERROR_CHECK(err_code); nrf_drv_twi_enable(&m_twi_one); err_code = nrf_drv_twi_init(&m_twi_two, &twi_two_config, twi_TwoCallback, NULL); APP_ERROR_CHECK(err_code); nrf_drv_twi_enable(&m_twi_two); }
Here is the cycle for reading humidity and temperature as required by the sensor datasheet (I report only one of the functions, the other is identical)
static void read_twi_one_data() { ret_code_t err_code; twi_one_done = false; err_code = nrf_drv_twi_tx(&m_twi_one, HTU21DF_I2CADDR, htu21cmd_ReadHum, sizeof (htu21cmd_ReadHum), false); APP_ERROR_CHECK(err_code); do { idle_state_handle(); }while(!twi_one_done); twi_one_done = false; err_code = nrf_drv_twi_rx(&m_twi_one, HTU21DF_I2CADDR, twi_oneHumidity, sizeof(twi_oneHumidity)); do { idle_state_handle(); }while(!twi_one_done); twi_one_done = false; err_code = nrf_drv_twi_tx(&m_twi_one, HTU21DF_I2CADDR, htu21cmd_ReadTemp, sizeof (htu21cmd_ReadTemp), false); do { idle_state_handle(); }while(!twi_one_done); twi_one_done = false; err_code = nrf_drv_twi_rx(&m_twi_one, HTU21DF_I2CADDR, twi_oneTemperature, sizeof(twi_oneTemperature)); do { idle_state_handle(); }while(!twi_one_done); APP_ERROR_CHECK(err_code); }
And finally here is the code managing the callback where I simply put the flag to true to exit from the while cycle
void twi_OneCallback(nrf_drv_twi_evt_t const * p_event, void * p_context) { switch (p_event->type) { case NRF_DRV_TWI_EVT_DONE: twi_one_done = true; break; default: break; } }
At the end of the operations, I uninit and disable the TWIs to save energy.
I read several discussions on the forum, and almost everywhere I found that this is the correct way to handle TWI communications, but it seems to me that the idle_state_handle() function is actually not putting the device to sleep while waiting for the callback.
I activated the EASY_DMA for the TWI.
Any idea would be welcome, because 10mA for 100ms is quite a big consumption for our needs (when sampling at fastest rate, we may need one sample every second, which will mean a consumption of 10mA, for 100 ms every second....).
Thanks in advance.