Documentation

RS-232/RS-422/RS-485 Send/Receive (Composite)

RS-232/RS-422/RS-485 Send/Receive block

Library

Simulink® Real-Time™ Library for RS-232

Description

The dynamic dialog for these subsystem blocks allows you to perform basic board setup and setup of send/receive data. You control parameter visibility with the Parameter Group parameter and the port number.

There are two versions of this block, non-F and F (FIFO). Both serial boards and the main board have these two versions. The primary difference is that the F blocks bring the FIFO signal out of the subsystem:

  • The non-F blocks have RCV outputs. These blocks have basic FIFO read blocks inside the subsystem. They are most useful for simple character streams. These subsystem blocks generate output as an array of packed integers (settable at 8, 16, or 32 bits) with characters in the lower byte and received status information in the upper byte.

  • The F blocks have FIFO outputs. These blocks give you greater flexibility and allow you to use the FIFO read blocks.

    • FIFO Read block — A model that contains an F block in combination with the FIFO Read block provides the same capability as the non-F block.

    • FIFO Read HDRS and FIFO Read Binary — A model that contains an F block in combination with a FIFO Read HDRS or FIFO Read Binary block provides greater capability than the FIFO Read block. See FIFO Read HDRS (Composite) and FIFO Read Binary (Composite).

Only one Send/Receive block can exist for each interrupt. All ports that use that interrupt must be associated with that block.

For example, if you have four ports configured on the main board, COM1 and COM3 typically share an interrupt. In this case, COM1 and COM3 must then share the same Send/Receive block. COM1 is also of note because you can use it for linking the development and target computers. If COM1 is used for the serial link, neither COM1 nor COM3 can be used with this block as long as they share an interrupt. The same is true for COM2 and COM4.

The Board Setup and Basic Setup configuration parameter options for F-Send-Receive blocks are the same as for their non-F Send Receive block counterparts. To provide direct access to the board, these blocks also have a FIFO Setup parameter option. The following descriptions merge the common elements and call out the differences among the different blocks.

Block Parameters

Parameter Group

This parameter allows you to choose which subset of configuration parameters you want to modify. Possible values are:

  • Board Setup

  • Basic Setup

  • Transmit Setup

  • Receive Setup

  • FIFO Setup

The configuration parameter subsets are:

Board Setup

The Parameter Group Board Setup option is supported by both F and non-F Send Receive blocks.

Configuration (Mainboard)

From the list, choose combinations of port pairs (Com1/none, Com2/none, Com1/Com3, Com2/Com4, none/Com3, none/Com4, or Custom). This parameter specifies the ports for which you are defining transmit and receive. A Custom port is one that does not match the existing combinations of port pairs. For example, you can set the IRQ and two addresses or, if one of the ports is not used, set that to 0.

IRQ number (Quatech®, Commtech)

Enter the number of the interrupt request line for this board. If you do not know the interrupt request line number for this board, at the MATLAB® Command Window, enter:

tg = slrt;
getPCIInfo(tg, 'installed')

This command displays the PCI interfaces currently attached to the target computer. From that display, find the instance of the board controlled by this block. Each board uses a unique interrupt request line number.

For Emerald-MM, set this to the IRQ chosen by jumpers on the board. Set the four ports to the same IRQ.

For Emerald-MM-8, this block setting programs the board IRQ.

(Diamond) Not all IRQ values work in all target computer machines. You should experiment to find a working combination.

Clock Bits (Commtech)

Enter the number of click bits to control a clock generator common to both channels. This parameter adjusts the master clock of both channels. Calculate this parameter using the function fc422mexcalcbits.

Master Clock Frequency (Commtech Fastcom® 422/2-PCI-335, 422/4-PCI-335)

Enter the clock generator frequency for the master clock. Enter a value between 6 MHz and 50 MHz, inclusive.

Use standard reference and rates (Commtech Fastcom 422/2-PCI-335, 422/4-PCI-335)

This check box enables you to use default values for the block. Select this check box to use the default values for the Master Clock Frequency parameter. If you clear this check box, you can enter a custom value for the Master Clock Frequency parameter. This same check box also appears on the Basic Setup option page for all ports. Selecting this box applies to all channels.

Slot (PCI boards)

If only one board of this type is in the target computer, enter -1 to automatically locate the board.

If two or more boards of this type are in the target computer, enter the bus number and the PCI slot number of the board associated with this driver block. Use the format [BusNumber, SlotNumber]. To determine the bus number and the PCI slot number, type:

tg = slrt;
getPCIInfo(tg, 'installed')
Base address (Diamond Emerald-MM-8)

Enter the base address of the board that you are setting up. This is the address of the configuration register on the board. The first port address referenced in Modem Control and Modem Status blocks is offset 0x10 from the configuration register address, and each subsequent port address is offset 0x8 from that.

You must set the configuration register address on the board with a jumper. You can set the configuration register address to one of the following addresses: 0x100, 0x140, 0x180, 0x1c0, 0x200, 0x240, 0x280, 0x2c0, 0x300, 0x340, 0x380, or 0x3c0. Note that the Simulink Real-Time software assigns successive 8 byte addresses to the eight UARTs even though the I/O module allows random placement.

Be sure that these addresses do not conflict with the COM port addresses listed in Adding RS-232 Blocks. If you set the configuration register address to 0x2c0, it conflicts with COM2. If you set the configuration address to 0x3c0, it conflicts with COM1.

First port address (Diamond Emerald-MM)

From the list, select the first port address for the board. This address is the first of four port addresses for the Emerald-MM board. You must initially set this address on the board with a jumper. The remaining three addresses follow consecutively in increments of 0x8. Be sure that these addresses do not conflict with the COM port addresses listed in Adding RS-232 Blocks.

Basic Setup

The Parameter Group Basic Setup option is supported by both F and non-F Send Receive blocks.

Port to modify

From the list, choose a port. The Port to modify parameter specifies the port for which you want to view or modify the parameters.

For Baseboard drivers, the port is the Simulink block port, where the upper port is 1 and the lower port is 2. For other drivers, the port number corresponds to the channel number.

Use standard reference and rates (Commtech Fastcom 422/2-PCI-335, 422/4-PCI-335)

This check box enables you to use default values for the block. Select this check box to use the default values for the Baud divisor and Sampling rate parameters. Selecting this check box allows you to enter a value for the Baud rate parameter and also selects the Prescale parameter. If you clear this check box, you can enter custom values for the Baud divisor and Sampling rate parameters, but must use the default value for the Baud rate parameter. Clearing this check box also clears the Prescale check box.

If selected:

  • Reference is set to 14.7456 MHz.

  • Prescale is disabled.

  • Sampling rate is 16X (standard).

  • Select the baud rate from Baud Rate.

If not selected, you must provide a custom baud rate that is not on the drop-down list to get the desired reference. For example, if you have a desired baud rate of 1.0 MHz, you can use the following equation to calculate the reference:

reference = baud rate x sampling rate x divisor x prescale

The following values give an acceptable reference that is less than or equal to 50 MHz.

reference = 1.10e6 x 16 x 1 x 1 = 16 MHz
Baud Divisor (Commtech)

Enter a divisor integer. The block determines the actual baud rate for a particular channel by dividing the maximum baud rate by this divisor. This number can be different for each channel.

Baud rate (Mainboard, Quatech, Diamond, (Commtech Fastcom 422/2-PCI-335, 422/4-PCI-335)

From the list, choose a baud rate.

(Diamond Emerald-MM) The Emerald-MM block lists the baud rates with an HS label to indicate the rate if the board contains the high speed crystal option.

Sampling rate (Commtech Fastcom 422/2-PCI-335, 422/4-PCI-335)

From the list, select 8x or 16x (standard) per port. This parameter is enabled if you clear the Use standard reference and rates parameter.

Prescale (Commtech Fastcom 422/2-PCI-335, 422/4-PCI-335)

For very slow baud rates, you might need to enable this divide by 4 prescaler to achieve the desired rate. In most cases, you do not need to enable this.

Parity

From the list, choose None, Even, Odd, Mark, or Space. This parameter defines the parity.

Data bits

From the list, choose either 5, 6, 7, or 8 to select the number of bits per character.

Stop bits

From the list, choose either 1 or 2 to define the number of stop bits for the port. Most modern RS-232 boards work fine with a character stream that uses single (1) stop bits.

Hardware FIFO size (Quatech, Diamond)

From the list, choose either 64 deep, 16 deep, or 1 deep. This parameter specifies the size of the FIFO in the UART. The Hardware FIFO size parameter affects both the receive and transmit FIFOs. For example, specifying a FIFO size of 64 bytes results in fewer interrupts. Fewer interrupts can allow more processing to occur in the model.

The types of UARTs include

16450 — Maximum 1 byte depth

16550 — Maximum 16 byte FIFO depth

16750 — Maximum 64 byte FIFO depth

Receive FIFO interrupt level

From the list, choose 1, quarter full, half full, or almost full. This parameter specifies the number of characters in the Receive FIFO before an interrupt occurs. Receive interrupts occur at least as often as this parameter specifies.

If a gap of at least 4 character times, the span of four characters, occurs in a data stream, the UART requests an interrupt for the receiver. The UART requests an interrupt regardless of the value of Receive FIFO interrupt level. If the FIFO on the board contains at least one character, an interrupt is signaled.

(Commtech) The Fastcom 422/2–PCI and Fastcom 422/2–PCI F blocks do not have this parameter as a drop-down list. Instead, these blocks allow you to enter an arbitrary number of bytes up to the FIFO size, with 64 as the default. Typically, 8 to 16 bytes is large enough, but the size you choose depends on the speed of the incoming characters. Be careful that you do not enter a size that causes too many interrupts.

Auto RTS/CTS (RS-232 boards)

Select this check box to enable the RTS/CTS handshake for flow control. This RTS/CTS handshake feature of the UART is used to prevent data loss due to FIFO overflow on the board.

Because of the large 64 byte FIFO in the I/O module, flow control that is based on software control in the interrupt service routine can have problems. In most cases, the interrupt service routine executes quickly enough to empty the FIFO. However, if you get FIFO overruns, select this check box.

Assert on transmit (RS-422/485 boards)

From the list, select None, RTS, or DTR to specify the state of the RTS or DTR line. The driver asserts the selected line upon transmission.

Hardware handshake (Commtech Fastcom 422/2-PCI-335, 422/4-PCI-335)

Enable the RTS/CTS handshake for flow control. This feature of the UART is used to prevent loss due to FIFO overflow. From the list, select RTS/CTS to enable this behavior; otherwise, select none.

Software handshake (Commtech Fastcom 422/2-PCI-335, 422/4-PCI-335)

Allows the UART to send the XOFF character if the receive FIFO gets too full. It then sends the XON character when the receive FIFO empties. Because the UART handles this, the XON/XOFF characters are sent immediately, even if the transmitter is empty. From the list, select XON/XOFF to enable this behavior; otherwise, select none.

XON character (Commtech Fastcom 422/2-PCI-335, 422/4-PCI-335)

Normally, enter 17 (Control Q). This is the default.

XOFF character (Commtech Fastcom 422/2-PCI-335, 422/4-PCI-335)

Normally, enter 19 (Control S). This is the default.

RS485 auto turnaround (Commtech Fastcom 422/2-PCI-335, 422/4-PCI-335)

Select this check box to enable RS-485 automatic turnaround. In RS-485 mode, where the transmitters and receivers use the same differential pair of wires, you can enable only one transmitter at a time. Select this check box to turn on the automatic transmitter control in the UART. The RTS output is routed to the enable input of the RS-485 transmitter.

RS485 turnaround delay (Commtech Fastcom 422/2-PCI-335, 422/4-PCI-335)

Enter the desired RS-485 turnaround delay. The UART automatically asserts RTS when there are characters in the transmit FIFO. It de-asserts RTS when the transmit FIFO empties and the RS-485 turnaround default delay of 0 to 15 bit times elapses. The transmitter output goes tristate (high impedance) when disabled, which allows another device to transmit.

Transmit Setup

The Parameter Group Transmit Setup option is supported by only non-F Send Receive blocks.

Port to modify

From the list, choose a port. The Port to modify parameter specifies the port for which you want to view or modify the parameters.

Use standard reference and rates (Commtech Fastcom 422/2-PCI-335, 422/4-PCI-335)

This check box enables you to use default values for the block.

Transmit software FIFO size

Enter the transmit software FIFO size, in bytes. This parameter specifies the size of the software FIFO used to buffer transmitted characters.

Transmit FIFO data type

From the list, choose count+32 bit int, count+32 bit uint, count+16 bit int, count+16 bit uint, 8 bit int null terminated, or 8 bit uint null terminated. This parameter specifies the data type of the transmitter. The 8-bit data types require a NULL-terminated string in the input vector.

The 16- and 32-bit data types reserve the first full element to contain the number of elements to expect in the rest of the input vector. Only the low-order byte of each data element is sent. Setting this data type allows a wider data type to hold the bytes.

If the data stream needs to include a NULL byte, you must select one of the 16- or 32-bit data types. Because the 8-bit data types are NULL terminated strings, the NULL byte would terminate the string.

Receive Setup

The Parameter Group Receive Setup option is supported by only non-F Send Receive blocks.

Port to modify

From the list, choose a port. The Port to modify parameter specifies the port for which you want to view or modify the parameters.

Use standard reference and rates (Commtech Fastcom 422/2-PCI-335, 422/4-PCI-335)

This check box enables you to use default values for the block. Select this check box to use the default values for the Baud divisor and Sampling rate parameters. Selecting this check box allows you to enter a value for the Baud rate parameter and also selects the Prescale parameter. If you clear this check box, you can enter custom values for the Baud divisor and Sampling rate parameters, but must use the default value for the Baud rate parameter. Clearing this check box also clears the Prescale check box.

If selected:

  • Reference is set to 14.7456 MHz.

  • Prescale is disabled.

  • Sampling rate is 16X (standard).

  • Select the baud rate from Baud Rate.

If not selected, you must provide a custom baud rate that is not on the drop-down list to get the desired reference. For example, if you have a desired baud rate of 1.0 MHz, you can use the following equation to calculate the reference:

reference = baud rate x sampling rate x divisor x prescale

The following values give an acceptable reference that is less than or equal to 50 MHz.

reference = 1.10e6 x 16 x 1 x 1 = 16 MHz
Receive software FIFO size

Enter the size of the receive software FIFO, in bytes. This parameter specifies the size of the software FIFO to buffer characters between interrupt service and periodic execution.

Receive maximum read

Enter the maximum number of elements that you want returned by a single call to this block. This parameter is also used to set the output vector width. If the Read to delimiter check box is selected, the maximum number of characters read is limited by this parameter even if the delimiter is not found.

Receive minimum read

Enter the minimum number of characters to read. If the FIFO does not contain at least this number of characters, the output vector is empty.

Read to delimiter

Select this check box to have this block return all characters in the FIFO, up to and including the specified delimiter. If the block does not find the delimiter in the FIFO, it returns nothing.

If the buffer has errors, such as framing errors, characters are returned regardless of the presence of the delimiter. This special case helps diagnose errors such as mismatched baud rates.

Delimiter

Enter the numeric value of the character that is the message delimiter. Any value from 0 to 255 is valid. The common case looks for 10 (line feed) or 13 (carriage return).

Receive data type

From the list, select count+32 bit int, count+32 bit uint, count+16 bit int, count+16 bit uint, 8 bit int null terminated, or 8 bit uint null terminated. This parameter specifies the data type of the receiver. The 8-bit data types produce a null terminated string in the output vector. For 16- and 32-bit data types, the first element contains the number of valid elements in the rest of the output vector.

For 8-bit data types, only the character data is in the output vector, and a NULL terminator is appended. The 16- or 32-bit wide data types cause the error status from the UART to be placed in the second byte of each data element. (The error status contains the parity, overrun, framing, and break bits.) The character data is in the bottom eight bits of each element; the first element of the vector contains the number of data elements that follow.

Receive SampleTime

Base sample time or a multiple of the base sample time.

FIFO Setup

The Parameter Group FIFO Setup option is supported by only F Send Receive blocks.

Port to modify

From the list, choose port 1 or 2. The Port to modify parameter specifies the port for which you want to view or modify the parameters.

Transmit software FIFO size

Enter the transmit software FIFO size, in bytes. This parameter specifies the size of the software FIFO used to buffer transmitted characters.

Transmit FIFO data type

From the list, choose count+32 bit int, count+32 bit uint, count+16 bit int, count+16 bit uint, 8 bit int null terminated, or 8 bit uint null terminated. This parameter specifies the data type of the transmitter. The 8-bit data types require a NULL-terminated string in the input vector.

The 16- and 32-bit data types reserve the first full element to contain the number of elements to expect in the rest of the input vector. Only the low-order byte of each data element is sent. Setting this data type allows a wider data type to hold the bytes. If the data stream needs to include a NULL byte, you must select one of the 16- or 32-bit data types.

Receive software FIFO size

Enter the size of the receive software FIFO, in bytes. This parameter specifies the size of the software FIFO to buffer characters between interrupt service and periodic execution.

Was this topic helpful?