Sensing tilt using accelerometer alone

johnwasser:
The accelerometer is sensing the pull of gravity. If the accelerometer is flat the X and Y accelerations are 0 and the Z acceleration is -1g. As the accelerometer tilts the Z acceleration gets closer to 0 and the X and/or Y accelerations go up or down. Using some trig you can determine the pitch and roll angles.

First thing to do is to calibrate the accelerometer so you can subtract the zero offset and calculate acceleration in g.

Right, I have done that. I have used the atan2 function to get the pitch and roll.
The problem is that when I get the pitch, i get strange values for roll, and when I get roll I get strange values for pitch.
*xrot = atan2(-yforce,-zforce)*57.2957795+180;
*yrot = atan2(-xforce,-zforce)*57.2957795+180;
*zrot = atan2(-yforce,-xforce)*57.2957795+180;
This is what I use, 180/PI = 57.2957795
xrot is the rotation about x axis.
I want to understand how is it done in smartphones?