nRF5 SDK is not maintained anymore
More Info: Consider nRF Connect SDK for new designs

Disabling peripherals and default state of GPIOTE

Hello dear nRF people!

I am going thorough the various power optimization techniques and over and over again I come across the following advice here on the DevZone:

Disable the peripheral before going to systemON state.

I'm struggling to find out the proper procedure to disable the peripheral and then enable them again. I am developing nRF52832 on a custom board,  using nRF-SDK v17.1.0. 

I have a classic sensor, a LIS3DH hanging on the TWI0 peripheral, that gets periodically readout (in the RTC handler routine). My procedure is something like this:

void timer_handler(){
    NRF_TWI0->ENABLE = TWI_ENABLE_ENABLE_Enabled << TWI_ENABLE_ENABLE_Pos;
    float sensor_data = lis3dh_readout();
    printf("\n\rInclination: %.3f", sensor_data);
    NRF_TWI0->ENABLE = TWI_ENABLE_ENABLE_Disabled << TWI_ENABLE_ENABLE_Pos;
}

void main(){
...

    while (true){
    
        idle_state_handle();
    }
}

The issue I have here is that current consumption is the same (cca 340uA) regardless of whether I leave or delete `NRF_TWI0->ENABLE` lines. An Nordic Engineer Kenneth here was pointing out in another thread that I should make sure that GPIOs are in a right state once my TWI gets disabled. I was not sure what that exactly means, but I decided to initialize the GPIOTE as an active high output before going to the `while` loop, like this:

// Config TWI pins as for a default state 
nrf_drv_gpiote_out_config_t out_config = GPIOTE_CONFIG_OUT_SIMPLE(true);  // configure to be output high
err_code = nrf_drv_gpiote_out_init(I2C_SCL_PIN, &out_config);
APP_ERROR_CHECK(err_code);
err_code = nrf_drv_gpiote_out_init(I2C_SDA_PIN, &out_config);
APP_ERROR_CHECK(err_code);

But it didnt help reducing the consumption. What am I doing wrong? What is the right way to disable a peripheral and then enable it again. Do I need to reinitialize every time? What if I need to store the sensor state?

P.S. I was reading in the  Errata that GPIOTE has some issues with high consumption so I implemented a workaround from [89] and [97] (put GPIOTE sense in PORT EVENT mode). But I had no success in reducing the current consumption. 

Parents Reply Children
Related