by Gort » Sun Aug 30, 2009 2:31 am
by Gort
Sun Aug 30, 2009 2:31 am
Thanks I-Bot, here is my code so far. Now the issue is that I am alwas getting a value of 10 for the compass.
Main:
I2cAddr = &H42 'Default address of compass
I2cReg = 1 'Register containing Compass bearing as a single Byte
GOSUB WriteA
DELAY 100
GOSUB ReadBearing
PRINT &HFE,&H01
PRINT "heading = "
PRINT FORMAT (I2cDataWord, DEC)
DELAY 4000
GOTO Main
WriteA:
GOSUB I2cStart
I2cBuf = I2cAddr
GOSUB I2cOutByte
I2cBuf = "A"
GOSUB I2cOutByte
PRINT &HFE,&H01
PRINT "Done with WriteA"
DELAY 1000
RETURN
ReadBearing:
GOSUB I2cStart
I2cBuf = I2cAddr OR 1 ' or in the read bit to address
GOSUB I2cOutByte
GOSUB I2cInByte
I2cDataWord = I2cBuf * 256
GOSUB I2cInByte
I2cDataWord = I2cDataWord + I2cData
GOSUB I2cStop
PRINT &HFE,&H01
PRINT "Done with ReadBearing"
PRINT FORMAT (I2cData, DEC)
DELAY 1000
RETURN
Thanks I-Bot, here is my code so far. Now the issue is that I am alwas getting a value of 10 for the compass.
Main:
I2cAddr = &H42 'Default address of compass
I2cReg = 1 'Register containing Compass bearing as a single Byte
GOSUB WriteA
DELAY 100
GOSUB ReadBearing
PRINT &HFE,&H01
PRINT "heading = "
PRINT FORMAT (I2cDataWord, DEC)
DELAY 4000
GOTO Main
WriteA:
GOSUB I2cStart
I2cBuf = I2cAddr
GOSUB I2cOutByte
I2cBuf = "A"
GOSUB I2cOutByte
PRINT &HFE,&H01
PRINT "Done with WriteA"
DELAY 1000
RETURN
ReadBearing:
GOSUB I2cStart
I2cBuf = I2cAddr OR 1 ' or in the read bit to address
GOSUB I2cOutByte
GOSUB I2cInByte
I2cDataWord = I2cBuf * 256
GOSUB I2cInByte
I2cDataWord = I2cDataWord + I2cData
GOSUB I2cStop
PRINT &HFE,&H01
PRINT "Done with ReadBearing"
PRINT FORMAT (I2cData, DEC)
DELAY 1000
RETURN