Code:
X0 var byte
X1 var byte
Y0 var byte
Y1 var byte
Z0 var byte
Z1 var byte
ID var byte
Mode var byte
high ADXL345_CS ' Set high to put unit into I2C mode
pause 1 ' Added to insure no R/W issue
low ADXL345_SDO ' Set low to put unit addresses to $A6, $A7
pause 1 ' Added to insure no R/W issue
serout2 RS232_TX, 6, [13,13,10,"Start of Test Program. "]
'Initialize ADXL345
I2Cread ADXL345_SDA,ADXL345_SCL, $A7,$00, [ID], I2C_error 'read Device ID
serout2 RS232_TX, 6, ["Device ID: $", hex2 ID,13,10] ' Value should be $E5
I2CWRITE ADXL345_SDA,ADXL345_SCL, $A6, $31, [$0B], I2C_error '+/-16g, 13-bit mode
pauseus 5
I2CWRITE ADXL345_SDA,ADXL345_SCL, $A6, $2D, [$08], I2C_error 'Start Measurement or put into Run Mode
pauseus 5
I2Cread ADXL345_SDA,ADXL345_SCL, $A7, $2D, [Mode],I2C_error ' Confirm mode setting
serout2 RS232_TX, 6, ["Mode: ",hex Mode,13,10] ' value should be 8
pauseus 5
Main_I2C: ' Main Loop
I2Cread ADXL345_SDA,ADXL345_SCL, $A7, $32, [X0,X1,Y0,Y1,Z0,Z1], I2C_error
serout2 RS232_TX, 6, ["X,Y,Z, ", Sdec 256*X1+X0,", ",Sdec 256*Y1+Y0,", ",Sdec 256*Z1+Z0,13,10]
pause 100
Goto Main_I2C
I2C_Error:
serout2 RS232_TX, 6, ["I2C Comm Error",13,10]
stop
Bookmarks