« Close

Datasheets and User Guides

Software & Driver

 

13.7 Asynchronous Serial [T-Series Datasheet]

Overview

The T-Series devices have universal asynchronous receiver-transmitter (UART) functionality available that supports 3.3V logic level (CMOS/TTL) asynchronous (asynch) serial communication. The TX (transmit) and RX (receive) lines can appear on any digital I/O.  Baud rates up to 38400 are supported, but the device's processor is heavily loaded at that rate.  The number of data bits, number of stop bits, and parity are all controllable.

Asynchronous (UART) vs. RS-232:

The T4/T7's asynchronous support and the RS-232 standard are the same in terms of timing and protocol, but different in terms of electrical specifications.  Connection to an RS-232 device will require a converter chip such as the MAX233, which inverts the logic and shifts the voltage levels.  On the T4/T7, a low is 0 volts (inputs recognize 0.0 to 0.5) and a high (1) is 3.3 volts (inputs recognize 2.64 to 5.8 volts).  With RS-232, a low (0) is 3 to 25 volts and a high (1) is -3 to -25 volts; RS-232 has unique voltage levels and is inverted.

Lua Scripting:

Lua scripting is often convenient for serial applications.  For example, you might write a script that does the serial communication to get a new reading from the serial device once per second, and puts that reading in a USER_RAM register.  This puts the complications of serial communication in a script running on the T4/T7 itself, and then the host software can just do a simple read of the USER_RAM register when convenient.  We have many serial examples available for Lua scripting.

A direct connection to a serial device is preferable:

This serial link is not an alternative to the USB/Ethernet/WiFi connection. Rather, the host application will write/read data to/from the T4/T7 over USB/Ethernet/WiFi, and the T4/T7 communicates with some other device using the serial protocol. Using this serial protocol is considered an advanced topic. A good knowledge of the protocol is recommended, and a logic analyzer or oscilloscope might be needed for troubleshooting.

If it is practical to run a cable directly from the host computer to the serial device, that is usually a better than putting the T4/T7 in between.  Use a standard USB<=>RS-232 adapter/converter/dongle (or RS-485 or RS-422).

Multiple asynchronous ports on a single LabJack:

The asynchronous feature can only be enabled on one pair of pins at a time, and to be more specific only one RX pin can read data at a time.  When the asynchronous feature is enabled on a pair of pins, a buffer is set up and the RX pin reads any data that comes in and stores it in the buffer.  This is useful for devices that spontaneously send out data where all that data is wanted all the time.  Most serial devices, however, act in a command-response manner where the LabJack sends a command that requests a reading and the device responds with the reading.  For these it is easy to do multiple ... just re-do the configuration writes whenever communication is desired on different pins.

How-To

  1. Initial Configuration
  2. Transmit Data
  3. Receive Data
  4. Debugging data parity errors (if enabled)

1. Initial Configuration

Several registers need to be written to in order to configure the T-Series device for Asynch communication.

  • TX/RX data lines (ASYNCH_TX_DIONUM, ASYNCH_RX_DIONUM)
  • Baud rate configuration (ASYNCH_BAUD)
  • Configure RX buffer size (ASYNCH_RX_BUFFER_SIZE_BYTES)
  • Configure number of bits, number of stop bits, and the parity. (ASYNCH_NUM_DATA_BITS,​​​​ ASYNCH_NUM_STOP_BITS, ASYNCH_PARITY)

After configuring the various registers, the ASYNCH feature should be enabled by writing a 1 to (ASYNCH_ENABLE).

Asynchronous Serial Configuration Registers
Name Start Address Type Access

ASYNCH_TX_DIONUM             The DIO line that will transmit data. (TX)

5410 UINT16 R/W

ASYNCH_RX_DIONUM             The DIO line that will receive data. (RX)

5405 UINT16 R/W

ASYNCH_BAUD             The symbol rate that will be used for communication. 9600 is typical. Up to 38400 works, but heavily loads the T7's processor.

5420 UINT32 R/W

ASYNCH_RX_BUFFER_SIZE_BYTES             Number of bytes to use for the receiving buffer. Max is 2048. 0 = 200

5430 UINT16 R/W

ASYNCH_NUM_DATA_BITS             The number of data bits per frame. 0-8, 0=8.

5415 UINT16 R/W

ASYNCH_NUM_STOP_BITS             The number of stop bits. Values: 1 = one stop bit, 2 = two stop bits, 0 = one stop bit.

5455 UINT16 R/W

ASYNCH_PARITY             Parity setting: 0=none, 1=odd, 2=even.

5460 UINT16 R/W

ASYNCH_ENABLE             1 = Turn on Asynch. Configures timing hardware, DIO lines and allocates the receiving buffer.

5400 UINT16 R/W

2. Transmit Data

In order to transmit data a user must do the following:

  1. Configure the number of bytes that needs to be sent (ASYNCH_NUM_BYTES_TX)
  2. Send data to the T-Series device using  the LJM_eWriteNameByteArray function (ASYNCH_DATA_TX)
  3. Write a 1 to the "GO" register (ASYNCH_TX_GO)
    note: The process of writing a 1 to the GO register instructs the T-Series device to transmit the buffered data via the TX line.

Asynchronous Serial Data Transmission Registers
Name Start Address Type Access

ASYNCH_NUM_BYTES_TX             The number of bytes to be transmitted after writing to GO. Max is 256.

5440 UINT16 R/W

ASYNCH_DATA_TX             Write data to be transmitted here. This register is a buffer.

5490 UINT16 W

ASYNCH_TX_GO             Write a 1 to this register to initiate a transmission.

5450 UINT16 W

3. Receive Data

T-Series devices buffer received Asynch data up to the size defined in the configuration step when writing to the register "ASYNCH_RX_BUFFER_SIZE_BYTES".  The usual method for reading data from the buffer is to do the following:

  1. Read how many bytes of information have been received by the device (ASYNCH_NUM_BYTES_RX)
  2. Read data from the T-Series device RX buffer using the LJM_eReadNameByteArray function (ASYNCH_DATA_RX)
    note: When ever possible, it is recommended to read an even number of bytes from the DATA_RX buffer.

Asynchronous Serial Data Receiving Registers
Name Start Address Type Access

ASYNCH_NUM_BYTES_RX             The number of data bytes that have been received.

5435 UINT16 R

ASYNCH_DATA_RX             Read received data from here. This register is a buffer. Underrun behavior - fill with zeros.

5495 UINT16 R

4. Debugging Data Parity Errors

Asynchronous Serial Data Parity Register
Name Start Address Type Access

ASYNCH_NUM_PARITY_ERRORS             The number of parity errors that have been detected. Cleared when UART is enabled. Can also be cleared by writing 0.

5465 UINT16 R/W

Examples

For performing asynchronous communication from a computer, see the LJM C examples or the LJM LabView examples.

For performing asynchronous communication on device, see the Lua scripting examples.