Bailey O.H.Embedded systems.Desktop integration.2005
.pdf
200 |
Chapter 7 / Hardware Development |
|
|
Figure 7-4
If the host system (DTE) has data to send, it first checks the Clear To Send (CTS) line to see if the embedded system is ready to accept data. If it is ready, the host will turn on the Request To Send (RTS) line, send a data character, check the status of CTS again (to see if the receive buffer on the DCE is full), and start the loop over again until the last character has been sent. The host will then turn off RTS. Remember that the host in this case is the Windows or UNIX system. In Figure 7-5 we illustrate how DCE handles the request from DTE.
Chapter 7 / Hardware Development |
201 |
|
|
Chapter 7
Figure 7-5
In Figures 7-4 and 7-5 we see how the DTE controls all data flow through the use of the RTS line. This is important because it means that DTE is being used as the RS-232 session manager. This is where many people get confused on how RS-232 communications works. The same signals exist on both sides of the interface. The difference is in where the pins get attached. In Figure 7-6 we have an RTS and CTS signal on both the DTE and DCE sides of the interface. At first glance it would appear that if pin 7 were RTS on the DCE, then pin 7 would be RTS on the DTE end. That assumption would be wrong.
This is one of the biggest areas of confusion when implementing a true RS-232 interface. Remembering how to properly implement this interface is both easy and straightforward. The
202 |
Chapter 7 / Hardware Development |
|
|
signal pins are crossed for the CTS/RTS signals. This means that RTS at either end gets attached to CTS at the other end. If the RTS interface isn’t used, it’s always a good idea to connect the CTS/RTS pins together locally.
In Figure 7-6 RTS and CTS are crossed at both ends. In addition, please note that DTR, DTS, and Pin 1 are connected together. This indicates that the DTE/DCE interface is not used, and by tying the signals together they will always indicate ready if the handshake line is turned on.
DCE |
|
|
|
DTE |
|
|
|
|
|
|
1 |
|
1 |
|
Transmit |
2 |
|
2 |
Transmit |
Receive |
3 |
|
3 |
Receive |
|
4 |
|
4 |
|
Ground |
5 |
|
5 |
Ground |
|
6 |
|
6 |
|
RTS |
7 |
|
7 |
RTS |
CTS |
8 |
|
8 |
CTS |
N/C |
9 |
|
9 |
N/C |
|
|
|
|
|
Embedded |
|
|
PC |
|
System |
|
|
|
Host |
Figure 7-6
Figure 7-6 shows a top view of how our DTE and DCE will be connected. The embedded system end is a female DB9 connector since it is defined as DCE. This will allow any standard DB9 straight through serial cable to be used in connecting the two systems together.
To recap the RS-232 interface, we have three levels of handshakes. We have the DTE/DCE, which is really just an equipment handshake. It can only tell us if two mating pieces of equipment are connected and only if they are both turned on. Next we have the CTS/RTS interface, which is really a data traffic cop used to signal when data can be transmitted. Finally, we have the XON/XOFF interface, which is a software-only implementation of a data handshake.
Chapter 7 / Hardware Development |
203 |
|
|
Building the RS-232 Interface
The MAX232CPE serial interface chip can be broken into two different functional groups: power and data. The power management portion of the chip includes two charge pumps. Again, these are used to increase a voltage level through the use of capacitors. The first charge pump utilizes pins 1, 2, and 3 to provide a positive voltage of at least 8.5 volts. The second charge pump utilizes pins 4, 5, and 6 in providing a negative voltage of at least –8.5 volts. Both of these charge pump circuits claim to be voltage doubling, which means that +10 volts and –10 volts are provided; however, the chips are rated to provide at least 8.5 volts and RS-232 standards will work fine with these voltages. If we were going long distances, then we would want to consider increasing these voltages to +10 volts and –10 volts to provide adequate signal strength, but since we are only a few feet apart this isn’t important.
The data portion of the chip is the RS-232 transceivers. Each transceiver uses four pins, two for TTL level I/O and two for RS-232 level I/O. The second transceiver uses pins 7, 8, 9, and 10. Pins 9 and 10 are TTL I/O, with pins 7 and 8 being RS-232 level I/O signals. Transceiver 1 is on pins 11, 12, 13, and 14 with pins 11 and 12 being TTL I/O, while pins 13 and 14 are RS-232 level I/O. You may have noticed the TTL pins are grouped together in pins 9 through 12. The remaining two pins are ground (pin 15) and power (pin 16), which carries +5 volts. Figure 7-7 shows how the functional divisions on the MAX232 chip are broken down.
Chapter 7
204 |
Chapter 7 / Hardware Development |
|
|
Figure 7-7
Let’s go through the interface step by step. Take a look at Figure 7-8. First, you’ll notice an absence of pins 1, 4, 6, and 9 being used on the DB9 connector. These pins aren’t used in our application; however, pins 1, 4, and 6 get tied together just in case the host accidentally looks for DTR/DSR signaling. After tying these pins together we will assert the signals when the system initializes. Asserting those signals means they will be driven to a high state (+8.5 volts), which indicates a “ready” condition. Pin 9 was left off altogether since it isn’t used at all in our design. I’ve tested the configuration on several systems and have not had any problems with it.
Next, you will note that the ground pin on the chip (pin 15) is connected to the ground on the DB9 (pin 5). This connection is very important since it equalizes the ground on both ends of the connection. If this ground is not connected or is improperly connected, the integrity of all the other signals will be compromised. This could cause all types of problems that would be all but impossible to diagnose, including erratic data.
Chapter 7 / Hardware Development |
205 |
|
|
|
|
DB-9 Pin |
|
|
MAX232 |
RS-232 |
|
|
|
|
|
1 |
16 |
|
5 |
2 |
15 |
Gnd |
|
|
|
||
3 |
14 |
TD |
2 |
4 |
13 |
RD |
3 |
|
|
|
|
5 |
12 |
|
|
6 |
11 |
|
|
7 |
10 |
|
|
8 |
9 |
|
|
|
|
CTS |
8 |
|
|
RTS |
7 |
RTS CTS TD RD
TTL
Figure 7-8
Finally, we have the DB9 connector as viewed from the front. In Figure 7-9 a standard DB9 is shown with the RS-232 signal definitions as we are looking at the front of the connector.
DCD RD TD DTR |
Gnd |
1 |
2 |
3 |
4 |
5 |
6 |
|
7 |
8 |
9 |
DSR |
|
RTS |
CTS |
|
DB-9 Male Front View
Figure 7-9
Chapter 7
Remember that DCD, DTR, and DSR (pins 1, 4, and 6) get tied together at both ends of the cable.
206 |
Chapter 7 / Hardware Development |
|
|
The RS-232 Schematic
Now that we’ve covered the RS-232 interface in detail and the handshake, let’s look at the completed circuit. In Figure 7-10 we have a completed RS-232 interface. SV1 is our TTL level connection to our microcontroller. X1 is our DB9, which is the RS-232 level interface to our host. SV2 is our external power and ground interface.
Figure 7-10
This board requires the following components. They are:
One prototype board that supports a DIP socket (Radio Shack 276-159)
One 16-pin DIP socket (Radio Shack 276-1998)
One MAX232CPE or equivalent RS-232 transceiver (DigiKey Part #296-6940-5-ND)
Four 1 F electrolytic capacitors (Radio Shack 272-996)
One DB9 female solder type connector (Radio Shack 276-1538)
Assorted 22 gauge stranded wire (Radio Shack 278-1221)
Two 2-wire terminal blocks (Radio Shack 276-1388)
Chapter 7 / Hardware Development |
207 |
|
|
To build this circuit, follow these steps:
1. |
Solder the 16-pin socket to the prototype board. Remember |
7 |
|
the center. When mounting the socket, leave the unused |
Chapter |
|
that the top of the socket is the end with the “U” recess in |
|
|
holes at the top of the board; we will use these for power |
|
|
connections. |
|
2. |
Cut a 6-inch piece each of red and black 22 gauge wire and |
|
|
strip 3/8 inch of shielding from each end. Carefully apply a |
|
|
small amount of solder to each end of the wire to prevent |
|
|
fraying. |
|
3. |
There are several additional solder pads not being used on |
|
|
the prototype board at the top. Solder one end of the red wire |
|
|
to the top leftmost hole. |
|
4. |
Next, solder one end of the black wire to the top rightmost |
|
|
hole. |
|
5. |
If step 1 was completed properly, there will be a second hole |
|
|
on the board directly beneath the two holes we just attached |
|
|
wires to. Using short pieces of red and black wires, connect |
|
|
the two holes and solder the jumpers in place. |
|
6. |
Solder a capacitor across pins 1 and 3 of the 16-pin socket, |
|
|
making sure the + symbol is toward pin number 1. |
|
7. |
Solder a second capacitor between pin 2 and the +5 volt sup- |
|
|
ply, making sure the + side of the capacitor is toward pin 2. |
|
8. |
Solder the third capacitor’s – lead to pin 6 and the remaining |
|
|
lead to ground. |
|
9. |
Solder the remaining capacitor’s + lead to pin 16 and the – |
|
|
lead to ground. |
|
10. |
Solder a jumper from the +5 supply to pin 16. This lead pro- |
|
|
vides power to the chip. |
|
11. |
Solder a jumper from pin 15 to ground. This will provide the |
|
|
ground to power the chip. |
|
208Chapter 7 / Hardware Development
Note:
This jumper is in addition to the capacitor we attached above. The capacitors we used on pins 15 and 16 are filters to prevent noise from getting into the transceiver circuits. The chip will not work properly if pins 15 and 16 are not connected properly.
12.Cut four pieces of 22 gauge wire approximately 4 inches long and strip 3/8 inch of insulation off each end.
13.Solder one end of each wire to the solder pads attached to pins 9, 10, 11, and 12, leaving the other ends unattached. These are the TTL lines that will go to the microcontrollers.
14.Solder terminal blocks to the solder pads attached to pins 7 and 8, and 13, and 14. These are the RS-232 lines that will go to the DB9-F.
If you soldered the RS-232 wires as directed in step 14 your board will look similar to the photograph in Figure 7-11.
Note:
Figure 7-11 shows the board using tantalum capacitors instead of electrolytic. This was done to have plenty of room for labels in the photo. While you can use tantalum capacitors instead of electrolytic, tantalum capacitors cost much more than the equivalent electrolytic. The wires in the top of the photograph go to power and ground connections on the microcontroller. The resistor and LED provide a visual indicator that power has been applied. The lines marked 3, 4, 5, and 6 are the TTL lines that go to the microcontroller TX, RX, RTS, and CTS lines. Lines 1, 2, 7, and 8 are the RS-232 lines that get connected to the DB9-F.
Chapter 7 / Hardware Development |
209 |
|
|
Chapter 7
Figure 7-11
The data lines in Figure 7-11 are numbered as follows:
1)RS-232 RTS signal
2)RS-232 CTS signal
3)TTL CTS signal
4)TTL RTS signal
5)TTL TD signal
6)TTL RD signal
7)RS-232 RD signal
8)RS-232 TD signal
