About a week ago, I noticed that my phone was no longer sensing its position. The screen would not rotate, and the compass was not working. I ran the sensor test using the *#0*# code, and both the accelerometer and magnetic sensor were stuck on one reading regardless of phone position. Rebooting had no effect.
I found the following procedure on a different site. I would post the link to give proper credit, but I don't have sufficient forum privileges because this is my first post. It was on the dp.nonoo.hu blog.
Your Samsung Galaxy S phone’s compass is not working? Auto rotation is faulty? Check your hardware by dialing *#0*# – this is a factory test app for the phone.
If the compass is broken there too, here’s how you can fix it: delete /data/system/ms3c_yamaha.cfg, and if there’s a backup file, delete it too, then reboot.
If it won’t help, make sure the files are deleted and then run /system/bin/sensorcalibutil_yamaha from a root shell, follow the instructions and then reboot your phone.
I deleted the file using RootExplorer and rebooted. The accelerometer and magnetic sensor were working perfectly.