I noticed that having the UART enabled on my application in a NRF52 (SD132, SDK 11.0.0) takes a lot of current consumption. If I completely disable any UART support on my application the current consumption drops dramatically. I can't do that, but considering my device will be 99% of the time idle, I need to disabled the UART before I put the processor to sleep.
I am using FreeRTOS so what I did is I enabled the ApplicationIdleHook and did as follows:
/* FreeRTOS application idle hook */
void vApplicationIdleHook(void) {
// Disable UART transmission and reception
bool uart_disabled = false;
if (!nrf_drv_uart_tx_in_progress()) {
NRF_UART0->TASKS_SUSPEND = 1;
//NRF_UART0->ENABLE = 0;
uart_disabled = true;
}
__WFI();
if (uart_disabled) {
//NRF_UART0->ENABLE = 1;
NRF_UART0->TASKS_STARTTX = 1;
NRF_UART0->TASKS_STARTRX = 1;
}
}
That theoretically should suspend the UART but unfortunately it increases current consumption compared to simply doing __WFI() and leaving the UART as it is. Notice that if I enable the lines where I do NRF_UART0->ENABLE = 0
and NRF_UART0->ENABLE = 1
the UART simply stops working.
I wonder that is the right way to disable the UART when you go to sleep.