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;
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;
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
// Turn on measurement mode
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:
// Reset CS pin
// 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
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