Low-Cost RS232 Multiplexer

The multiplexer has the following features:

The RS232 multiplexer is used for connecting multiple devices to one single RS232 port. It has one master port and 4 slave ports and works like a switch connecting the master port to one of the slave ports. The multiplexer works at a fixed data rate of 9600 baud (no parity, 1 stop bit). The communication must be line based, each line must be terminated by a carriage return (0x13). It can be used for example to control multiple stepper motors via one RS232 port.

There exist two different versions of microcontroller programs:

Version A: Data sent from the PC to the master RS232 port is transferred directly to the currently active slave port. A line sent from a device to a slave port is first stored completely into a buffer and then forwarded by the master port. The multiplexer puts a single digit in front of each line, indicating the id of the slave port which received the line.
Limitations: Because of a limited buffer size the maximum line length is 25 characters, including the terminating carriage return character. Each buffer can hold only one single line, therefore a device on a slave port may not send two lines immediately following each other, as the data has first to be forwarded by the master port. If this is necessary, use program version S.

This program for example allows parallel movement of multiple stepper motors. The active port can be switched before the corresponding motor has finished its movement, as data reception is independend from the actually chosen port.

Version S: With this program the RS232 multiplexer works more like an electronic switch. Data received by the master port is transferred direcly by the currently active slave port. Data received by the currently active slave port is forwarded unbuffered by the master port. This version doesn't have the limitations of version A, but all data transmitted by devices to an inactive slave port is lost.

With the "DoubleFox" series devices the version A microcontroller program can always be used. The communication with these devices always is line based and a device response line is never longer than 25 characters. The version S allows putting a multiplexer between PC and a device without changing communication protocol (except when a '$' at the start of a line can occur).

Assembly

Control commands

Control commands perform the switching between different ports as well as requesting status information. Control commands differ from normal data lines by their starting '$' sign. This '$' must be the first character of a line (i.e. it must be immediately transmitted after a 0x13 character). Control commands are only detected at the master port. To allow transmission of data lines starting with a '$' sign or allow stacking of multiplexers, a '$$' at a line start is transmitted as a single '$' followed by the normal data. As description of the control commands follows:

$?
Requests version identification string. The controller responds with someshing like 'DoubleFox MultiplexerA/S Rev. 1.0'

$s
Requests status information. The controller returns an 8 digit string, each digit is 1 or 0, respectively. The first 4 digit indicate framing errors. The first digit is 1 if a framing error has occurred at slave port 0, the second digit indicates a framing error on port 1 and so on. The last 4 digits indicate an overflow error and are always 0 on program version S. Overflow means that a character was received on a slave port before a previously received line could be fully transmittet by the master port. The 5th digit indicates an overflow error on slave port 0, the 6th digit on port 1 and so on.

$n
Makes port n the actual port. n is a digit from 0 to 3. Afterwards all data received at the master port is forwarded to slave port n. In program version S this also activates data reception on slave port n. In version A, data reception is independent of the choice of the actual port.

Stacking

Multiple RS232 multiplexers can be stacked. Stacking means, that the master port of a multiplexer can be connected to the slave port of another multiplexer. To issue a control command for a multiplexer connected to the slave port of a preceding multiplexer, use a double instead of a single '$'. The double '$' is translated into a single '$' by the first multiplexer and becomes a valid control command for the second multiplexer. With a triple '$' the third level of multiplexers can be addressed and so on. The maximum number of stacking levels depends on the program version. With version A, each level reduces the available line length as the receiver address digit on data reception must be stored within the buffer of the previous multiplexer. With 5 levels of multiplexers, the available line length for devices behind the last multiplexer level is 20 character. One has to imagine, that with 5 stacking levels already 1024 devices can be controlled! With program version 'S', the number of stacking levels is unlimited. The only limitation here is the signal running time.

Back


Frank Hitzel, 2003