UART Mode

Top  Previous  Next

In the UART mode the serial port has standard UART functionality. You can select the baudrate, parity, number of bits in each character, and full- or half-duplex operation (see Serial Settings). The UART works with signals of "TTL-serial" polarity — RX and TX lines are at logical HIGH when no data transmission is taking place, the start bit is LOW, stop bit is HIGH (shown below for the case of 8 bits/character and enabled parity).

 

tide_uart_data

UART data is sent and received via TX output and RX input lines. Two additional lines- RTS output and CTS input may also be used depending on the serial port setup (see below).

 

note_warning-wt

Please, remember that depending on the platform you may be required to configure some or all of your serial port's lines as inputs or outputs through the io.enabled property of the io object. Additionally, you may have the freedom of re-mapping certain serial port lines to different I/O pins of the device if required. For more information, refer to your device's platform documentation (for example, EM1000's is here).

How the serial port sends and receives UART data

The serial port can send and receive the data with no parity, or even, odd, mark, or space parity configuration. Additionally, you can specify the number of bits in each character (7 or 8). The serial port takes care of parity calculation automatically. When parity bit is enabled, it will automatically calculate parity bit value for each character it transmits. When receiving, the serial port will correctly process incoming characters basing on the specified number of bits and parity mode. Actual parity check is not done. The serial port will receive the parity bit but won't actually check if it is correct.

 

note_warning-wt

Actual parity check is not done. The serial port will receive the parity bit but won't actually check if it is correct. Parity is mostly kept for compatibility with older devices, so the serial port transmits it correctly.

How the UART data is stored in the RX and TX buffers of the serial port

When in the UART mode, each data byte in the TX or RX buffer of the serial port represents one character. When the serial port is configured to send and receive 7-bit characters, the most significant bit of each byte in the RX buffer will be 0, and the most significant bit of each byte in the TX buffer will be ignored. Parity bits are not stored in the buffers. For the outgoing data stream, the serial port will calculate and append the parity bit automatically. For the incoming serial data, the serial port will discard the parity bit so the RX buffer will only get "pure" data.

Full-duplex operation

The full-duplex mode of operation is suitable for communicating with RS232, RS422 devices, 4-line RS485 devices, and most TTL-serial devices. Naturally, external transceiver IC is needed for RS232, RS4222, or RS485. TTL serial devices can be connected to the serial port lines directly in most cases.

In the full-duplex mode, the RTS output and CTS input lines can be used for optional flow control. The RTS output is low whenever the serial port is ready to receive the data from "attached" serial device (port is opened and the RX buffer has at least 64 bytes of free space). The RTS line is high whenever the serial port is closed or the RX buffer has less than 64 bytes of free space left. Figure below illustrates RTS operation.

 

note_further-wt

All diagrams show TTL-serial signals. If you are dealing with the lines of the RS232 port you will see all signals in reverse!

 

tide_ser_rts

 

The CTS input is used by the serial port to check if attached serial device is able to accept the data. The serial port will only start to send the data when the CTS input is low. The serial port will stop sending the data once the line goes high. Note, that some Tibbo devices have a hardware buffer called "FIFO" ("fist-in-first-out" if you really need to know ;-). Once the TX data is in the FIFO it will be sent out even if the CTS line goes low. Therefore, after the attached serial device switches the CTS line to low the serial port may still output the number of bytes not exceeding the capacity of the FIFO. For more information, refer to your device's platform documentation (for example, EM1000's is here).

 

tide_ser_cts

When the flow control is enabled, the RTS and CTS lines are controlled by the serial port and cannot be manipulated by your application. When the flow control is off, your application can set and read the state of these lines through the io object.

Half-duplex operation

The half-duplex mode of operation is suitable for communicating with 2-wire RS485 devices. Again, appropriate interface transceiver IC is required to be connected to the serial port.

In the half-duplex mode the RTS output is used to control data transmission direction. You can select the polarity of the direction control signal, i.e. which state will serve as "data in" direction, and which- as "data out" direction (see Serial Settings).

When the serial port has no data to transmit (the TX buffer is empty), it is always ready to receive the data, so the RTS line is in the "data in" state. When the serial port needs to send out some data (the TX buffer is not empty) it switches the RTS line into the "data out" state, transmits the data, then switches the RTS back into the "data in" state. Assuming "LOWFORINPUT" direction control polarity, direction control looks like this:

 

tide_ser_dircontrol

 

The CTS line is not controlled by the serial port when in the half-duplex mode. Your application can manipulate this line through the io object.