AnsweredAssumed Answered

ADXL362Z Data Output

Question asked by usidedowner on Jan 11, 2017

I'm currently using the ADXL362Z with an STM32, using it as a movement tracker.


I have adapted the Arduino code that is supplied on the AD site for the sensor, but I'm having some trouble with the output format of the data. I was having the same problem that this user was having, so I followed the instructions given there. I saved the 12-bit output as a string, then used this code to convert into a signed decimal value.


int16_t binTwosComplementToSignedDecimal(char binary[],int significantBits)
int power = pow(2,significantBits-1);
int16_t sum = 0;
int i;

for (i=0; i<significantBits; ++i)
if ( i==0 && binary[i]!='0')
sum = power * -1;
sum += (binary[i]-'0')*power; //The -0 is needed
power /= 2;

return sum;


Is this the right thing to do here? I know there's something here that I'm missing.

The issue I'm having is that the data is not coming out as I expected. The values are all positive, even though I've saved the output of binTwosComplementToSignedDecimal as a signed int. Also, the data does not seem to reflect the actual activity of the sensor itself. Perhaps somebody here could shed some light on this for me please?


The "setup code" for the sensor I'm using is:




// Soft reset


// Selects 8g measurement mode
WriteByte_ADXL(0x2C, 0x83);

// Turn on measurement mode
WriteByte_ADXL(0x2D, 0x02);


for(int i = 0; i<3000;i++)

// Four identical values were being output.
// Delay inserted here to try and eliminate this replication.



Additionally, the code I'm using to log the data is:


int16_t readXYZData()
// Reset CS pin
GPIO_ResetBits(GPIOA, GPIO_Pin_4);

// Send read register instruction

// Start at XData Register

// A burst read of all three axes required to ensure all same sample time
XData = SendByte_ADXL(0x00);
XData = XData + (SendByte_ADXL(0x00)<<8);//Shift left
XData = binTwosComplementToSignedDecimal(XData,12);

YData = SendByte_ADXL(0x00);
YData = YData + (SendByte_ADXL(0x00)<<8); //Shift left
YData = binTwosComplementToSignedDecimal(YData,12);

ZData = SendByte_ADXL(0x00);
ZData = ZData + (SendByte_ADXL(0x00)<<8); //Shift left
ZData = binTwosComplementToSignedDecimal(ZData,12);

// Deselect the ACCEL: Chip Select high
GPIO_SetBits(GPIOA, GPIO_Pin_4);



IF there is something else that would be helpful to include, please just let me know!




Edit: I've added a snapshot of some of the data output