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!

11 comments:

  1. I'm trying to do something similar with this wifi module. Any chance you can throw up your modified example code? I just can't seem to get SPI working.

    ReplyDelete
  2. One thing I took out was the SPI switching in the Microchip code. It handles SPI bus sharing but I don't really need that so to simplify the code I pulled it out. I will be working on code a bunch tonight. I will post what I have late tonight or tomorrow. Hopefully it can be of some help. If I haven't just shoot me an email.

    ReplyDelete
  3. Looking forward to that.... I've been wading through these ifdefs for days only to still not have working code. It's somewhat maddening. Oh, and yeah, I don't really need the SPI bus sharing code either. I have one other SPI device, but it's on a separate bus.

    ReplyDelete
  4. I have spent a bunch of time turning my WiFi code into a portable module but have hit a wall so unfortunately I can't post that as it is very broken. I'd be happy to send you my original working code to play with. Shoot me an email at sidwarkd at hardlysoftware dot com and I'll zip it up and send it to you.

    ReplyDelete
  5. Hey this is really great!
    Would You mind sharing your Pin-Breakout Layout with me? If I could replicate it, it would really decrease the price of my future wifi-projects. I`ve only found boards with Arduinos or other ATmegas added for at least twice as much money as the MRF24WB0MA would cost alone and I don`t want to be limited in the selection of the host-controller.
    It woud be very helpful and nice if you could send me the layout files :)
    e-mail: ulrich.terhorst@gmail.com

    ReplyDelete
  6. I also did my board and I will use this module with PIC 18F but I can't find program for pic 18f, I want to do a simple thing, I want to scan for specific SSIDs of AP's and return the RSSI value,I would greatly appreciate if you send me your code example
    mrcaiuby@gmail.com

    ReplyDelete
    Replies
    1. Sent. Hopefully it helps. I really need to take some time to put together a stack tutorial. I love the idea of your project as the starting point for it.

      Delete
  7. This is a really great project. Any chance you would be willing to share the schematics and code?

    ReplyDelete
    Replies
    1. Hey Joshua, I haven't touched this project in years. I believe I have a very old version of the code that I'd be happy to email to you. As far as schematics I think I have an Eagle layout somewhere that I'll have to dig up. Shoot me an email at sidwarkd at hardlysoftware dot com and I'll do my best.

      Delete
  8. Hello
    that project was very fantastic, i want to try it with my hands :))))., because it can help me in my project that work with TCP/IP
    would you mind sending me your code please??
    my Email is t.ashkan89@gmail.com

    thank you very much

    ReplyDelete

Keep it clean and civil. That's all I ask.