Well my code is perl not C, but if I knew where the base code was and had write access I could contribute untested C based on the perl. Basically I changed the string of "ifs" that check for convergence.
if ( abs mean_accel_x <= accel_dead_zone )
{
ready++;;
}
else
to
if ( abs mean_accel_x <= accel_dead_zone )
{
ready |= 0x80;
}
else
And the exit from the loop to
if (ready == 0xfc) break ;
Each subsequent check uses the next bit, so the next tests set 0x40, 0x20, 0x10, 0x08 & 0x04 which or'ed together give 0xfc. The problen with the existing code is that "ready" can get incremented more than once by the same test on a subsequent loop iteration and therefore reach 6 before all six axis have converged.
BTW anyone know where the /8 and /4 before stuffing into the registers is documented?