Hi all,

I am using an 18F2820 clocked at 20 MHz, connected to an ADXL345 accelerometer and reading it as fast as I can and pushing the data out on the USART and looping back for more data. Code is as below.

My question is this... Why does the output go to fixed values when I try to pass out on the serial bus all of the axes (x, Y, and Z), but if I only try to output maybe one or two axes worth of data it becomes real numbers reflecting the orientation of the sensor???

Code:
define OSC 20
DEFINE HSER_BAUD 38400
DEFINE HSER_CLROERR 1
DEFINE HSER_RCSTA 90h
DEFINE HSER_TXSTA 24h

Include "modedefs.bas"
Serial_out  var portc.6
i2cSDA      VAR PORTC.4
i2cSCL      VAR PORTC.3
accx        VAR byte
accx2       var byte
accy        VAR byte
accy2       var byte
accz        VAR byte
accz2       var byte

I2CWRITE i2cSDA,i2cSCL, $a6, $2d, [0]  'accelerometer
pauseus 5
i2CWRITE i2cSDA,i2cSCL, $a6, $2d, [16] 'accelerometer
pauseus 5
I2CWRITE i2cSDA,i2cSCL, $a6, $2d, [8]  'accelerometer
pauseus 5
I2CWRITE i2cSDA,i2cSCL, $a6, $31, [11]  'accelerometer
pauseus 5
I2CWRITE i2cSDA,i2cSCL, $a6, $2c, [$f] 'set accelerometer sampling frequency
porta   =       %00000000
portc   =       %00000000
adcon1  =       %00000111
CMCON   =       %00000111
trisa   =       %00000000
trisc   =       %00000000
led     var     porta.0

pauseus 10

main:
i2cread i2cSDA,i2cSCL,$a7,50,[accx,accx2,accy,accy2,accz,accz2];,error;
pauseus 10
hserout [13,10,hex accx," ",hex accx2," ",hex accy," ",hex accy2," "]
hserout [13,10,hex accx]
goto main

error:
high led
hserout[13,10,"Error"]
goto error
Output is as follows:

10
10 10 10 10
10
10 10 10 10
10
10 10 10 10
10
10 10 10 10
10
10 10 10 10
10
10 10 10 10
10
10 10 10 10

But if I drop the HSEROUT[13,10,HEX accx," ",HEX accx2," ",HEX accy," ",HEX accy2," "] line, the output reverts to variable output as follows...

5E
84
6A
50
90
6A
20
C0
6A
A4
D0
DA
C0
68
DE


Something odd going on inside the chip or am I missing something daft (again!)?

Also, not sure if this is relevant, but if I enable the redirect on fail 'error' at the end of the I2CREAD command, it jumps out of the loop and switches on the LED and goes into the infinite loop 'Error'... Not sure why it's giving this error when it is acutally receiving data from the sensor as demonstrated above.

Cheers all

- Jimbo -