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

The correct procedure to uninit uarte then reinitialize it

I'm developing a project that use BLE advertise and uart communication with other uC.

The uart part is based on libuarte example. To decrease the current consumption, I think we must uninit uarte before system sleep, then reinitialize it when wakeup.

void uc_deInit()
{
  if(uartInited){
    nrf_libuarte_async_uninit(&libuarte);
 
  //when uarte inited then uninit, current consumption keep higher about 0.8ma, workarounds below
  //@refers https://devzone.nordicsemi.com/f/nordic-q-a/26030/how-to-reach-nrf52840-uarte-current-supply-specification/102605#102605
  //If you are using UARTE1 the base address is 0x40028000
  
  *(volatile uint32_t *)0x40002FFC = 0;
  *(volatile uint32_t *)0x40002FFC;
  *(volatile uint32_t *)0x40002FFC = 1;
  }
  uartInited = false;
  
}

void uc_init()
{
    ret_code_t err_code;
    uc_deInit();
    nrf_libuarte_async_config_t nrf_libuarte_async_config = {
            .tx_pin     = UC_TX_PIN,
            .rx_pin     = UC_RX_PIN,
            .baudrate   = UARTE_BAUDRATE_BAUDRATE_Baud1M,
            .parity     = NRF_UARTE_PARITY_EXCLUDED,
            .hwfc       = NRF_UARTE_HWFC_DISABLED,
            .timeout_us = 100, //86us/byte
            .pullup_rx  = false,//true,
            .int_prio   = APP_IRQ_PRIORITY_HIGH
    };

    err_code = nrf_libuarte_async_init(&libuarte, &nrf_libuarte_async_config, uart_event_handler, (void *)&libuarte);
    uartInited = true;
    APP_ERROR_CHECK(err_code);

    nrf_libuarte_async_enable(&libuarte);
}
 

Everything works before first sleep, when uc_deInit() executed then uc_init(), the NRF stop receiving but transmit works, I can confirm the UC received the NRF tx packet and response, but uart_event_handler never triggered.

So, what is the correct procedure for my purpose?

Thanks.

Related