Bailey O.H.Embedded systems.Desktop integration.2005
.pdf
190Chapter 7 / Hardware Development
Desoldering tool — I use a metal-barreled desoldering tool to fix my mistakes. There are many types of tools available from inexpensive bulbs (about $4) to desoldering irons (about $15). I also have a desoldering iron that I use if numerous parts are being desoldered.
Assorted stranded wire — A good assortment of 22 and 24 gauge stranded wire is a must. I always have four or five spools of assorted colors in my toolbox. Stranded wire won’t break as easily as solid wire and I put just a touch of solder on the end to prevent fraying (also known as “tinning” the end).
Assorted cutters and pliers — I use small and medium ones for cutting wires and holding small parts. I also use a product called Miracle Point for grasping small parts. These little tools are springloaded and have attached magnifying lenses. I also find small cutters from Xcelite to be very useful. These tools are very sharp and maintain their sharp edges well.
Magnifying glasses — When working with small parts a magnifying glass is a must. I use a product I found on the Internet called Helping Hands. It has a small metal base with two alligator clips and a magnifying glass and can hold small work pieces.
Small vise — I use a PanaVise Jr., which is designed to hold small circuit boards.
Assorted screwdrivers — Small and medium flat blade and Philips screwdrivers
Assorted tweezers — A good assortment of stainless steel tweezers
Multimeter — I have numerous multimeters that range in price from about $4 to over $60. Each has a purpose, with the most expensive meter having an RS-232 interface so I can do continuous recording. The least expensive meters I use to test components and low voltages.
Chapter 7 / Hardware Development |
191 |
|
||
|
|
|
|
|
Oscilloscope (optional) — An oscilloscope is a required |
|
|
||
piece of equipment if you’re serious about getting into the |
|
7 |
||
electronics area. Oscilloscopes make measuring signals, sig- |
||||
Chapter |
||||
|
|
|
||
nal timing, and debugging much easier. I own several oscilloscopes — one analog, one digital, and one USB digital scope. If you are just getting started and have never used an oscilloscope, I would recommend the Parallax USB oscilloscope. It comes with a book full of experiments to familiarize you with oscilloscope functions.
Logic analyzer (optional) — When developing any type of data communications product, a logic analyzer is almost a must. These devices capture electronic signals and reassemble them into readable data. While this can also be accomplished with a storage oscilloscope, a logic analyzer displays the bit patterns rather than just the signal transitions.
Soldering Techniques
I’m not going into tremendous details on how to solder because there are plenty of good sources of information on the subject already, so I’ll just cover the basics. Make sure your work area is well lit and ventilated. This is a must if you’re soldering for long periods of time or making printed circuit boards. If you’re using a regular soldering iron, make sure you let the iron warm up to the proper temperature before using it. The key to a good solder joint is providing the right amount of heat to the right spot for the right amount of time and the right amount of solder. The higher the wattage of the soldering iron element, the hotter the tip will get. A 20or 25-watt element provides enough heat to let the solder flow quickly. Do not heat the joint for more than a couple of seconds; applying too much heat for too long a period will damage components. If you’re soldering surface mount devices you may want to use a soldering station with low resistance to reduce the risk of static damage. This prevents ground resistance from
192 |
Chapter 7 / Hardware Development |
|
|
finding a path to the component. I don’t recommend you use surface mount devices (also known as SMDs) because they require special consideration when soldering and are hard to work with due to their small size. When soldering a joint, make certain that solder covers the entire wire end, not leaving “holes” around the connection. This will avoid a bad connection and uneven stress on the wire.
Building the Prototype Circuit Boards
There are many functions of this prototype that are common to all the microcontrollers we will use. We will start with the least difficult and progress to the most difficult. Most of the parts we will use can be obtained at the local Radio Shack store. Whenever possible the Radio Shack part number will appear in parentheses. Those parts that are not available at Radio Shack will be noted along with a source and part number. A current list of resources will also be available at www.wordware.com/files/
embsys and at www.time-lines.com. Since we have chosen to use an intelligent LCD display our task has been made somewhat easier.
To illustrate how we can build plug-compatible RS-232, USB, and Ethernet interfaces, we will put the RS-232 circuit on a separate board so we can create a true plug-and-play hardware interface for our microcontrollers. The first and easiest board to build is the RS-232 interface. The second board we will build contains the 1-Wire, 3-Wire, clock chip, temperature chip, and fan relay. We are using a very small relay that has a low current rating. As a result, don’t try attaching the fan blower on your furnace to this as this design is for concept proof only. The third and final board we will build has keypad functionality, power and alarm functions, an I2C interface, and a power supply. The reason we are providing power is because of the amount of current the Ethernet interface can draw. Let’s recap the purpose of each board.
Chapter 7 / Hardware Development |
193 |
||
|
|
||
Serial interface board — This board uses just one IC and sev- |
|||
eral capacitors to convert microcontroller signals to/from |
7 |
||
TTL to RS-232. It will be plug compatible with USB and |
|||
Chapter |
|||
Ethernet boards. |
|||
|
|||
Clock/temperature sensor/1-Wire/3-Wire interface board — This board consolidates all Dallas components and interfaces. This board will illustrate how to build a simple yet reliable 1-Wire interface that can support devices up to 2 feet away. It can also be used later as a model for remote temperature sensors.
The LCD, keypad, LED, alarm, I2C communications interface, and power supply board — This board interfaces to our intelligent LCD and contains the keys, LEDs, keypad interfaces, alarm buzzer and LED, and power supply.
The RS-232 Interface Board
The RS-232 interface is well established, as the last technical specification change made to it was in 1991. The interface is defined by the Electronics Industry Association (EIA) and has been widely used for over 40 years. The RS-232 interface connects two devices directly and works by attaching a 9-pin cable between the two devices. In order to facilitate an orderly conversation two types of RS-232 equipment are defined. The first is Data Terminal Equipment, which is also known as DTE. A personal computer is defined as DTE (even though a computer is an intelligent device). In simple terms, DTE is always an origination point of data (and usually in control of the data conversation). The second type of equipment defined in the RS-232 standard is Data Communications Equipment, also known as DCE. DCE is always a data carrier or transport. Figure 7-3 shows a typical RS-232 application.
194 |
Chapter 7 / Hardware Development |
|
|
Figure 7-3
As you can see from this illustration, any data host or consumer is DTE and the modem or data communications equipment is DCE. This is the easiest way to remember how a piece of equipment should be defined. If it is a data source, it is DTE; if it is a data carrier, it is DCE. To non-communications engineers these definitions have been a source of confusion over the years simply because we think of a PC as a piece of communications equipment rather than a piece of terminal equipment. By applying these simple rules, the public telephone switch in the example above is used only as a data transport.
The RS-232 hardware interface originally used a 25-pin cable to connect devices, but in recent years that has been replaced by a 9-pin D-Sub connector known as a DB9. By standard definition, DTE normally has a male connector and DCE has a female connector (but only if DTE/DCE were fully implemented). Using the analogy in Figure 7-3, our embedded system will be DCE since the PC is defined as DTE. We could also make this determination because the PC is considered the host and in control of the communications flow. If we were to define our embedded system as DTE it would require using a null-modem cable and could cause potential problems in connecting it to a host system. In that case, either an extra adapter or jumper box would be needed to allow both sides to properly communicate.
Chapter 7 / Hardware Development |
195 |
|
|
Rather than defining a hybrid communications system, we will define the embedded system as DCE. Using these definitions the 9-pin cable definition of RS-232 is shown in the following tables.
Table 7-1: Data Communications Equipment (DCE) RS-232 pin definitions
Pin Number |
Signal Name |
Direction |
|
|
|
1 |
Data Carrier Detect (DCD) |
To DTE |
|
|
|
2 |
Transmit Data (TX) |
To DTE |
|
|
|
3 |
Receive Data (RX) |
From DTE |
|
|
|
4 |
DTE Ready (DTE) |
From DTE |
|
|
|
5 |
Signal Ground |
From DTE |
|
|
|
6 |
DCE Ready (DCE) |
To DTE |
|
|
|
7 |
Clear To Send (CTS) |
From DTE |
|
|
|
8 |
Request To Send (RTS) |
To DTE |
|
|
|
9 |
Ring Indicator (RI) |
To DTE |
|
|
|
Table 7-2: Data Terminal Equipment (DTE) RS-232 pin definitions
Pin Number |
Signal Name |
Direction |
|
|
|
1 |
Receive Signal Detect |
From DCE |
|
|
|
2 |
Receive Data (RX) |
From DCE |
|
|
|
3 |
Transmit Data (TX) |
To DCE |
|
|
|
4 |
DTE Ready (DTE) |
To DCE |
|
|
|
5 |
Signal Ground |
To DCE |
|
|
|
6 |
DCE Ready (DCE) |
From DCE |
|
|
|
7 |
Request-To-Send (RTS) |
To DCE |
|
|
|
8 |
Clear-To-Send (CTS) |
From DCE |
|
|
|
9 |
Ring Indicator (RI) |
From DCE |
|
|
|
Chapter 7
196 |
Chapter 7 / Hardware Development |
|
|
RS-232 Signal Voltage Levels
Normal voltage levels range from 3 to 5 volts for today’s microcontrollers. RS-232 voltage levels are different from the “normal” voltages. TTL voltages are in one of two states: high or low. A high TTL state is +5 volts. A low TTL state is +0 volts. These voltages are measured against the ground signal. RS-232, on the other hand, operates to a maximum of +12 and –12 volt signaling. The higher voltage levels allow an RS-232 signal to travel longer distances without additional devices needed to repeat the signal. In the early days of computing we designed line driver circuits that would boost the 5-volt signal level to the +12 and –12 levels. Over the years this method has been replaced with single chips that boost signals and handle the complete RS-232 TTL conversion to and from the host.
Note:
Many RS-232 circuits that appear in publications use +5 and –5 volts instead of +12 and –12. While it’s true that in recent years many RS-232 drivers in PCs can operate fine at these lower voltage levels, not all types of equipment can operate at these lower voltage levels without modifications. In addition, using RS-232 at +5 and –5 volts over long distances can stress the communications interface components, causing premature component failure or erratic behavior.
The MAX232 Serial Interface Chip
One of the easiest and most frequently used solutions to the voltage differences for TTL and RS-232 is the MAX232 chip from Maxim Semiconductor. This chip converts 5-volt TTL signals to a minimum of +8 and –8 volts. There are several variations of these chips. The two biggest differences are the number of RS-232 interfaces and the use of internal or external capacitors. For our needs we will use the BASIC MAX232CPE chip, which has two TTL-RS-232 level converters. Each level converter handles the conversion of two TTL lines. We will use the first for
Chapter 7 / Hardware Development |
197 |
|
|
data transmit and receive and the second for CTS/RTS handshaking. Over the years many other vendors have entered the market with their own version of the MAX232 chip. I happen to have several of the TI chips available so we will use that component for the heart of our circuit, but you can use any MAX232CPEcompatible chip as a direct replacement for the TI chip I’m using since they all share the same pinouts. If you decide to use a different chip, make sure the pinouts are the same or change your wiring to accommodate the new pinouts. Power and ground connections are not the same on all versions of the MAX232 chips. The MAX232CPE chip I am using requires a 1-microfarad capacitor. Some require only a .1-microfarad cap, so be certain you get the right capacitors if you choose a different MAX232 type component. The MAX232CPE is a 16-pin chip that has two complete RS-232 transceivers.
These chips work by using the capacitors to boost the signal voltage levels to operate within the RS-232 signal definitions. This type of circuit is known as a charge pump. The capacitor charges and when it reaches its discharge level, it pumps the higher voltage to the circuit. This chip comes in several different forms, but for our purpose we will use the 16-pin DIP, which is easy to work with and does not require surface mounting.
Note:
One of the biggest sources of errors in defining RS-232 electrically is made by not properly defining the DTE/DCE pins, which causes a hybrid to be developed. These types of errors lead to designs that are difficult to understand, wire, and debug. Avoid this problem by clearly defining the wiring between our embedded system and PC. Pay particular attention to the three different levels of handshaking available in the RS-232 standard. Two of these are hardware handshakes and the third is a software handshake. These handshake methods are defined as follows.
Chapter 7
198 |
Chapter 7 / Hardware Development |
|
|
The DSR/DTR Handshake Described
The first handshake method we will cover is known as DTR/ DSR, which stands for Data Terminal Ready and Data Set Ready. This handshake is generally used to let the data terminal or the data set equipment make itself known to the other. In short, looking at this signal tells if a matching piece of equipment is attached and powered up at the other end. It is not an indicator that the other piece of equipment is ready to accept data. For our purpose we will not use this handshake, opting instead to tie the pins for these signals together.
The RTS/CTS Handshake Described
The second handshake available is the RTS/CTS handshake, which stands for Request To Send/Clear To Send. This handshake is used to acknowledge it is OK to send data and/or data is ready to be sent. This handshake is also known as hardware flow control, since its primary use is controlling the flow or exchange of data.
The XON/XOFF Handshake Described
The third and final handshake is a software-only handshake. It can be used in addition to the RTS/CTS handshake or as its replacement. In this case, an XOFF character is sent to the transmitter notifying it to stop sending data. When the receiver is ready to accept data, an XON character is sent to start data flowing again. Again, this handshake is controlled by the host, which is defined as DTE.
Chapter 7 / Hardware Development |
199 |
|
|
Hardware and Software Handshake
Considerations
If we choose not to use the handshaking, we may experience data loss. Remember that our protocol checks to see that only good data packets are accepted. If a bad data packet is received, the entire packet is thrown out, making the sender transmit the entire packet again and taking valuable time. While the amount of time this takes on a PC host is minimal, our microcontroller has better things to do than continuously ask for the same data over and over again. Also keep in mind that a new PC runs at upward of 2 gigahertz, whereas a microcontroller runs at from 4 to 50 megahertz, making a PC about 40 times faster. To prevent data transmission errors we will implement RTS/CTS hardware handshaking. This will cost us the use of two additional processor pins, but it will assure data integrity and notify the host if the thermostat goes offline for extended periods, which could be a symptom of other problems. If the thermostat goes offline, the CTS line will be low, telling the host no data can be sent. The CTS line will also be used to regulate the flow of data coming into the microcontroller, acting as a traffic cop. This hopefully will prevent buffer overruns and avoid unnecessary data retransmissions.
Chapter 7
