1.. zephyr:code-sample:: uart_async 2 :name: UART ASYNC API 3 :relevant-api: uart_interface 4 5 Demonstrate the use of the asynchronous API 6 7Overview 8******** 9 10This sample demonstrates how to use the UART serial driver asynchronous 11API through a simple packet transmitter. 12 13Every 5 seconds, 1 to 4 data payloads are generated and queued for 14transmission. Every other 5 second period, receiving is enabled through 15the asynchronous API. 16 17By default, the UART peripheral that is normally used for the Zephyr shell 18is used, so that almost every board should be supported. 19 20Building and Running 21******************** 22 23Build and flash the sample as follows, changing ``nrf52840dk/nrf52840`` for 24your board: 25 26.. zephyr-app-commands:: 27 :zephyr-app: samples/drivers/uart/async_api 28 :board: nrf52840dk/nrf52840 29 :goals: build flash 30 :compact: 31 32Sample Output 33============= 34 35.. code-block:: console 36 37 Loop 0: Packet: 0 38 Loop 0: Packet: 1 39 Loop 0: Packet: 2 40 [00:00:05.001,919] <inf> sample: Loop 0: Sending 3 packets 41 [00:00:05.002,008] <inf> sample: RX is now enabled 42 Loop 1: Packet: 0 43 [00:00:10.002,086] <inf> sample: Loop 1: Sending 1 packets 44 [00:00:10.002,138] <inf> sample: RX is now disabled 45 Loop 2: Packet: 0 46 Loop 2: Packet: 1 47 [00:00:15.002,215] <inf> sample: Loop 2: Sending 2 packets 48 [00:00:15.002,293] <inf> sample: RX is now enabled 49 [00:00:15.009,010] <inf> sample: RX_RDY 50 68 65 6c 6c 6f 0a |hello. 51 Loop 3: Packet: 0 52 Loop 3: Packet: 1 53 Loop 3: Packet: 2 54 [00:00:20.002,343] <inf> sample: Loop 3: Sending 3 packets 55 [00:00:20.002,424] <inf> sample: RX is now disabled 56 57Note that because the UART transmissions are triggered directly, they will 58appear in the serial logs **before** the ``LOG_INF`` message at the top of 59the loop, since log writes are typically deferred by several seconds 60