Is there a straightforward way (a library or a simple function) to get tilt compensated heading with these chips?
I have them all connected and working fine, but i cant seem to find a simple formula for calculating tilt compensated heading..

I successfully read accelerometer x,y,z, gyro x,y,z and magnetometer x,y,z.
I know the magnetometer points to magnetic north and it's not in a good scale 360 degrees round but i guess i could map it or somehow calibrate it against real north in my area.

My problem is i can't get these (incorrect) readings to stay the same when i tilt the device.
I plan on using the device on sea, and if it works in air.

You have a 3-axis magnetometer and a 3-axis accelerometer - one can measure the
magnetic vector, the other the gravity vector (both relative to the circuit board), you
need to know some vector math to project various vectors down to the horizontal plane.

You need to project both the magnetic vector and the axis of the circuit board down to
that plane and then find the angle between them - this means using dot- and cross-products
on 3D cartesian vectors. Wikipedia has lots of good maths stuff, but I wouldn't be
surprised if someone pops up with working code soon.