290 |
Chapter 8 / The BASIC Stamp 2p Prototype |
|
|
In Figure 8-17 the processor board is located on the left side with the I/O card on the right. Notice the 10-pin ribbon cable that connects both boards. For our use we want to use the TTL RS-232 port that would normally be connected to a PC. We can simply disconnect the ribbon cable and attach the TTL level signals to the BASIC Stamp; however, in doing so we will eliminate our ability to do source code debugging since the second RS-232 port is used for that purpose. So to allow our debugger to work and still connect to the TTL RS-232 of the BASIC Stamp we will need a second 10-pin cable and two 10-pin headers that we will attach to our Stamp prototype board. Figure 8-18 illustrates what I’m talking about by simply adding a “tap” between the boards to which we can connect the BASIC Stamp.
Figure 8-18
This will allow us to use either or both RS-232 or TTL level RS-232 without losing our ability to debug. Table 8-2 shows the pin outs for the J5 connector.
Table 8-2
Pin |
Signal |
|
|
1 |
(VSS) Ground |
|
|
2 |
CTS1 |
|
|
3 |
TX1 |
|
|
4 |
RX1 |
|
|
292 |
Chapter 8 / The BASIC Stamp 2p Prototype |
|
|
After the Installation
Once the SB72 kit is installed, review the quick start guide to make sure the installation was done correctly. Within the NetBurner NNDK program group there are several programs and manuals. The quick start guide explains how to use the C IDE and create C projects. Also review the NNDK programmers guide (NNDKProgMan.pdf) and work through the first sample application. This will give you some first-hand experience in setting up the debugger, creating a project, saving the project, compiling, downloading, and debugging. Once this step is completed and working, you will know your installation is set up correctly. Then I would suggest reading the developers manuals that cover TCP/IP and uOS, the operating system used in the SB72. The SB72 compilers and IDE are open-source products that have been enhanced by NetBurner. The IDE is Dev-C++ and is available from SourceForge.net. The compiler is GCC and is available from www.gnu.org. SDB is also available from www.gnu.org.
Testing the SB72 Setup
Now let’s test our SB72 installation and see if it works. Once we complete this step, we will attach our BASIC Stamp and write a short program to see if the Stamp can send and receive data via the NetBurner connection.
The SB72 can be connected directly to a PC or to an Ethernet hub. The kit includes two cables, one red and one blue. If you’re connecting the SB72 directly to your computer, use the red cable; otherwise use the blue. Connect the Ethernet cable and make sure the cable that connects the SB72 and the I/O board together is in place. Plug in the transformer and connect power to the SB72 I/O board. The green LED next to the Ethernet connect should light immediately, indicating the power is connected. After a few seconds the remaining two lights should come on to indicate a good Ethernet connection has been made.
Chapter 8 / The BASIC Stamp 2p Prototype |
293 |
|
|
If you installed the NetBurner tools to the default path, then you should have a directory on your C drive named Nburn. Navigate to the PCBin folder and run the IPSetup program. You should see a screen similar to Figure 8-19.
Chapter 8
Figure 8-19
If you’re unfamiliar with Ethernet let’s walk through the information you’re looking at. The first address is the device address of the SB72, which in this case is set to 192.168.0.252. This is the device address and has to be unique to the LAN or WAN it is attached to. The second address is the network mask. This can be used to define a workgroup or location within a company or region. The gateway address is set to 0.0.0.0, which means the IP address in line 1 is static or set manually. We could have a DHCP server assign the IP address, in which case we would input the address of the DHCP server in this line. The final IP address is for the domain name server, or DNS. Again, if we had a resident domain name server we would put that address here. The last entry is the serial baud rate for the RS-232 debug port.
If an SB72 is detected when IPSetup starts, it will be displayed in the window to the right of the IP addresses, which in this case is true. If the application running on the SB72 supports a web page the Launch Webpage button will be active. If you wish to set up TFTP, then click the Advanced button to see or change current TFTP settings. Since the SB72 has an application running that does support a web page, let’s click the Launch
294 |
Chapter 8 / The BASIC Stamp 2p Prototype |
|
|
Webpage button. Your default browser should start and a page similar to Figure 8-20 should be displayed.
Figure 8-20
Some of the information displayed also appears in IPSetup but other information does not. For example you can change the device name and submit the change to the SB72 by clicking the Update button at the bottom of this page. You can also configure the other serial port that will be attached to the BASIC Stamp from this page.
Let’s download and run a simple test program. We will walk through the steps necessary to write, download, and test a simple program. In the process we will take a look at what needs to be done to utilize the Ethernet interface with minimal code changes to the BASIC Stamp code. Remember that the BASIC Stamp views the SB72 as a serial I/O device. This means that the SB72 will be responsible for the session management to the host and serial data I/O to the Stamp, and properly packetizing the data into our message protocol. While Ethernet allows us to have a many-to-one relationship, we will implement a simple TCP/IP
Chapter 8 / The BASIC Stamp 2p Prototype |
295 |
|
|
program without the frills for the prototype. The SB72 has a multitasking supervisor that allows many tasks to run at one time by dividing the available time by priority. Let’s take a look at how the finished Ethernet interface will integrate to the BASIC Stamp.
Chapter 8
Figure 8-21
Right now we are dealing with the embedded side; we will cover the host development in Chapter 11. We will set up the SB72 as a TCP/IP server that listens on port 3675. Port 3675 is allocated by IANA to another product I developed and sell for the telephony industry so we aren’t stealing someone else’s port number. (Please don’t use this port in your production products; you can apply for a port number at www.iana.org.) This test will require one Ethernet port and two serial ports. As we complete the SB72 interface we will eliminate the need for one serial port since we will move that I/O data to the BS2, but this test is just to get us started.
We will write a template that will be used for the rest of this chapter. Using the template we will then write our test program,
296 |
Chapter 8 / The BASIC Stamp 2p Prototype |
|
|
which will evolve into our Ethernet handler for the BS2. Currently we are using the SB72 serial port and power board. By using the same port and data configuration for our test we can get our software working. Then we will connect the port to connector J6 on the SB72 and our BS2 will be connected to J5 (which is the TTL serial). Finally, we will supply +5 and GND to connector J8 on the SB72. Those three connections will allow us to eliminate the SB72 I/O board, power connection, and second serial port.
To write our template let’s go the Nburn\devcpp folder and run devcpp. When the program starts, there are no open files or projects. To create our base template, select File | New | Appwizard.
Figure 8-22
Enter Template for the application name. Leave the platform set to Default. Create a path to Nburn\embbk1\chapter8\test1 and use this as the target folder for the template project. Uncheck Include DHCP and WIFI but leave the WebServer and AutoUpdate boxes checked. Click the Create button. We now
298 |
Chapter 8 / The BASIC Stamp 2p Prototype |
|
|
choose the Make Clean option. This will erase any temporary files and get the environment ready for a clean build. When complete, a progress window will remain on the screen like the one in Figure 8-23.
Figure 8-23
When all the files have been removed, the Progress button will change to Close; just click Close to continue.
Next, we will compile, link, and download the program to the SB72. This is where the AutoUpdate selection comes into play. AutoUpate will download the code and start the program automatically. This allows you to see the results of your program immediately. If we wish to debug we need to make a few changes, but for now let’s see what this program does.
By default the program will output any information via the printf statements to port 1, so make sure you have a DB9 cable attached to serial port 1 on the SB72 and attached to a COM port on the host. After you’ve connected the serial cable we need to go to the Nburn\pctools directory and run the MTTY application. Select the proper COM port and choose a baud rate of 115200, leaving all the other options unchanged. Now press the Connect button. If the port was properly opened, Connect will change to
Chapter 8 / The BASIC Stamp 2p Prototype |
299 |
|
|
Disconnect; otherwise an error message will be displayed after a timeout period has elapsed.
Now we will compile, link, and download the program to the SB72. Again, choose the Build menu but this time select the Compile and Download selection or simply press the F9 key. A progress dialog will be displayed such as the one in Figure 8-24.
Chapter 8
Figure 8-24
If the program compiled and linked correctly when the auto update program is executed, a download progress bar will be shown as in Figure 8-25.
Figure 8-25
Once the download is completed the progress bar will disappear automatically. After the program is downloaded successfully, the SB72 will automatically be reset. Once the application is running, an “Application started” message will be sent to the terminal port