UART (HDLC)
This section refers to the following sample application(s):
02-uart
The UART serial port can be used by a computer or external microcontroller to communicate with your application. The
chip provides hardware-accelerated HDLC support for the UART port.
Your application can set up the UART device to trigger a notification whenever a valid HDLC frame is received over the serial port. The frame contained in this notification has already passed CRC verification, and the HDLC flags and escape characters have been removed. Similarly, your application can send a data frame over UART; the device will take care of the HDLC framing, character escaping and CRC calculation.
The 02-uart Sample Application
The 02-uart sample application creates two tasks, and defines 3 CLI commands. A companion Python script uart_app.py runs on your computer and connects to the UART API port of your device.
Setup
The diagram below illustrates the setup for running this sample application:
Your computer and
are connected over a USB cable.
Your
is programmed with the
02_uartsample application.Your computer runs the following:
The
uart_app.pyPython script (available in the/app/02-uart/directory).A terminal client to enter CLI commands for the
.
You need to know the API and CLI serial ports corresponding to your
. You will connect the uart_app.py Python script to the API port, and the terminal client to the CLI port.
Refer to the SmartMesh IP Tools Guide for information about how to identify the different serial ports.
Overview
The 02-uart sample application creates 2 tasks.
the
uartTxTasktask transmits a number of UART frames from yourto the
uart_app.pyPython script. The number of frames to send, their length, and the inter-frame delay are set using CLI commands.the
uartRxTasktask listens for incoming UART frames, sent in this case by the theuart_app.pyPython script.
The 02-uart sample application defines 3 CLI commands:
use
lento specify the length, in bytes, of the frames theuartTxTasktask transmits.use
delayto specify the duration, in ms, for theuartTxTasktask to wait between two successive frames.use
txto specify the number of frames to transmit, and trigger theuartTxTasktask to start transmitting.
The uart_app.py Python script connects to the API port of your
. It defines a number of commands allowing you to transmit UART frames to the
. It also prints the UART frames it receives. Start the uart_app.py Python script by double-clicking on its file.
Before you run this application, make sure you have Python and pyserial installed on your computer.
Refer to the SmartMesh IP Tools Guide for installation instructions.
The uart_app.py Python script defines the same CLI commands are the 02-uart sample application, i.e. len, delay and tx. On top of those, the uart_app.py Python script defines the connect command to connect it to the API serial port of your
.
You can type help on both the 02-uart sample application and the uart_app.py Python script to obtain the list of available commands.
Type help on the your
:
> uart app, ver 1.0.0.2
SmartMeshIP stack, ver 1.2.1.5
> help
help <command>
Commands:
mtrace
mset
mget
minfo
mlog
mfs
mseti
mgeti
mshow
mxtal
mhwlog
len
delay
tx
>Type help in the uart_app.py Python script:
uart_app OCFDK Sample application
> help
Commands:
connect <comPort>
len <numBytes>
delay <numMs>
tx <numPackets>
exit
>Send UART frames from the
First, connect the uart_app.py Python script to the API port of your
(here on COM28).
> connect COM28
>On the
, type the following command to send 5 HDLC frames, of 10 bytes each, with an inter-frame delay of 100ms to the uart_app.py Python script:
> len 10
> delay 100
> tx 5
> Sending 5 UART packets, 10 bytes, delay 100 ms
done.The following is printed by the uart_app.py Python script:
uart RX (10 bytes) 0a 0a 0a 0a 0a 0a 0a 0a 0a 0a
uart RX (10 bytes) 0a 0a 0a 0a 0a 0a 0a 0a 0a 0a
uart RX (10 bytes) 0a 0a 0a 0a 0a 0a 0a 0a 0a 0a
uart RX (10 bytes) 0a 0a 0a 0a 0a 0a 0a 0a 0a 0a
uart RX (10 bytes) 0a 0a 0a 0a 0a 0a 0a 0a 0a 0aReceive UART frames at the
On the uart_app.py Python script, type the following command to send 5 HDLC frames, of 10 bytes each, with an inter-frame delay of 100ms to the
: