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

Putting I2C peripheral back into lowest power state

I am using an NRF52832 on an energy harvesting board where lowest power is critical.  I can achieve ~2 uA current consumption in idle state (waiting on RTC interrupt), wake up to perform some processing, then return to ~2 uA current consumption.  However, as soon as I use the I2C peripheral (simply writing to a non-existent I2C device) in my wake-up state, the current consumption jumps to ~200 uA and never goes back down again. I am programming the device using mbed-os, which I know does not call the necessary HW clean-up when the I2C device is deleted, hence I am cleaning up the I2C peripheral registers myself.

Below is the code I am using to shut-down the I2C peripherals (both of them, since I can't be sure which one mbed-os is using) after deleting it at mbed-os level. What am I missing?

NRF_TWIM0->TASKS_STOP = 0x01;
wait_ms(1);
NRF_TWIM0->ENABLE = 0;
NVIC_DisableIRQ((IRQn_Type) (((uint32_t) NRF_TWIM0) >> 12U));
NRF_TWIM0->SHORTS = 0;
NRF_TWIM0->INTENCLR = 0xFFFFFFFF;
NRF_TWIM0->ERRORSRC = NRF_TWIM0->ERRORSRC;
*((volatile uint32_t *)((uint8_t *)NRF_TWIM0 + (uint32_t)(NRF_TWI_EVENT_STOPPED |
                                                          NRF_TWI_EVENT_RXDREADY |
                                                          NRF_TWI_EVENT_TXDSENT |
                                                          NRF_TWI_EVENT_ERROR |
                                                          NRF_TWI_EVENT_BB |
                                                          NRF_TWI_EVENT_SUSPENDED))) = 0;
NRF_TWIM0->PSEL.SCL = 0xFFFFFFFF;
NRF_TWIM0->PSEL.SDA = 0xFFFFFFFF;

NRF_TWIM1->TASKS_STOP = 0x01;
wait_ms(1);
NRF_TWIM1->ENABLE = 0;
NVIC_DisableIRQ((IRQn_Type) (((uint32_t) NRF_TWIM1) >> 12U));
NRF_TWIM1->SHORTS = 0;
NRF_TWIM1->INTENCLR = 0xFFFFFFFF;
NRF_TWIM1->ERRORSRC = NRF_TWIM1->ERRORSRC;
*((volatile uint32_t *)((uint8_t *)NRF_TWIM1 + (uint32_t)(NRF_TWI_EVENT_STOPPED |
                                                          NRF_TWI_EVENT_RXDREADY |
                                                          NRF_TWI_EVENT_TXDSENT |
                                                          NRF_TWI_EVENT_ERROR |
                                                          NRF_TWI_EVENT_BB |
                                                          NRF_TWI_EVENT_SUSPENDED))) = 0;
NRF_TWIM1->PSEL.SCL = 0xFFFFFFFF;

NRF_TWIM1->PSEL.SDA = 0xFFFFFFFF;

Rob

Related