Ms14 uart

From Wiki for Dragino Project
Jump to: navigation, search

Different modes of UART

ms14 has a uart interface expose on the 2x8 router connector. this interface can be act as:

  • Console port to debug the openwrt system inside ms14. refer link here.

or

  • UART interface to communicate to other devices such as a avr daughter board.


to disable UART as a console port, user can comment the related line in file /etc/inittab. And reboot the device.

root@dragino2-684db6:/# vi /etc/inittab 
::sysinit:/etc/init.d/rcS S boot
::shutdown:/etc/init.d/rcS K shutdown
#ttyATH0::askfirst:/bin/ash --login                        // Comment this line to disable uart as console.

If your computer has serial port connect to ms14, you will still able to see output from serial when booting. but it will stop some while after boot.


Example 1: Debug UART transmit / receive feature in computer

A fast way to debug the UART interface is use your computer to simulate transaction between the ms14 and mcu. Here is simple test set up to do this test.

This test required:

  1. Your computer has a rs232/uart converter to connect to ms14 and have properly set up. Reference Link
  2. Know how to edit files in ms14. Reference Link
  3. Know how to use SSH to access ms14 and run command. Reference Link
Use computer to debug uart


Transmit strings to computer

Create a lua file uarttx.lua to transmit data

local nixio = require 'nixio'
 
function DataToUART(message)
	local	serialout=nixio.open("/dev/ttyATH0","w")      --open uart interface
	serialout:write(message)
	serialout:close()
end
 
msg = arg[1]      -- Get string from command line
DataToUART(msg)   --send string to uart tx

to run this script, in ms14, runs:

root@dragino2-684db6:~# lua uarttx.lua "This message is from ms14"

then you will be able to see the string in computer console panel

Computer get string from console terminal


Get strings from computer

Create a lua file uartrx.lua to receive data

while 1 do                          --loop to get data and process
serialin=io.open("/dev/ttyATH0","r")   --open serial port and prepare to read data from Arduino
	while line==nil do        -- read data from serial. 
         	line=serialin:read() 
         	serialin:flush()
	end
	print(line)    --print the data
 
	--------------------------------------
	--put your code here to process data--
	--------------------------------------
 
	serialin:close()
	line=nil    --clear the line data
end

to run this script, in ms14, runs:

root@dragino2-684db6:~# lua uartrx.lua

Then once you type message in computer console panel followed by "ENTER". the message will be show in ms14 console.

Use minicom

root@dragino2-684db6:/# opkg update
Downloading http://downloads.openwrt.org/snapshots/trunk/ar71xx/packages/Packages.gz.
Inflating http://downloads.openwrt.org/snapshots/trunk/ar71xx/packages/Packages.gz.
Updated list of available packages in /var/opkg-lists/snapshots.
root@dragino2-684db6:/# opkg install minicom
Installing minicom (2.3-1) to root...
Downloading http://downloads.openwrt.org/snapshots/trunk/ar71xx/packages/minicom_2.3-1_ar71xx.ipk.
Configuring minicom.
root@dragino2-684db6:/# minicom -s                           //   use minicom -s to configure serial port 
   A -    Serial Device      : /dev/ttyATH0                              |       // use ttyATH0 as serial port
   | B - Lockfile Location     : /var/lock                                 |
   | C -   Callin Program      :                                           |
   | D -  Callout Program      :                                           |
   | E -    Bps/Par/Bits       : 115200 8N1                                |
   | F - Hardware Flow Control : No                                        |
   | G - Software Flow Control : No                                        |
   |                                                                       |
   |    Change which setting?