In order to interact with the UART, you need to first declare a device struct and then get a binding to the device:
static struct device *uart; ... uart = device_get_binding("UART_1");
Then in order to switch the UART on and off you need to do:
uart_off() { NRF_UARTE1_NS->TASKS_STOPTX = 1; NRF_UARTE1_NS->TASKS_STOPRX = 1; NRF_UARTE1_NS->ENABLE = 0; } uart_on() { NRF_UARTE1_NS->ENABLE = 8; NRF_UARTE1_NS->TASKS_STARTRX = 1; NRF_UARTE1_NS->TASKS_STARTTX = 1; }
But I wonder if there is a way to write a function that will take as input a string like "UART_1" and will perform the power on and off of the specified device.
What I have found out so far is that you can write a function like this:
void uart_power_on(NRF_UARTE_Type* dev) { dev->ENABLE = 8; dev->TASKS_STARTRX = 1; dev->TASKS_STARTTX = 1; }
And use as argument for UART1 for example NRF_UARTE1_NS.
In this way I can power on the device again. But what I would like to do is initialize the device and power it on or off in one function with the same argument.
Any ideas?