A typical system for distributed monitoring and/or control consists of a multidrop network—a PC acts as the host and communicates with 8-bit microcontrollers acting as slaves (see the figure). Usually, the physical layer of such a network is based on the RS-485 standard, while the logical layer is a commercial or user-defined protocol. In either case there’s an address byte within the transmitted frame that identifies the target slave device.
With early-generation microcontrollers, all slaves had to search for this address byte within the frame to determine whether the frame was addressed to them. This meant that every slave in the network had to be interrupted by every byte being transmitted, wasting the slaves’ precious CPU processing time.
Later microcontrollers, like Motorola’s 68HC05C8 or Intel’s 8051, implemented their serial port with a special mode for multiprocessor communications. In this mode, 9 bits are received. The 9th bit goes to a special register. The serial port can be configured to activate the serial-port interrupt, depending on the state (i.e., a logical one) of the 9th bit.
When the master wants to transmit a block of data to one of several slaves, it first sends out an address byte that identifies the target slave. An address byte has its 9th bit set, while a data byte has it cleared. Because of this bit state, the address byte will interrupt all slaves. Each one examines the received byte and see if it’s being addressed.
The addressed slave will activate the serial port interrupt (ignoring the 9th bit state of successive bytes) to receive the data following the address byte. The non-addressed slaves will continue with their program, ignoring the incoming data bytes until a new address byte interrupts them, minimizing wasted CPU processing time.
From the master point of view, the main problem with this addressing method is that the PC UART (originally 8250-based and now 16x50-based) doesn’t have the newer 9-bit word capability. It would be necessary to add hardware to the PC, such as another microcontroller to handle communications with the slaves or a UART with 9-bit communciations mode (e.g., Intel’s 82521).
However, it’s possible to use the PC UART with 9-bit protocols without any extra hardware. The trick is to use the parity bit as the 9th bit. Suppose we want to send a string, such as “ABC,” to the slave processor at address 41h and that we’ve established odd parity for communications. The frame to be transmitted would look like that shown in the table.
The 8th bit is used to change the quantity of “ones” in the byte, causing the parity (9th) bit to be set properly to meet the parity used. This can be accomplished rather easily using two lookup tables: one for the byte as an address byte and one for the byte as a data byte. The table is indexed using the byte value to be transmitted. This way, any byte can behave both as an address byte or as a data byte (like 41h and “A”).
Due to the use of the 8th bit, this method limits the data byte length to 7 bits (i.e., standard ASCII) and slave addressing to 128 slaves. While this is sufficient for many networks, there are applications (code downloading, sending a CRC, etc.) where 8-bitlength words are needed. The code listing shows two C-like pseudocode routines as an example of how to avoid this restriction.
The trick here is to reconfigure the UART parity before each byte transmission, according to the type of byte to transmit. If we send a frame to slave #E9h (decimal 233, binary 11101001) the SetParity() function retreives the 233th element of “addrTbl”. This is the value to be written in the parity register of the UART. Here, it will configure the UART to use even parity; so, the parity (9th) bit will be set to one, causing this byte to be recognized as an address byte.
Once the address byte is transmitted, the function looks up in “dataTbl” to find the parity register values that convert (9th bit cleared) the next bytes of the frame into data bytes. If byte E9h appears within the frame, SetParity() will reconfigure the UART to use odd parity. Therefore, the 9th (parity) bit will be cleared and, this time, the network will see it as a data byte.