CMPS11 - Tilt Compensated Compass Module 

I2C mode

Connections

3.6v-5v
SDA
SCL
Mode
Factory use
0v Ground

To enter the I2C mode of operation leave the mode pin unconnected

I2C Communication
I2C communication protocol with the compass module is the same as popular eeprom's such as the 24C04. First send a start bit, the module address with the read/write bit low, then the register number you wish to read. This is followed by a repeated start and the module address again with the read/write bit high. You now read one or two bytes for 8bit or 16bit registers respectively. 16bit registers are read high byte first. The compass has a 28 byte array of registers. organized as below:

Register  Function
0 Command register (write) / Software version (read)
1 Compass Bearing 8 bit, i.e. 0-255 for a full circle
2,3 Compass Bearing 16 bit, i.e. 0-3599, representing 0-359.9 degrees. register 2 being the high byte
4 Pitch angle - signed byte giving angle in degrees from the horizontal plane, Kalman filtered with Gyro
5 Roll angle - signed byte giving angle in degrees from the horizontal plane, Kalman filtered with Gyro
6,7 Magnetometer X axis raw output, 16 bit signed integer with register 6 being the upper 8 bits
8,9 Magnetometer Y axis raw output, 16 bit signed integer with register 8 being the upper 8 bits
10,11 Magnetometer Z axis raw output, 16 bit signed integer with register 10 being the upper 8 bits
12,13 Accelerometer  X axis raw output, 16 bit signed integer with register 12 being the upper 8 bits
14,15 Accelerometer  Y axis raw output, 16 bit signed integer with register 14 being the upper 8 bits
16,17 Accelerometer  Z axis raw output, 16 bit signed integer with register 16 being the upper 8 bits
18,19 Gyro X axis raw output, 16 bit signed integer with register 18 being the upper 8 bits
20,21 Gyro  Y axis raw output, 16 bit signed integer with register 20 being the upper 8 bits
22,23 Gyro Z axis raw output, 16 bit signed integer with register 22 being the upper 8 bits
24,25 Temperature raw output, 16 bit signed integer with register 24 being the upper 8 bits
26 Pitch angle - signed byte giving angle in degrees from the horizontal plane (no Kalman filter)
27 Roll angle - signed byte giving angle in degrees from the horizontal plane (no Kalman filter)

Register 0 is a dual action register, in the event of a read the CMPS11 will reply with the software version, for a write it acts as the command register and is used to calibrate the compass, change address and if necessary restore the factory default calibration. Register 1 is the bearing converted to a 0-255 value, this may be easier for some applications than 0-3599 which requires two bytes. For those who require better resolution registers 2 and 3 (high byte first) form a 16 bit unsigned integer in the range 0-3599. This represents 0-359.9. Register 4 is the pitch angle, giving an angle of 0 when the board is flat and up to +/- 85 at maximum tilt in either direction and also features a Kalman filter that uses the gyro sensor to reduce errors caused by unwanted acceleration effects (such as shake). Register 5 works the same way but with results for the Roll angle. There is then an array of registers (6-25) providing all the raw sensor data from the magnetic and acceleration sensors. Finally we have included the pitch and roll angle with no Kalman filter in registers 26 and 27. The raw output values in registers 6-25 are exactly what we get from the LSM9DS0 sensor chip, customers wishing to make use of these should consult the ST data sheet for further information.

Calibration of the CMPS11 
Please do not do this until you have I2C communication fully working. I would recommend evaluating the CMPS11 performance first before implementing this function. Its purpose is to remove sensor gain and offset of both magnetometer and accelerometer and achieves this by looking for maximum sensor outputs. First of all you need to enter the calibration mode by sending a 3 byte sequence of 0xF0,0xF5 and then 0xF6 to the command register, these MUST be sent in 3 separate I2C frames, you cannot send them all at once. There MUST be a minimum of 20ms between each I2C frame. An I2C frame is [start sequence] [I2C address] [register address] [command byte] [stop sequence]. The LED will then extinguish and the CMPS11 should now be rotated in all directions in 3 dimensions, if a new maximum for any of the sensors is detected then the LED will flash, when you cannot get any further LED flashes in any direction then exit the calibration mode with a command of 0xF8. Please make sure that the CMPS11 is not located near to ferrous objects as this will distort the magnetic field and induce errors in the reading. While calibrating rotate the compass slowly. Remember the axis of the magnetic field is unlikely to be horizontal, it dips into the earth at an angle which varies depending on your location. At our offices in the UK it dips into the earth at 67 degrees and that is the orientation each axis of the compass needs to be to find the maximums. You need to find both positive and negative maximums for each axis so there are 6 points to calibrate. The accelerometer is also calibrated at the same time, so the module should also be positioned horizontal, inverted, and on all 4 sides to calibrate the 6 accelerometer points. Each accelerometer point needs to be stable for 200mS for its reading to be used for calibration. This delay is deliberate so that light taps to the module do not produces disruptive accelerometer readings which would mess up the pitch and roll angles. There is no delay for the magnetic points. The performance of the module is directly related to how well you perform calibration so do this slowly and carefully. 

Calibration of the CMPS11 for horizontal only operation
If the compass does not require the tilt compensation then a simple calibration may be used that can be implemented by a rotation on the horizontal plane only. First of all you need to enter the calibration mode by sending a 3 byte sequence of 0xF0,0xF5 and then 0xF7 to the command register, these MUST be sent in 3 separate I2C frames, you cannot send them all at once. There MUST be a minimum of 20ms between each I2C frame. The LED will then extinguish and the CMPS11 should now be rotated in all directions on a horizontal plane, if a new maximum for any of the sensors is detected then the LED will flash, when you cannot get any further LED flashes in any direction then exit the calibration mode with a command of 0xF8. Please make sure that the CMPS11 is not located near to ferrous objects as this will distort the magnetic field and induce errors in the reading. While calibrating rotate the compass slowly. Only the X and Y magnetometer axis are calibrated in this mode.

Restoring Factory Calibration
Should you need to revert to the factory calibration then write the following to the command register in 3 separate transactions with 20ms between each transaction: 0x20,0x2A,0x60. These commands must be sent in the correct sequence to restore the calibration, additionally, No other command may be issued in the middle of the sequence. The sequence must be sent to the command register at location 0, which means 3 separate write transactions on the I2C bus. (A write transaction is [start sequence] [I2C address] [register address] [command byte] [stop sequence] then a 20mS delay).

Changing the I2C Bus Address
To change the I2C address of the CMPS11 you must have only one module on the bus. Write the 3 sequence commands in the correct order followed by the address with 100ms between writes. Example; to change the address of a compass currently at 0xC0 (the default shipped address) to 0xC2, write the following to address 0xC0; (0xA0, 0xAA, 0xA5, 0xC2 ) with a 100ms delay after each of the first three bytes. These commands must be sent in the correct sequence to change the I2C address, additionally, No other command may be issued in the middle of the sequence. The sequence must be sent to the command register at location 0, which means 4 separate write transactions on the I2C bus. When done, you should label the CMPS11 with its address, however if you do forget, just power it up without sending any commands. The CMPS11 will flash its address out on the LED, one long flash followed by a number of shorter flashes indicating its address. The flashing is terminated immediately on sending a command the CMPS11.

Address Long Flash Short flashes
Decimal Hex
192 C0 1 0
194 C2 1 1
196 C4 1 2
198 C6 1 3
200 C8 1 4
202 CA 1 5
204 CC 1 6
206 CE 1 7

Take care not to set more than one device to the same address, there will be a bus collision and very unpredictable results.