I've been playing with the Honeywell HMC5843 I2C magnetometer triad as a potential hardware addition to the gluonpilot. It is a three axis magnetometer which provides a lot of potential for not only obtaining static heading data, but also vector matching to supplement the accelerometers. For development I've used the breakout board from sparkfun (the breakout I received was flakey as supplied and I had to replace the capacitor with a 10uF ceramic for consistent operation - see the forums at sparkfun.com).
I've attached a working MPLAB project. The code should be all inclusive and self explanatory. It's close to Tom's code guidelines - except I'm using the internal FRC on my dspic hardware platform (btw nice to see the boards are in and anxiously waiting). I've substituted microcontroller.c with my own micro_frc.c. Switching to the external oscillator should only require using Tom's microcontroller.c and possibly adjusting I2C1BRG for the I2C frequency.
The code also demonstrates how to use a c union structure to avoid shifting bits around when reading values by the byte - see hmc5843.h
Note - like accelerometers you don't have to calibrate these devices if you calculate using ratios of the axis.
Some example uses:
Total measured magnetic field is |Hearth| = sqrt(Hx2 + Hy2 + Hz2)
For level conditions true heading = atan (YH / XH) +- declination
If the attitude is known phi=roll theta=pitch, first project onto xy plane with
YH = Y*cos(phi) + Z*sin(theta)
XH = X*cos(theta) + Y*sin(phi)*sin(theta) - Z*cos(phi)*sin(theta)
More data can be derived knowing the local inclination which defines the vertical component of the local magnetic field. See http://www.ngdc.noaa.gov/geomagmodels/IGRFGrid.jsp
Use the code as you please.
Mitch