AnsweredAssumed Answered

ADX345 read output problem

Question asked by renanbs on Mar 17, 2014
Latest reply on Mar 21, 2014 by neilzhao

I'm having problem getting the output from this ADXL345.

I'm using a LPC1769.

This is part of my code:


void adxl345_setDataRate (int rate)
    uint8_t registerContents = i2c_read_reg (XL345_ALT_ADDR, XL345_BW_RATE);
    registerContents &= 0x10;
    registerContents |= rate;
    i2c_write_reg (XL345_ALT_ADDR, XL345_BW_RATE, registerContents);

void adxl345_setPowerControl (int settings)
    i2c_write_reg (XL345_ALT_ADDR, XL345_POWER_CTL, settings);

void adxl345_setDataFormatControl (int settings)
    i2c_write_reg (XL345_ALT_ADDR, XL345_DATA_FORMAT, settings);
void adxl345_init ()
    adxl345_setPowerControl (0x00);
    //Full resolution, +/-16g, 4mg/LSB.
    adxl345_setDataFormatControl (0x0B);
    //200Hz data rate.
    adxl345_setDataRate (XL345_RATE_200);
    //Measurement mode.
    adxl345_setPowerControl (0x08);
void adxl345_read_axes (uint16_t *x, uint16_t *y, uint16_t *z)
    uint8_t buff[6];
     i2c_read_multi_reg (XL345_ALT_ADDR, XL345_DATAX0, buff, 6);

    *x = (((uint16_t) buff[1]) << 8) | (uint16_t)buff [0];
    *y = (((uint16_t) buff[3]) << 8) | (uint16_t)buff [2];
    *z = (((uint16_t) buff[5]) << 8) | (uint16_t)buff [4];


And this is the function I use to print data over serial:

uint16_t x;
uint16_t y;
uint16_t z;
adxl345_read_axes (&x, &y, &z);
printf ("[%04d], [%04d], [%04d]\n", (signed char)x, (signed char)y , (signed char)z);


I'm getting this kind of output:

[0022], [-025], [-065]


Can someone help me?