Bluetooth: Central UART

The Central UART sample demonstrates how to use the Nordic UART Service (NUS) Client. It uses the NUS Client to send data back and forth between a UART connection and a Bluetooth® LE connection, emulating a serial port over Bluetooth LE.

Requirements

The sample supports the following development kits:

Hardware platforms

PCA

Board name

Board target

nRF54LV10 DK

PCA10188

nrf54lv10dk

nrf54lv10dk/nrf54lv10a/cpuapp/ns nrf54lv10dk/nrf54lv10a/cpuapp

nRF54LM20 Dongle

PCA10208

nrf54lm20dongle

nrf54lm20dongle/nrf54lm20b/cpuapp

nRF54LM20 DK

PCA10184

nrf54lm20dk

nrf54lm20dk/nrf54lm20b/cpuapp/ns nrf54lm20dk/nrf54lm20b/cpuapp nrf54lm20dk/nrf54lm20a/cpuapp/ns nrf54lm20dk/nrf54lm20a/cpuapp

nRF54LC10 DK

PCA10226

nrf54lc10dk

nrf54lc10dk/nrf54lc10a/cpuapp/ns nrf54lc10dk/nrf54lc10a/cpuapp

nRF54L15 DK

PCA10156

nrf54l15dk

nrf54l15dk/nrf54l15/cpuapp/ns nrf54l15dk/nrf54l15/cpuapp

nRF54L15 DK (emulating nRF54L10)

PCA10156

nrf54l15dk

nrf54l15dk/nrf54l10/cpuapp

nRF54L15 DK (emulating nRF54L05)

PCA10156

nrf54l15dk

nrf54l15dk/nrf54l05/cpuapp

nRF54H20 DK

PCA10175

nrf54h20dk

nrf54h20dk/nrf54h20/cpuapp

nRF5340 DK

PCA10095

nrf5340dk

nrf5340dk/nrf5340/cpuapp/ns nrf5340dk/nrf5340/cpuapp

nRF52 DK

PCA10040

nrf52dk

nrf52dk/nrf52832

nRF52840 DK

PCA10056

nrf52840dk

nrf52840dk/nrf52840

nRF21540 DK

PCA10112

nrf21540dk

nrf21540dk/nrf52840

For more security, it is recommended to use the */ns variant of the board target. When built for this variant, the sample is configured to compile and run as a non-secure application using security by separation. Therefore, it automatically includes Trusted Firmware-M that prepares the required peripherals and secure services to be available for the application.

The sample also requires another development kit running a compatible application (see Bluetooth: Peripheral UART).

Overview

When connected to a Bluetooth LE device implementing the Nordic UART Service (NUS), the sample relays data between a UART peripheral and the Bluetooth LE connection. On Nordic Semiconductor’s development kits, the UART peripheral is typically gated through the SEGGER chip to a USB CDC ACM virtual serial port.

nRF54LM20 Dongle USB CDC ACM interfaces

The nRF54LM20 Dongle does not have a built-in SEGGER chip, so on this board, the sample implements the USB CDC ACM device class with several interfaces for different purposes. When you plug the dongle into a USB port, the following interfaces are available:

Index

Label

Purpose

0

(no label)

Zephyr console (logging)

1

NUS

Nordic UART Service

2

nRF54LM20 Dongle MCUmgr

MCUmgr (used by nRF Util to reset the device to bootloader during DFU)

User interface

Green LED:

Lit when connected over Bluetooth LE. Blinks briefly when data is sent or received over Bluetooth LE.

Blue LED:

Blinks when debug messages are emitted.

Debugging

Depending on the board, this sample uses either the SEGGER J-Link RTT or a USB CDC ACM interface to display debug messages.

The sample uses the CDC ACM interface with index 0 for debug logging (see nRF54LM20 Dongle USB CDC ACM interfaces). Open the interface in a terminal emulator to view debug messages.

FEM support

You can add support for the nRF21540 front-end module to this sample by using one of the following options, depending on your hardware:

  • Build the sample for one board that contains the nRF21540 FEM, such as nRF21540 DK.

  • Manually create a devicetree overlay file that describes how the nRF21540 FEM is connected to the SoC. See Configuring devicetree for different ways of adding the overlay file.

  • Provide nRF21540 FEM capabilities by using a shield, for example the nRF21540 EK shield that is available in the nRF Connect SDK. In this case, build the project for a board connected to the shield you are using with an appropriate variable included in the build command, for example -DSHIELD=nrf21540ek. This variable instructs the build system to append the appropriate devicetree overlay file.

    To build the sample in nRF Connect for VS Code for an nRF52840 DK with the nRF21540 EK attached, add the shield variable in the build configuration’s Extra CMake arguments and rebuild the build configuration. For example: -DSHIELD=nrf21540ek.

    See How to work with build configurations in the nRF Connect for VS Code documentation for more information.

    See Programming nRF21540 EK for information about how to program when you are using a board with a network core, for example the nRF5340 DK.

Each of these options adds the description of the nRF21540 FEM to the devicetree. See Developing with Front-End Modules for more information about FEM in the nRF Connect SDK.

To add support for other front-end modules, add the respective devicetree file entries to the board devicetree file or the devicetree overlay file.

Building and running

This sample can be found under samples/bluetooth/central_uart in the nRF Connect SDK folder structure.

For more security, it is recommended to use the */ns variant of the board target (see the Requirements section above.) When built for this variant, the sample is configured to compile and run as a non-secure application using security by separation. Therefore, it automatically includes Trusted Firmware-M that prepares the required peripherals and secure services to be available for the application.

To build the sample, follow the instructions in Building an application for your preferred building environment. See also Programming an application for programming steps and Testing and optimization for general information about testing and debugging in the nRF Connect SDK.

Note

When building repository applications in the SDK repositories, building with sysbuild is enabled by default. If you work with out-of-tree freestanding applications, you need to manually pass the --sysbuild parameter to every build command or configure west to always use it.

When building this sample with Sysbuild for an SoC that has a network core, the IPC radio firmware is automatically applied to the build. The IPC radio is one of the companion components in the nRF Connect SDK and allows to use the radio peripheral from another core in a multicore device. If needed, you can modify the IPC radio configuration in the prj.conf source file in the sample’s sysbuild/ipc_radio directory.

Testing

After programming the sample to your development kit, complete the following steps to test it:

  1. Connect the kit to the computer using a USB cable. The kit is assigned a serial port. Serial ports are referred to as COM ports on Windows, /dev/ttyACM devices on Linux, and /dev/tty devices on macOS. To list Nordic Semiconductor devices connected to your computer together with their serial ports, open a terminal and run the nrfutil device list command. Alternatively, check your operating system’s device manager or its equivalent.

  2. Connect to the kit that runs this sample with a terminal emulator (for example, the Serial Terminal app). See Testing and optimization for the required settings and steps.

    Note

    On the nRF54LM20 Dongle, the sample uses the USB CDC ACM interface with index 1 for NUS data (see nRF54LM20 Dongle USB CDC ACM interfaces).

  3. Optionally, view debug messages as described in Debugging.

  4. Reset the kit.

  5. Observe that the text “Starting Bluetooth Central UART sample” is printed on the COM listener running on the computer and the device starts scanning for Peripherals with NUS.

  6. Program the Bluetooth: Peripheral UART sample to the second development kit. See the documentation for that sample for detailed instructions.

  7. Observe that the kits connect.

    When service discovery is completed, the event logs are printed on the Central’s terminal. Now you can send data between the two kits.

  8. To send data, type some characters in the terminal of one of the kits and press Enter. Observe that the data is displayed on the UART on the other kit.

  9. Disconnect the devices by, for example, pressing the Reset button on the Central. Observe that the kits automatically reconnect and that it is again possible to send data between the two kits.

Dependencies

This sample uses the following nRF Connect SDK libraries:

In addition, it uses the following Zephyr libraries:

  • include/zephyr/types.h

  • boards/arm/nrf*/board.h

  • Kernel Services:

    • include/kernel.h

  • Peripherals:

    • include/uart.h

  • API:

    • include/bluetooth/bluetooth.h

    • include/bluetooth/gatt.h

    • include/bluetooth/hci.h

    • include/bluetooth/uuid.h

The sample also uses the following secure firmware component: