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