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

How can I enable and disable UART devices at run time on nRF9160?

I need to enable UART1 in runtime in order to be able to read some data coming on that device.

In order to be able to use the uart functionality, I need to set CONFIG_SERIAL=y, otherwise I get compilation errors. So I wonder how can I disable all uart devices and then enable them back on runtime.

I read this thread, but when I tried to implement it for both UART0 and UART1, the application hang.


This how I try to do it:

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
void disable_uart()
{
NRF_UARTE1_NS->TASKS_STOPRX=1;
while(NRF_UARTE1_NS->EVENTS_RXTO == 0);
NRF_UARTE1_NS->EVENTS_RXTO = 0;
NRF_UARTE1_NS->TASKS_STOPTX = 1;
while(NRF_UARTE1_NS->EVENTS_TXSTOPPED == 0);
NRF_UARTE1_NS->EVENTS_TXSTOPPED = 0;
NRF_UARTE1_NS->ENABLE = 0;
NRF_UARTE1_NS->PSEL.TXD = 0xFFFFFFFF;
NRF_P0_NS->OUTCLR = (1 << 1);
NRF_UARTE0_NS->TASKS_STOPRX=1;
while(NRF_UARTE0_NS->EVENTS_RXTO == 0);
NRF_UARTE0_NS->EVENTS_RXTO = 0;
NRF_UARTE0_NS->TASKS_STOPTX = 1;
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX


So what am I missing?

Thank you very much for your assistance!