Friday, October 7, 2011

Microchip Stack Working!

As usual it's been a while since I've posted. I have, however, made quite a bit of progress on the WiFi implementation. As of this posting I have the MRF24WB0MA connected to and communicating with the PIC in a simple setup that supports ICMP (ping requests), Telnet, and making simple GET requests to a website. That's really all of the supported functionality I'll need for my project. How did I get here?

Plugging in the Code

The first thing I did was try to get the Microchip stack compiling in a project. To isolate any issues that may be caused by my bootloader I decided to create a fresh project for it. I refactored the code a bit since Microchip ships a bunch of examples for their different sample boards. Most of it was removing button and LED code. I also trimmed out a bunch of the UART code. I have to hand it to Microchip for building code that is very cross-chip, cross-compiler friendly but it really makes the code messy. For instance I'm using a PIC18 chip but have to wade through all of the PIC32 and PIC16 and PIC24 code to find which chunks are actually going to be compiled. It's one big ifdef nightmare. Anyway, after about 3 hours of messing with it and reducing the default buffer sizes (my PIC doesn't have enough RAM for the defaults) I was able to compile the code in the project. Here's a look at the memory usage.

Breakout Board

Once the code was compiling it was time to actually try this board out. To do so I needed to create a breakout board because while some people may be able to meticulously solder to the tiny pads on the MRF24WB0MA I just don't have the patience. Besides, creating your own home-etched boards is like a rite of passage. I whipped up a simple breakout board in Eagle. The hardest part about that was remembering how to export the layout so I could print it multiple times in a document editor. I'll try to put a post up on that in the next little while. I use the PCB Fab in a Box system to etch my boards at home and I highly recommend it. It's very low cost, easy, and produces amazing results. Once you get the hang of it you can crank out very good prototype boards in about 30 minutes. Here is what it looks like when it's been transferred to the copper and ready to etch.



With the contact etch method it only takes about 2 to 3 minutes with a sponge and some ferric chloride from the local Radio Shack and you've got yourself a nice board. Drill the pad holes with a Dremel, do a little soldering and you end up with this.



With the breakout board done I soldered the MRF24WB0MA on along with a couple of male headers. I used some super handy connectors from Sparkfun to get everything wired up to my breadboard and connected to the PIC.

The Hard Part

Next was the hard part. As with virtually all projects this thing didn't work the first time I flipped the power switch. I ran in to several problems. First, I didn't read the MRF24WB0MA datasheet close enough to realize that one of the JTAG pins always requires a connection. I had to do some of that meticulous soldering I was trying to avoid to remedy that (notice the read lead wire going to one of the pins in the pictures). Second, I had incorrectly entered my SSID in the source code. Third, and most annoying, there was a tiny fleck of solder creating a short on the MRF24WB0MA. Once I removed that the module started trying to connect. Still it failed. I finally found that, by default, the code for the MRF24WB0MA tries to connect to your router on channels 1, 6, and 11. Mine was set to auto-select the channel and was using channel 2. Switched that to 1 and boom, I started getting an IP address.



I still couldn't do a simple GET request however. It would start to transfer data and just freeze up. After quite a bit of troubleshooting I found that I had not set up my buffers correctly in TCPIPConfig.h. I highly recommend using Microchip's utility to handle that for you. Once that was done I was pinging, telnetting, and GETing away.

Next Up

Now that I have the Wifi unit in a working state I need to polish up the hardware and the firmware code. I want to get the Wifi code into a module so it is easy to plug in to any project. Microchip does a pretty good job but with some smart defaults and a few other tweaks I think I can make it a bit more friendly for the average hobbyist. Here's what the whole thing looks like at this point. Kind of a mess but it works!