westaust55
Moderator
Hi all,
I am having problems calibrating a CMPS03 compass module using the i2c method (using the manual/switch method tonight works) but want so try and sort out what is wrong in the/my i2c method.
The program to calibrate first correctly reads the firmware revision and heading so the basic i2c comms is working.
To calibrate, one has to write the value 255 to register 15 once for each of the four cardinal points with the compass alighed to each of the 4 directions.
The value in register is supposed to be cleared in a fraction of a second but appears to be locking / holding as 255.
I tried writing a different value but it still read back 255 suggest no actual response from the register.
Before I write to the register 15, I DO read back a value of zero (0) from register 15 suggesting the i2c comms is working and can see the register.
I see this value change from 0 to 255 on read back after writing a value to register 15.
Extracted below are some of the pertinent lines from the PICAXEcode I am using.
Its getting late here and maybe I am overlooking something obvious.
Any help would be greatly appreciated.
I am having problems calibrating a CMPS03 compass module using the i2c method (using the manual/switch method tonight works) but want so try and sort out what is wrong in the/my i2c method.
The program to calibrate first correctly reads the firmware revision and heading so the basic i2c comms is working.
To calibrate, one has to write the value 255 to register 15 once for each of the four cardinal points with the compass alighed to each of the 4 directions.
The value in register is supposed to be cleared in a fraction of a second but appears to be locking / holding as 255.
I tried writing a different value but it still read back 255 suggest no actual response from the register.
Before I write to the register 15, I DO read back a value of zero (0) from register 15 suggesting the i2c comms is working and can see the register.
I see this value change from 0 to 255 on read back after writing a value to register 15.
Extracted below are some of the pertinent lines from the PICAXEcode I am using.
Code:
SYMBOL cmps03_0 = %11000000 ; CMPS03 COMPASS MODULE address = $C0
; many other SYMBOL statements here are omitted
Main: HI2CSETUP i2cmaster, cmps03_0, i2cslow, i2cbyte
PAUSE 100
HI2CIN 0, (b9,b10, b19,b18) ; reads revision, 1-byte and 2-byte values correctly
SEROUT lcd_data, N2400, ("Revision ", #b9) ; all the read data is displayed correctly
PAUSE 10
SEROUT lcd_data, N2400, (lcdcmand,lcdline3)
PAUSE 10
SEROUT lcd_data, N2400, ("angle ", #b10)
PAUSE 10
SEROUT lcd_data, N2400, (lcdcmand,lcdline4)
PAUSE 10
SEROUT lcd_data, N2400, ("angle ", #w9) ; w9 = b19 (msb) and b18 (lsb)
PAUSE 2000
HI2CIN 15, (b9) ; read value in register 15 into b9 : it does shows up as zero (0) here at power up
debug ; displays all the PICAXE variables on PC screen
:
:
:
DO ; keypad is read by interrupt routine which is working
PAUSE 10
LOOP WHILE keyval =0 ; wait for a keypress on keypad - this is one
of 4 such loops, to handle the four cardinal directions for calibration
pause 5
HI2COUT 15, (255) ; write a calibration command/action to CMPS03 register 15
pause 100
' on the CMPS03, pin 5 should go low but stays high = no calibration started
HI2CIN 15, (b9) ; read back the value in register 15 = always comes back
; with 255 even if a value like 170 written to register 15.
; (suggesting that I am not getting response back on i2c )
; but seems to read value from reg. 15 correctly at start
debug
pause 1000
END
Any help would be greatly appreciated.