Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Info

This section refers to the following sample application(s):

  • 02-uart

Table of Contents

 


The UART serial port can be used by a computer or external microcontroller to communicate with your application. The 

Include Page
_def_chip_eterna
_def_chip_eterna
 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:

...

Tip

You need to know the API and CLI serial ports corresponding to your

Include Page
_def_mote
_def_mote
. 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.

...

  • use len to specify the length, in bytes, of the frames the uartTxTask task transmits.
  • use delay to specify the duration, in ms, for the uartTxTask task to wait between two successive frames.
  • use tx to specify the number of frames to transmit, and trigger the uartTxTask task to start transmitting.
The uart_app.py Python script connects to the API port of your 
Include Page
_def_mote
_def_mote
. It defines a number of commands allowing you to transmit UART frames to the 
Include Page
_def_mote
_def_mote
. It also prints the UART frames it receives. Start the uart_app.py Python script by double-clicking on its file.
 


Note

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. lendelay 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 
Include Page
_def_mote
_def_mote
.
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 
Include Page
_def_mote
_def_mote
: 


No Format
> 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:

No Format
uart_app OCFDK Sample application
> help
Commands:
   connect <comPort>
   len <numBytes>
   delay <numMs>
   tx <numPackets>
   exit
>

Send UART frames from the 
Include Page
_def_mote
_def_mote

First, connect the uart_app.py Python script to the API port of your 

Include Page
_def_mote
_def_mote
 (here on COM28).

No Format
> connect COM28
>

On the 

Include Page
_def_mote
_def_mote
, 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:

No Format
> 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:

No Format
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 
Include Page
_def_mote
_def_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 

Include Page
_def_mote
_def_mote
:

No Format
> len 10
> delay 100
> tx 5
Sending 5 UART packets, 10 bytes, delay 100 ms
done.
>

The following is printed at the 

Include Page
_def_mote
_def_mote
:

No Format
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