LSM303DLHC - Calibration, Pitch, Roll and Tilt Compensated Heading

jremington:

  roll  = atan2(fYa, sqrt(fXa * fXa + fZa * fZa));

pitch = atan2(fXa, sqrt(fYa * fYa + fZa * fZa));



One of the two equations for pitch and roll is wrong, so it is not surprising that the correction is wrong.

I'm confused why you say something is wrong here. It's straight from the OP. Is it wrong there too?

EDIT: I guess I should mention, I am struggling with getting the OP's calibration and code working for me.