circuitcellar.com
Magazine Support   Digital Library   Products & Services   Suppliers Directory 
 
 





 

November 2004, Issue 172

TCP/IP Stack Solution
A Detailed Look at the CMX-MicroNet


by Fred Eady


LAN BUGGY

My new LAN buggy is composed of a 2 × 16 LCD, a Packet Whacker, a programmer/debugger interface (for the hockey puck), a regulated 5-VDC supply, and a microEngineering Labs PICProto 80 development board carrying a PIC18F8621 running at 20 MHz. My new form of LAN locomotion is posing in Photo 3. The PIC18F8621 is an 84-pin part. As you can see in Photo 3, I didn’t use all 84 pins. So, only the active connections are shown in Figure 3.

(Click here to enlarge)

Photo 3—No rocket science here. The Packet Whacker is wired into the PIC18F8621 according to the I/O layout specified in the CMX-MicroNet rtlregs.h file. I modified the hockey puck interface cable to accommodate the microEngineering Labs PICProto 80 ICSP connector and added some code to drive the LCD.

 

(Click here to enlarge)

Figure 3—It’s extremely uncharacteristic of me not to wire in a serial port. However, I won’t be exercising the CMX-MicroNet PPP or SLIP functionality, so it would be a waste to include a serial port here. Here’s yet another microcontroller that is supported by the ubiquitous Packet Whacker.

I’ve already test driven CMX-MicroNet TCP and UDP functionality with the Easy Ethernet W/PIC18. The reason I built up this new LAN ride is to provide extra space for the other CMX-MicroNet components to run.

In addition to added headroom, the LAN buggy sports more horsepower. Although the LAN buggy is cruising along at 20 MHz, the PIC18F8621 has an engine that can run at 40 MHz. So, I put the pedal to the floor and turned on DHCP, TCP, and UDP. The statistics for ROM and RAM usage for the Packet Whacker/PIC18F8621 LAN buggy are shown in Figure 2c. 

Although the LAN buggy has plenty of legroom and lots of horsepower, I had to do a bit of engine tuning to get DHCP to cooperate. The Netgear router never granted the LAN buggy an IP address although it saw the LAN buggy’s MAC address. Again, I turned to the CMX-MicroNet support team. Paul’s initial site-unseen diagnosis was that my receive buffer was probably too small. Hmm. I slapped the sniffer into action. The DHCP offers from the router were 590 bytes in length. My LAN buggy’s receive buffer size was set for 122 bytes. As you can see in the Photo 4 sniffer shot, the LAN buggy was asking for an IP address but was unable to swallow the 590-byte offer. After I modified mnconfig.h and increased the receive buffer size, my little LAN buggy was granted a lease for 192.168.0.3.

(Click here to enlarge)

Photo 4—I can’t tell you how many times the sniffer has saved my bacon.

It isn’t likely that you would ever try to cram all of the CMX-MicroNet functionality into an application. However, I had to know if it could be done. So, I turned on everything with the exception of PPP and SLIP. The usage statistics for the big PIC are shown in Figure 2d.

Now that everything is loaded, let’s take a look at some of the other functionality the CMX-MicroNet offers beginning with SMTP. I’ve already put most of the pieces of SMTP into place. Listing 2 is a summary of what I have defined and where I defined it. The only additional thing I had to do to get SMTP online was set up the mail addresses and put some words into the mail body. After instructing the LAN Buggy to run the CMX-MicroNet SMTP example code, I ended up with what you see in Photo 5.

(Click here to enlarge)

Photo 5—This was easy to accomplish. After I had all of my IP ducks pointed in the right direction, it was just a simple matter of filling in the blanks and kicking off the program.

I got really tired of not knowing which portion of the CMX-MicroNet example code I was running. So, I decided to insert some choice code of my own to drive the LCD and tell me which piece of example code I had selected. The PICC-18 C compiler comes with an LCD code module that can drive LCDs in 4- or 8-bit mode. All of the necessary LCD commands are also included in the source code module. After studying the source code for the LCD driver, I figured that all I had to do was modify the lcd.h file and map the LCD driver’s I/O scheme to the LAN buggy’s I/O scheme. To preserve the original I/O definitions, I copied the original LCD include file, modified it to suit the LAN buggy, and renamed it freds_lcd.h. The PICC-18 C compiler also contains a nice delay function that I included and used with the modified LCD driver code.

Putting the PICC-18 C compiler code together to realize my custom LCD utility function was a piece of cake. The modifications and additions I made to get the LCD module up are shown in Listing 3.