AnsweredAssumed Answered

ADXL345 linux driver axes reading

Question asked by Alberto on Dec 19, 2016
Latest reply on Dec 22, 2016 by Alberto

Hi I am trying to modify the adxl345_get_triple() function of the adxl34x.c linux driver

https://wiki.analog.com/resources/tools-software/linux-drivers/input-misc/adxl345

to store the three axes values in a char buffer instead of a short buffer, so i am trrying to replace the next function

 

/* Get the adxl345 axis data */

static void adxl345_get_triple(struct adxl345 *ac, struct axis_triple *axis)

{

short buf[3];

  

ac->bops->read_block(ac->dev, DATAX0, DATAZ1 - DATAX0 + 1, buf);

  

ac->saved.x = (s32)buf[0];

axis->x = ac->saved.x;

  

ac->saved.y = (s32)buf[1];

axis->y = ac->saved.y;

  

ac->saved.z = (s32)buf[2];

axis->z = ac->saved.z;

}

 

with the next function below:

 

static void adxl345_get_triple(struct adxl345 *ac, struct axis_triple *axis)

{

char buffer[6];

  

ac->bops->read_block(ac->dev, DATAX0, DATAZ1 - DATAX0 + 1, buffer);

  

ac->saved.x = (int)(buffer[1] << 8) | (int)buffer[0];

axis->x = ac->saved.x;

ac->saved.y = (int)(buffer[3] << 8) | (int)buffer[2];

axis->y = ac->saved.y;

ac->saved.z = (int)(buffer[5] << 8) | (int)buffer[4];

axis->z = ac->saved.z;

  

}

When i am using short buffer[] i can read the axes values in the right way but when i am using char buffer[] i am obtaining wrong values. Any idea about the reason ?

 

Thanks

Outcomes