eLua reference manual - UART module

Overview

This module contains functions for accessing the serial ports (UARTs) of the eLua CPU.

Data structures, constants and types

uart.VUART0
uart.VUART1
.............
uart.VUART7

If virtual UART support is enabled in eLua these constants are automatically defined to the IDs of the virtual UARTs in the system.

Functions

baud = uart.setup( id, baud, databits, parity, stopbits )

Setup the serial port. Note that you can't call this function for a virtual UART.

Arguments:

  • id - the ID of the serial port
  • baud - serial baud rate
  • databits - number of data bits
  • parity - parity type, can be either uart.PAR_EVEN, uart.PAR_ODD or uart.PAR_NONE
  • stopbits - the number of stop bits, can be either uart.STOP_1 (for 1 stop bit), uart.STOP_1_5 (for 1.5 stop bits) or uart.STOP_2 (for 2 stop bits)

Returns: The actual baud rate set on the serial port. Depending on the hardware, this might have a different value than the baud parameter

uart.write( id, data1, [data2], ..., [datan] )

Write one or more strings or 8-bit integers (raw data) to the serial port. If writing raw data, its value (represented by an integer) must be between 0 and 255.

Arguments:

  • id - the ID of the serial port.
  • data1 - the first string/8-bit integer to write.
  • data2 (optional) - the second string/8-bit integer to write.
  • datan (optional) - the n-th string/8-bit integer to write.

Returns: nothing.

uart.set_buffer( id, bufsize )

Sets the size of the UART buffer. Note that calling this function with bufsize = 0 for a virtual UART is not allowed.

Arguments:

  • id - the ID of the serial port
  • bufsize - the size of the buffer (must be a power of 2) or 0 to disable buffering on the specified UART.

Returns: nothing.

uart.set_flow_control( id, type )

Sets the flow control on the UART. Note that this function works only on physical ports, it will return an error if called on a virtual UART.

Arguments:

  • id - the ID of the serial port.
  • type - the flow control type, it can be either uart.FLOW_NONE (no flow control), uart.FLOW_RTS for RTS flow control, uart.FLOW_CTS for CTS flow control or uart.FLOW_RTS + uart.FLOW_CTS for full RTS/CTS flow control.

Returns: nothing.