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
LTC5800
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
SmartMesh mote
are connected over a USB cable. - Your
SmartMesh mote
is programmed with the02_uart
sample application. - Your computer runs the following:
- The
uart_app.py
Python script (available in theonchipsdk/
src/
/app/02-uart/
directory). - A terminal client to enter CLI commands for the
SmartMesh mote
.
- The
You need to know the API and CLI serial ports corresponding to your
SmartMesh mote
. You will connect theuart_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
uartTxTask
task transmits a number of UART frames from yourSmartMesh mote
to theuart_app.py
Python script. The number of frames to send, their length, and the inter-frame delay are set using CLI commands. - the
uartRxTask
task listens for incoming UART frames, sent in this case by the theuart_app.py
Python script.
02-uart
sample application defines 3 CLI commands:- use
len
to specify the length, in bytes, of the frames theuartTxTask
task transmits. - use
delay
to specify the duration, in ms, for theuartTxTask
task to wait between two successive frames. - use
tx
to specify the number of frames to transmit, and trigger theuartTxTask
task to start transmitting.
uart_app.py
Python script connects to the API port of your SmartMesh mote
. It defines a number of commands allowing you to transmit UART frames to theSmartMesh mote
. It also prints the UART frames it receives. Start theuart_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.
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 SmartMesh mote
.help
on both the 02-uart
sample application and the uart_app.py
Python script to obtain the list of available commands.help
on the your SmartMesh mote
:
> 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
SmartMesh mote
First, connect the uart_app.py
Python script to the API port of your
SmartMesh mote
(here onCOM28
).> connect COM28 >
On the
SmartMesh mote
, type the following command to send 5 HDLC frames, of 10 bytes each, with an inter-frame delay of 100ms to theuart_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 0a
Receive UART frames at the
SmartMesh mote
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
SmartMesh mote
:> len 10 > delay 100 > tx 5 Sending 5 UART packets, 10 bytes, delay 100 ms done. >
The following is printed at the
SmartMesh mote
: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 0a