RS-232 Send/Receive

Send and receive data over Mainboard Baseboard serial port

  • Library:
  • Simulink Real-Time / RS232 / Mainboard

Description

The Send/Receive block sets up the serial interface to send and receive basic character streams. This block has basic FIFO Read blocks inside the subsystem. It generates output as an array of packed integers (settable at 8 bits, 16 bits, or 32 bits). Characters appear in the lower byte and received status information appears in the upper byte.

Only one Send/Receive can exist for each COM interrupt. All ports that use that interrupt must be associated with that block. For example, if the main board is configured with four ports, COM1 and COM3 typically share an interrupt. In this case, COM1 and COM3 must then share a Send/Receive block.

Ports

Input

expand all

Vector of data to transmit over port 1.

Vector of data to transmit over port 2.

Output

expand all

Vector containing data that has been received from serial port 1.

Vector containing data that has been received from serial port 2.

Parameters

expand all

To configure a group of parameters, select a group.

Programmatic Use

Block Parameter: group

Board Setup

This parameter specifies the ports for which you are defining transmit and receive. For example, Com1/Com3 specifies that port 1 uses COM1 and port 2 uses COM3. On the Simulink® block, the upper port is port 1 and the lower port is port 2.

A Custom configuration is one that does not match the existing combinations of port pairs. For example, assume that your target computer BIOS disables port 1 and reconfigures port 2 to use base address 0x220, IRQ 11. Then you can make the following settings:

  • ConfigurationCustom

  • IRQ number11

  • First port address0

  • Second port address0x220

In this case, port 1 is unused.

The value Custom makes the IRQ number, First port address, and Second port address parameters visible.

Programmatic Use

Block Parameter: config

Use this IRQ to specify a Custom serial port configuration.

The value Custom causes the IRQ number parameter to become visible.

Programmatic Use

Block Parameter: irqnum

Use this base address to specify a Custom serial port configuration.

The value Custom causes the First base address parameter to become visible.

Programmatic Use

Block Parameter: saddr1

Use this base address to specify a Custom serial port configuration.

The value Custom causes the Second base address parameter to become visible.

Programmatic Use

Block Parameter: saddr2

Basic Setup

This parameter specifies the port for which you want to view or modify parameters. On the Simulink block, the upper port is port 1 and the lower port is port 2.

Programmatic Use

Block Parameter: port

Select a baud for transmitting and receiving data through the modem.

Programmatic Use

Block Parameter: baud1,baud2

Select a parity for checking data integrity.

Programmatic Use

Block Parameter: parity1,parity2

Select the number of bits that encode a character.

Programmatic Use

Block Parameter: ndata1,ndata2

Select the number of stop bits for the character stream.

Programmatic Use

Block Parameter: nstop1,nstop2

Depth of hardware FIFO, in characters. The capability of the UART limits the depth of the FIFO.

Programmatic Use

Block Parameter: fifomode1,fifomode2

This parameter specifies the number of characters in the receive hardware FIFO before an interrupt occurs.

Receive interrupts occur at least as often as this parameter specifies. Each interrupt calls the interrupt service routine, causing overhead. Interrupt level 1 produces much higher overhead than the other settings. Consider interrupt level 1 only for applications that have low latency.

If both of the following are true, the UART requests an interrupt for the receiver regardless of the value of Receive FIFO interrupt level:

  • The FIFO contains at least 1 character.

  • A gap of at least 4 character times (the time required to transfer four characters) occurs in a data stream.

Programmatic Use

Block Parameter: rlevel1,rlevel2

To enable the RTS/CTS handshake of the UART for flow control, select this check box. Serial controllers use the RTS/CTS handshake to prevent data loss due to hardware FIFO overflow on the device that you are sending to.

Usually, the interrupt service routine executes quickly enough to empty the FIFO. However, if your model gets FIFO overruns, select this check box.

Programmatic Use

Block Parameter: automode1,automode2

Transmit Setup

This parameter specifies the port for which you want to view or modify parameters. On the Simulink block, the upper port is port 1 and the lower port is port 2.

Programmatic Use

Block Parameter: port

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

Programmatic Use

Block Parameter: xmtfifosize1,xmtfifosize2

This parameter specifies the data type of the transmitter. The 8-bit data types require a NULL-terminated character vector in the input vector.

The 16-bit 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 requires a NULL byte, select one of the 16-bit or 32-bit data types. Because the 8-bit data types are NULL terminated character vectors, the NULL byte would terminate the character vector.

Programmatic Use

Block Parameter: xmtdatatype1,xmtdatatype2

Receive Setup

This parameter specifies the port for which you want to view or modify parameters. On the Simulink block, the upper port is port 1 and the lower port is port 2.

Programmatic Use

Block Parameter: port

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

Programmatic Use

Block Parameter: rcvfifosize1,rcvfifosize2

Enter the maximum number of elements that you want returned by a single call to this block. The block uses this parameter to set the output vector width.

If the Read to delimiter check box is selected and if the block does not find the delimiter before it reads Receive maximum read characters, the output vector is empty.

Programmatic Use

Block Parameter: rcvmaxread1,rcvmaxread2

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.

Programmatic Use

Block Parameter: rcvminread1,rcvminread2

Select this check box to have this block return all characters in the FIFO, up to and including the specified delimiter.

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

If the block does not find the delimiter before it reads Receive maximum read characters, the output vector is empty.

Programmatic Use

Block Parameter: rcvusedelim1,rcvusedelim2

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).

Programmatic Use

Block Parameter: rcvdelim1,rcvdelim2

This parameter specifies the data type of the receiver. The 8-bit data types produce a NULL-terminated character vector in the output vector.

For 16-bit 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-bit 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 8 bits of each element; the first element of the vector contains the number of data elements that follow.

Programmatic Use

Block Parameter: rcvdatatype1,rcvdatatype2

Enter the base sample time or a multiple of the base sample time. -1 means that sample time is inherited.

Programmatic Use

Block Parameter: rcvsampletime1,rcvsampletime2

Introduced in R2008a