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 |
|
|---|---|---|---|
nRF54LV10 DK |
PCA10188 |
|
|
PCA10208 |
nrf54lm20dongle |
|
|
PCA10184 |
|
||
nRF54LC10 DK |
PCA10226 |
nrf54lc10dk |
|
PCA10156 |
|
||
PCA10156 |
|
||
PCA10156 |
|
||
PCA10175 |
|
||
PCA10095 |
|
||
PCA10040 |
|
||
PCA10056 |
|
||
PCA10112 |
|
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.
See the list of supported boards in Requirements. No buttons and LEDs are used.
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.
See the list of supported boards in Requirements.
The sample uses the SEGGER J-Link RTT for debug logging. To view debug messages, follow the procedure in Testing and optimization.
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.
To build the sample from the command line for an nRF52840 DK with the nRF21540 EK attached, use the following command within the sample directory:
west build -b nrf52840dk/nrf52840 -- -DSHIELD=nrf21540ekSee 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:
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 listcommand. Alternatively, check your operating system’s device manager or its equivalent.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).
Optionally, view debug messages as described in Debugging.
Reset the kit.
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.
Program the Bluetooth: Peripheral UART sample to the second development kit. See the documentation for that sample for detailed instructions.
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.
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.
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.hboards/arm/nrf*/board.h-
include/kernel.h
-
include/uart.h
API:
include/bluetooth/bluetooth.hinclude/bluetooth/gatt.hinclude/bluetooth/hci.hinclude/bluetooth/uuid.h
The sample also uses the following secure firmware component: