CMPS10 - Tilt Compensated Compass Module 

Serial mode

Connections

3.6v-5v
Tx
Rx
Mode
Factory use
0v Ground

To use the serial mode of operation the mode pin must be connected to ground.

Communication settings
The Serial mode operates over a link with a default baud rate of 9600 bps (no parity, 2 stop bits) and 3.3v-5v signal levels. 
This is not RS232. Do not connect RS232 to the module, the high RS232 voltages will irreversibly damage the module.

Commands
Below is a table describing commands that can be sent to the CMPS10 and the data it will respond with.

Commands for Serial

Command

Name

Bytes returned

Returned data description

0x11

GET VERSION 1 Software version

0x12

GET ANGLE 8 BIT 1 Angle as a single byte 0-255

0x13

GET ANGLE 16 BIT 2 Angle as two bytes, high byte first 0-3600

0x14

GET PITCH 1 Pitch angle +/- 0-85

0x15

GET ROLL 1 Roll angle +/- 0-85

0x21

GET MAG RAW 6 Raw magnetic data, 16 bit signed: X high, X low, Y high, Y low, Z high, Z low 
0x22 GET ACCEL RAW 6 Raw accelerometer data, 16 bit signed: X high, X low, Y high, Y low, Z high, Z low

0x23

GET ALL 4 angle high, angle low (0-3600), pitch (+/- 0-85), roll  (+/- 0-85)
0x31 CALIBRATE EN1 1 returns ok (0x55)
0x45 CALIBRATE EN2 1 returns ok (0x55)
0x5A CALIBRATE EN3 1 returns ok (0x55)
0x5E CALIBRATE 1 returns ok (0x55)
0x6A RESTORE 1 1 returns ok (0x55)
0x7C RESTORE 2 1 returns ok (0x55)
0x81 RESTORE 3 1 returns ok (0x55)

0xA0

BAUD 19200 1 returns ok (0x55)
0xA1 BAUD 38400 1 returns ok (0x55)

Calibration the CMPS10 
I would recommend evaluating the CMPS10 performance first before implementing this function. Its purpose is to remove offsets caused by constant magnetic sources around the CMPS10. First of all you need to determine North and align the CMPS10 with it, then write a sequence of 3 commands in the correct order with a small delay between bytes, 100ms will be more than adequate. The sequence to enter calibration mode is 0x31,0x45,0x5A, then calibrate the first point by sending 0x5E to the command register, this should also light the LED. The Compass should then be rotated 90 and 0x5E sent to the command register again, repeat for two further 90 rotations and the calibration completes and the LED turns off. Please make sure that the CMPS10 is not located near to ferrous objects as this will distort the magnetic field and induce errors in the reading. 

Restore of factory calibration of the CMPS10
To perform a restore of the factory calibration write a sequence of 3 commands in the correct order with a small delay between bytes, 100ms will be more than adequate. The sequence is 0x6A,0x7C,0x81.

Changing the baud rate
While the CMPS10 operates at a default serial bus baud rate of 9600 you may wish to change this. There are two other baud rates that can be used, for 19200 just send 0xA0 or alternatively for 38400 send 0xA1. Please note that the CMPS10 will always default to its 9600kbps rate after power cycling and after setting a new baud rate the ok response (0x55) will be sent at the newly selected speed.