Terry
- 4th August 2015, 00:58
Hi,
I am currently very unsuccessful at communicating via I2C to an ADXL345 Accelerometer. The code and circuit appear to both very simple, but the response I get back makes no sense. Here are the details:
The ADXL345 CS is set high (3.3v) to put the device into I2C mode.
The ADXL345 Alt Address is set low (0v)
I have pull-up resistors on the Clock and SDA lines.
The chip is a PIC18F26K22 running at +3.3v
Below is the I2C code:
I2Cread ADXL345_SDA,ADXL345_SCL, $A7, $00, [X0] ' Read Device ID
serout2 RS232_TX, 6, ["ID: ",bin8 X0,13,10] ' The result should be 11100101 but is 00010000 like all other read results.
I2CWRITE ADXL345_SDA,ADXL345_SCL, $A6, $2D, [8] ' Put into Run Mode
pauseus 5
Main_I2C:
I2Cread ADXL345_SDA,ADXL345_SCL, $A7, $32, [X0,X1,Y0,Y1,Z0,Z1] ' Read accelerometer data
serout2 RS232_TX, 6, ["X: ",dec X0,",",dec X1]
serout2 RS232_TX, 6, [" Y: ",dec Y0,",",dec Y1]
serout2 RS232_TX, 6, [" Z: ",dec Z0,",",dec Z1,13,10]
pause 100
Goto Main_I2C
When reading back any byte the answer is always 16 or 00010000, which implies that I have something fundamentally configured wrong.
Any suggestions is greatly appreciated.
Terry
I am currently very unsuccessful at communicating via I2C to an ADXL345 Accelerometer. The code and circuit appear to both very simple, but the response I get back makes no sense. Here are the details:
The ADXL345 CS is set high (3.3v) to put the device into I2C mode.
The ADXL345 Alt Address is set low (0v)
I have pull-up resistors on the Clock and SDA lines.
The chip is a PIC18F26K22 running at +3.3v
Below is the I2C code:
I2Cread ADXL345_SDA,ADXL345_SCL, $A7, $00, [X0] ' Read Device ID
serout2 RS232_TX, 6, ["ID: ",bin8 X0,13,10] ' The result should be 11100101 but is 00010000 like all other read results.
I2CWRITE ADXL345_SDA,ADXL345_SCL, $A6, $2D, [8] ' Put into Run Mode
pauseus 5
Main_I2C:
I2Cread ADXL345_SDA,ADXL345_SCL, $A7, $32, [X0,X1,Y0,Y1,Z0,Z1] ' Read accelerometer data
serout2 RS232_TX, 6, ["X: ",dec X0,",",dec X1]
serout2 RS232_TX, 6, [" Y: ",dec Y0,",",dec Y1]
serout2 RS232_TX, 6, [" Z: ",dec Z0,",",dec Z1,13,10]
pause 100
Goto Main_I2C
When reading back any byte the answer is always 16 or 00010000, which implies that I have something fundamentally configured wrong.
Any suggestions is greatly appreciated.
Terry