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

nrf9160 disabling uart for sleeping and re-enabling not working as expected

NCS 1.4.2

modem fw 1.2.3

We have a custom board with 3 uarts:

Uart 0 -> debug output (testing only)

Uart 1 -> BLE

Uart 2 -> External GPS

I have been trying to disable the uart when not in use which seems to work (I think) but then when i restart the uart it does not work until I issue another nrf_uarte_enable(NRF_UARTE0) command.

Here is the code for disabling the uart:

uint8_t waiting = 0;
bool disable_uart()
{
  waiting = 0;

  // NRF_UARTE1_NS->TASKS_STOPTX = 1;
  NRF_UARTE1_NS->TASKS_STOPRX = 1;
  
  //we have to wait for the RXTO event before using nrf_uarte_disable
  while((NRF_UARTE1_NS->EVENTS_RXTO==0 )  && waiting <100)
  {
    waiting++;
    k_sleep(1);
  }
  nrf_uarte_disable(NRF_UARTE1); 
  gpio_pin_configure(gpio_dev, uart1TX, GPIO_INPUT | GPIO_PULL_DOWN);
  gpio_pin_configure(gpio_dev, uart1RX, GPIO_INPUT | GPIO_PULL_DOWN);

  //if process went successful, waiting will not have timed out
  if (waiting < 100)
    return true;
  else
    return false;

}

and here is the code for re-enabling the uart:

NRF_UARTE1_NS->TASKS_STARTRX = 1;
NRF_UARTE1_NS->TASKS_STARTTX = 1;
 nrf_uarte_enable(NRF_UARTE1);

 uart_irq_rx_enable(uart_ble);

I do not receive any data with the above block does. I have to add the nrf_uarte_enable(NRF_UARTE1) before the STARTRX =1 for it to work:

nrf_uarte_enable(NRF_UARTE1);
NRF_UARTE1_NS->TASKS_STARTRX = 1;
NRF_UARTE1_NS->TASKS_STARTTX = 1;
nrf_uarte_enable(NRF_UARTE1);

uart_irq_rx_enable(uart_ble);

I am sure I am making a very simple mistake, if you can please help me out here.

Regards

Noaman

Parents Reply Children
No Data
Related