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

How to close UART to save power for nRF52810

Hi,

I'm using SDK v14.2 and s112_5.1.0 for nRF52810 basing on the ble_app_uart example. Now we use the uart to communicate with external MCU. Also we want to close uart to save power when there is no data transmitting. I have used the BSP module to configure a gpio to control the UART, enable the UART when the gpio level is low, disable the UART when the gpio level is high. But if I enabled or disable UART in the bsp_event_handler, it couldn't be successful and it would stop running. Is there any problem with the function? Could you give me some advice how to do is better?

Enabled UART:

void app_uart_open(void){
uint32_t                     err_code;
const app_uart_comm_params_t  comm_params =
{
    .rx_pin_no    = RX_PIN_NUMBER,
    .tx_pin_no    = 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,
    .baud_rate    = UARTE_BAUDRATE_BAUDRATE_Baud9600
};

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);}

Disabled UART:

uint32_t app_uart_close(void){
nrf_drv_uart_uninit(&app_uart_inst);
return NRF_SUCCESS;}

BSP event:

void bsp_event_handler(bsp_event_t event){
switch (event)
{
    case BSP_EVENT_UART_SLEEP:			
	app_uart_close();									
        break;

    case BSP_EVENT_UART_WORK:
    app_uart_open();																							
        break;
}}
  • I'm still not sure what you are trying to achieve here, but it seems like when:

    1. you press the button bsp_event_handler() is called with event BSP_EVENT_UART_WORK
    2. uart_status is set to 2
    3. After that handle_uart_sta() is called from main context
    4. Since uart_status = 2 NRF_UARTE0->ENABLE is set to 8 (enabled).
    5. Average current consumptions is ~750uA

    As long as you keep the button pressed the UART still works. When you release the button though:

    1. bsp_event_handler() is called again with event BSP_EVENT_UART_SLEEP
    2. uart_status is set to 1
    3. After that handle_uart_sta() is called from main context
    4. Since uart_status = 1 NRF_UARTE0->ENABLE is set to 0 (disabled).
    5. Average current consumptions goes down to ~190uA

    So i.e. after you have pushed and released the button the UART is disabled.

    Is this your problem?

  • For our application, if the MCU want to send data to the 52810 module via uart, it will keep P0.31 low until finishing sending data then let the P0.31 high to save power.

    There's no problem that just pushed and released the button much time, because the uart still could output 0x55 0x66 in the handle_uart_sta function.

    But the problem is, once the uart has received data,for example,use UART terminal on the PC to send data to nRF52810, it will get stuck and there's no any reaction push and releas the button at this time.

  • Is it stuck in app_error_fault_handler()? Have you debugged and checked the error code, line number, and file name?

Related