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

Multiple serial "ports" on nRF51822, e.g., using app_uart module from SDK with UIDs?

Folks, I'd like to use the single UART peripheral in the nRF51822 in interleaved fashion to support two serial "ports", e.g., sets of GPIO pins dedicated to separate serial channels.

Is the version of the app_uart module in SDK 4.4.2 (because I have "C0" chips right now) which assigns UIDs designed for this purpose? I infer that it is from the SDK documentation, but could clearly be wrong here :)

If so, is there a state machine diagram, etc., for this scenario? For example, do I call app_uart_init (the version that issues UIDs repeatedly) to assign all the ports I want? But then how do I switch between them? Or do I bracket each port's usage of the peripheral with an app_uart_init/app_uart_close pair? If so, what happens when I open a specific port the second time? Do I supply the former UID and it gets reused? Or do I set the UID parameter to 0 and it gets a new value (which seems to be useless then)?

Haven't been able to answer these questions myself from the SDK docs and haven't found an example use of the app_uart module with UIDs in sample code. Am I missing something?

TIA,

Mike

  • Yes, you need to bracket usage of each port with app_uart_init and app_uart_close, and you should reuse the UID you got back from the first app_uart_init when re-initializing a peripheral.

    I've been doing something similar; note, however, I've found that app_uart_close does not do a proper shutdown; it disables the UART before receive/transmit are finished, resulting in lost data if transmit or receive are happening at the time of shutdown (you'll be fine if you pre-arrange with the other device to shut down first). I'll be making a post on the issue I found and a fix (search on app_uart_close).

  • The C0 still works with SDK6, SDK5 too. You are not stuck with 4. I don't recall app_uart issuing UID. Do you mean UID for BLE ? You don't need to reinit each time. You just need to switch pin map for the UART, provide 2 both use the same baudrate. But that is only good for transmit, you may have issue on receive. Unless you use hardware handshaking.

Related