280 |
Chapter 8 / The BASIC Stamp 2p Prototype |
|
|
So now we’ve added the time, temperature, and relay board to our prototype even though we haven’t completely wired the 1- and 3-Wire interfaces to the Stamp. Now your prototype should look similar to Figure 8-12.
Figure 8-12
Communications Selection Options
Now that we have our keyboard, LCD display, temperature, time, and alarms all working it’s time to implement the communications interface. As you may recall, we have a design requirement to provide RS-232, USB, and Ethernet for our prototype. Our requirements call for only one active interface at a time and we have enough BASIC Stamp I/O pins available to accomplish this task. This means we have two options in how we implement our communications interface. The first is to use the available pins and implement all three interfaces separately, and at the same time. If we do this, we can share the handshake lines, thus reducing the total number of pins we need to eight total.
The second option for the BASIC Stamp is to build an interface that is functionally identical from a hardware interface point of view and implement all three interfaces using either a switch,
282 |
Chapter 8 / The BASIC Stamp 2p Prototype |
|
|
both forms of “serial” communication it would consolidate the serial communications hardware interface.
Now you may be asking how we would make this work and still use a menu selection, so here is the logical thinking behind this approach. To add the capability to switch select between RS-232 and USB, we would add a single switch that would electrically switch between the interfaces. By utilizing one processor pin we could read this switch to display the currently selected serial interface in use on the LCD. If we choose to use this approach it will be designed in after implementing all the interfaces to see how many processor pins are left unused.
Ethernet for the Embedded Developer
Let’s get started with the Ethernet interface first. Ethernet differs from RS-232 and USB because it communicates through a network backbone rather than a direct host connection. This means that the host doesn’t need to be physically nearby and any host that supports TCP/IP either in hardware or software can attach to the embedded system. In fact we could even use an embedded wireless Ethernet connection to eliminate cables completely. Today, Ethernet is the most common and widely used network interface in the world. For the embedded systems developer Ethernet offers many benefits that allow it to compete favorably with USB and RS-232. Over the last few years Ethernet has become very price competitive with USB as a high-speed interface.
Additionally, many microcontroller manufacturers now include Ethernet as a standard option. Maxim/Dallas Semiconductor and Zilog both include Ethernet hardware interfaces in their products. Go into any local store and you’ll find Ethernet cards for PCs for a little as $10 per card.
So, you ask, what about TCP/IP software? Well, there are many sources of embedded Ethernet software. The Maxim/Dallas Ethernet controllers have the TCP/IP protocol embedded right into the chip. Zilog provides the protocol in software, and there are many TCP/IP software packages that range in price
Chapter 8 / The BASIC Stamp 2p Prototype |
283 |
|
|
from free to thousands of dollars. There is really something for everyone.
Embedded systems developers have as many choices for Ethernet interfaces as PC users.
Ethernet interfaces operate at 10 to 100 MPS (megabits per second). Assuming a 10-bit frame per character (including overhead), that’s a full 1 to 10 million characters per second. Hook that up to the Internet over a high-speed connection and you are moving at a very fast pace that allows huge blocks of data to be moved very quickly. In fact, combining high-speed Ethernet cards with a broadband connection comes much closer to the speed of a dedicated T1 line than dial-up or DSL provide, and usually for a much lower cost than a T1.
Taking your Ethernet interface from being LAN to WAN accessible is a simple matter of providing a cable or hardware link to the WAN and possibly changing the IP address. To go from WAN to Internet access means adding accessibility to the outside world and possibly making some Ethernet address and port changes. The point is that the basic hardware connection doesn’t change. If you’re connected to a single system and want to connect to the LAN, it’s a simple matter of changing cables and possibly making some IP address changes. Here are the benefits that Ethernet provides for the host:
Cost — Ethernet chips and cards are inexpensive.
Wide platform support — All major host operating systems have built-in support for the protocol.
Expandability — Widening the availability of your device is fast, inexpensive, and easy once the initial development has been completed.
Speed — Ethernet is fast when compared to RS-232.
Provides a many-to-many connection — Ethernet can broadcast messages to a single user or a group at the same time.
Okay, Ethernet has some great benefits, but how easy is the software to implement on the embedded systems side? That depends on several factors. Ethernet is scalable from the hardware
284 |
Chapter 8 / The BASIC Stamp 2p Prototype |
|
|
perspective and implemented in software through multiple layers. A LAN becomes a WAN by scaling the network up in size as opposed to a complete software/hardware reconfiguration. Software is implemented in a similar fashion with different protocol layers to meet memory and protocol needs.
At the foundation of the software protocols is TCP/IP. This protocol provides endpoint connection identifiers called sockets (named after the old telephone switchboards where a plug had to be inserted in a socket for a call connection to be complete). TCP/IP is necessary for communication on LANs, WANs, and the Internet. Even though TCP/IP is widely available from many sources, it may not be implemented or fully implemented for your processor, so you may have a considerable amount of work to do. There is also a possibility that the Ethernet chip you have chosen (assuming you’ve chosen to build the Ethernet interface from scratch) has TCP/IP partially or fully implemented in firmware right on the chip (like the Maxim/Dallas components). As you can see, when it comes to implementing an Ethernet interface we have several options that require from little or no development to a full-blown hardware/software development project.
The trade-off is cost. The less hardware or software you’ll need to develop in-house, the higher the cost of the hardware interface (typically). Having said that, it can be more cost effective to use an off-the-shelf hardware/software solution in some cases depending on what (if any) special protocol/communications needs are required. Consider the human resources needed to build a custom Ethernet interface and the experience they will need to do it right. Developing a high-quality working Ethernet interface could cost hundreds of thousands of dollars, and that money is spent before you even know if the design works.
Remember that on the host side TCP/IP is handled by the operating system, but on the embedded system side the chances of Ethernet being a part of your microcontroller depend on several factors of which the two biggest are available memory and EEPROM space. No matter how you look at this topic, there are three ways for an embedded developer to implement TCP/IP.
286Chapter 8 / The BASIC Stamp 2p Prototype
Note:
A lot of factors need to be considered when implementing an Ethernet interface in an embedded system. Each project has different requirements and different areas where development is needed. All of these approaches to implementing Ethernet have their place, and under the right design circumstances are cost effective. As an engineer I too often see an approach eliminated early in the review process because of perceived costs. First perceptions are not always what they seem when development alternatives, ongoing maintenance costs, licensing fees, and integration costs are considered. As we move on we will see how using the NetBurner product with the BASIC Stamp will pay off in several ways.
The NetBurner SB72
For this prototype we have selected an out-of-the box hardware solution that provides a full software implementation and software development environment for enhancing or modifying the TCP/IP environment. We’ve made this choice because it allows us to immediately use the hardware and simply develop the needed software changes to communicate with the desktop systems. Since Ethernet will be an option for the finished product, we could purchase Ethernet interfaces for only those units ordered with that type of host interface. This can be very cost effective since it allows us market entry with a fully functional interface that has a minimal investment in staff and engineering costs.
Building the Ethernet Circuit
The NetBurner SB72 Ethernet kit includes the following components:
SB72 serial to Ethernet board
SB72 adapter development board
Software CD
288 |
Chapter 8 / The BASIC Stamp 2p Prototype |
|
|
The SB72 uses the Motorola Coldfire processor as the brains of the system. The processor and Ethernet interface are contained on one board while the second board provides various types of serial communication to an embedded system. These include RS-232, RS485, SPI (3-Wire), and TTL. The Ethernet board is shown in Figure 8-14 and the serial communications board in Figure 8-16.
Figure 8-14
The main processor/Ethernet board has several jumpers and interfaces. For our use we are concerned with only two of these connectors. They are J4, which is at the center top of Figure 8-14, and J8, which is the three-pin connector located just above the Ethernet connector and behind the second and third LED.
Chapter 8 / The BASIC Stamp 2p Prototype |
289 |
|
|
Connector J4 contains the RS-232 TTL interface for two serial ports. J8 has +5 on both outside pins and GND on the center pin. The second board contains connections for two RS-232 PC ports and power. Figure 8-16 shows the second board.
Chapter 8
Figure 8-16
In Figure 8-16 RS-232 port 1 is at the lower left with RS-232 port 0 on the right. Power may be connected either by a terminal block located at the upper right of the board or a regular power connector just below the terminal block. The connector at the center top of the board has a 10-pin ribbon connector that attaches it to the processor board.
Figure 8-17 shows the complete assembly with both boards attached.