Reprints     Printer-Friendly    Email this Article    RSS        Font Size     What's This?

[Ideas For Design]

Use The PC's UART With 9-Bit Protocols



Contributing Author  |   ED Online ID #6245  |   December 1, 1998

Article Rating: Not Rated

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.




Reprints     Printer-Friendly    Email this Article    RSS        Font Size     What's This?


  • Network-On-Chip Tools Arrive for The Masses
  • Tackling System Design Challenges Through Early Verification
  • ESL Tools Take Center Stage As Designers Move Up
  • Parasitic Extraction Tool Targets Next-Generation Custom ICs
  • Synopsys Jumps Into ESL-Synthesis Pool
  • Verify Control Systems Before Committing To Hardware
  • You're Using How Many FPGAs?
  • Tool Up For The FPGA Blitz
    1) Build A Smart Battery Charger Using A Single-Transistor Circuit
    (177 views today)
    2) Hot Hands For Some Cool Rock: Motion Sensing Meets Audio Engineering
    (168 views today)
    3) What's All This Transimpedance Amplifier Stuff, Anyhow? (Part 1)
    (88 views today)
    4) GPS-Derived Grandmaster Clock Delivers Ultra-Precise Time And Frequency Sync
    (83 views today)
    5) Downconverting Mixers Lower Power Consumption While Improving Performance
    (63 views today)
    ALL TOP 20







    Reader Comments

    But how to read 9-bit data? (Send is easy.)

    Anonymous -October 08, 2009

    POST YOUR COMMENTS HERE

    Name:

    Email:
    Rate this article:

     less useful more useful 
    1
    2
    3
    4
    5
    Your Comments:

    Enter the text from the image below




    Please refresh the page if you have trouble reading this text.
    (Acceptable Use Policy)
     
     

    PartFinder

    Find real-time pricing, stock status, same-day/next-day shipping options and more. Brought to you by Digi-Key. Go to PartFinder.    
    GlobalSpec

    PART SEARCH :
    Powered by: GlobalSpec - The Engineering Search Engine
    Sponsored Links

    Electronic Design Europe Electronic Design China EEPN Power Electronics Auto Electronics Microwaves & RF
    Mobile Dev & Design Schematics Find Power Products Military Electronics EE Events Related Resources