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

"app_uart_close()" cannot disable UART

Hi I am now working on a project which I use ble_app_uart_c as a reference. SDK 15.2 and used softdevice s132. In the project I need to disable the UART before it enters into System ON sleep mode. But when I measure the current using the PPK, the current consumption doesn't change after I close the UART using "app_uart_close". In the following snippet, you will see, I just initialize the UART module and close it after 5seconds. But the current consumption is still the same as shown in the figurre.

static void uart_init(void)
{
	uint32_t                     err_code;
	app_uart_comm_params_t const comm_params =
	{
		.rx_pin_no    = 8/*RX_PIN_NUMBER*/,
		.tx_pin_no    = 6/*TX_PIN_NUMBER*/,
		.rts_pin_no   = RTS_PIN_NUMBER,
		.cts_pin_no   = CTS_PIN_NUMBER,
		.flow_control = APP_UART_FLOW_CONTROL_DISABLED,
		.use_parity   = false,
#if defined (UART_PRESENT)
		.baud_rate    = UARTE_BAUDRATE_BAUDRATE_Baud115200
#else
		.baud_rate    = NRF_UARTE_BAUDRATE_115200
#endif
	};

	APP_UART_FIFO_INIT(&comm_params,
	                   UART_RX_BUF_SIZE,
	                   UART_TX_BUF_SIZE,
	                   uart_event_handle,
	                   APP_IRQ_PRIORITY_LOWEST,
	                   err_code);
	APP_ERROR_CHECK(err_code);
}

int main(void)
{
	uart_init();
	nrf_delay_ms(5000);	
	app_uart_close();
	nrf_delay_ms(100);
	
	for(;;)
	{

		idle_state_handle();
	}
	
}

Here is the one in which I just directly goes to system ON sleep and the current consumption is way more reduced.

int main(void)
{
	//uart_init();
	nrf_delay_ms(5000);	
	//app_uart_close();
	nrf_delay_ms(100);
	
	for(;;)
	{

		idle_state_handle();
	}
	
}

What's the reason for this. Is there any more else to do to disable UART totally? Really needs your help. Thanks.

Parents
  • Hi 

    Could you try to run the following line of code before calling app_uart_close():

    NRF_UART0->TASKS_STOPRX = 1;

    It is possible that the UART RX is not completely disabled, and that the HF clock is requested in sleep (which increases sleep current significantly). 

    Best regards
    Torbjørn

  • I even tried this code snippet which I found in this link but still the current consumption is the same.

    void disabled_uart(void) {
      uint32_t err_code = app_uart_close();
    //  APP_ERROR_CHECK(err_code);
      NRF_UARTE0->TASKS_STOPTX = 1;
      NRF_UARTE0->TASKS_STOPRX = 1;
      NRF_UARTE0->ENABLE = 0;
      /* Workaround by disabling the UART peripherals due to Nordic SDK15.0 issue */
      *(volatile uint32_t *)0x40002FFC = 0; /* Power down UARTE0 */
      *(volatile uint32_t *)0x40002FFC;     
      *(volatile uint32_t *)0x40002FFC = 1; /* Power on UARTE0 so it is ready for next time */
    }
    int main(void)
    {
        uart_init();
    	nrf_delay_ms(5000);	
    	//NRF_UART0->TASKS_STOPRX = 1;
    	disable_UART();
    	nrf_delay_ms(100);
    	//NRF_POWER->SYSTEMOFF = 1;
    	for(;;)
    	{
    		idle_state_handle();
    	}
    	
    }

  • Hi I found one more thing. I forgot to mention this earlier. The nrf52832 ble chip is connected to ESP32 via UART and most of the time ESP32 will go into deepsleep mode. What I found out is that the UART from nrf52832 can close successfully if the ESP32 is in idle state and cannot close after ESP32 chip goes into deepsleep mode.

    int main(void)
    {
    	
    	// Initialize.
    
    	timer_init();
    	//uart_init();
    
    	//nrf_gpio_cfg_output(PIN_BLE_INT); // gpio_init
    
    	buttons_leds_init();
    	db_discovery_init();
    	power_management_init();
    	ble_stack_init();
    	gatt_init();
    	nus_c_init();
    	scan_init();
    
    	uart_init();
    	nrf_delay_ms(50);
    
    	
    	for(;;)
    	{
    		
    		app_uart_close();
    		idle_state_handle();
    	}
    }

    when app_uart_close() function is used before esp32 goes into deepsleep.

    when app_uart_close() function is used after esp32 goes into deepsleep.

    Please!! need your help quite urgently.

  • I got it. I just added "nrf_gpio_cfg_input(RX_PIN_NUMBER,NRF_GPIO_PIN_PULLUP);" after APP_UART_FIFO_INIT as in this link .

  • Hi ,

    I am using same hardware. did u got any issue like no data from nrf52 tx line when system is live for long days?

    I am using continuous data transmission but after some days UART gets Stucked somewhere.

    Please let me know if you have any observations for the same.

Reply Children
Related