Here is the datasheet I followed: STK8321 SENSORTEK | C966924 - LCSC Electronics
We are trying the following code:
#include <Wire.h>
int ADXLAddress = 0x0F; // Device address in which is also included the 8th bit for selecting the mode, read in this case.
#define X_Axis_Register_DATAX0 0x03 // Hexadecima address for the DATAX0 internal register.
#define X_Axis_Register_DATAX1 0x02 // Hexadecima address for the DATAX1 internal register.
#define Y_Axis_Register_DATAX0 0x05 // Hexadecima address for the DATAX0 internal register.
#define Y_Axis_Register_DATAX1 0x04 // Hexadecima address for the DATAX0 internal register.
#define Z_Axis_Register_DATAX0 0x07 // Hexadecima address for the DATAX0 internal register.
#define Z_Axis_Register_DATAX1 0x06 // Hexadecima address for the DATAX0 internal register.
int X0, X1, X_out;
int Y0, Y1, Y_out;
int Z0, Z1, Z_out;
void setup() {
Wire.begin(); // Initiate the Wire library
Serial.begin(115200);
Wire.beginTransmission(ADXLAddress);
Wire.endTransmission();
}
void loop() {
Wire.beginTransmission(ADXLAddress); // Begin transmission to the Sensor
//Ask the particular registers for data
Wire.write(X_Axis_Register_DATAX0);
Wire.write(X_Axis_Register_DATAX1);
Wire.endTransmission(); // Ends the transmission and transmits the data from the two registers
Wire.requestFrom(ADXLAddress, 2); // Request the transmitted two bytes from the two registers
if (Wire.available() <= 2) { //
X0 = Wire.read(); // Reads the data from the register
X1 = Wire.read();
}
Serial.print("\n X0= "); Serial.print(X0); Serial.print(" X1= "); Serial.print(X1);
delay(100);
Wire.beginTransmission(ADXLAddress); // Begin transmission to the Sensor
Wire.write(Y_Axis_Register_DATAX0);
Wire.write(Y_Axis_Register_DATAX1);
Wire.endTransmission(); // Ends the transmission and transmits the data from the two registers
Wire.requestFrom(ADXLAddress, 2); // Request the transmitted two bytes from the two registers
if (Wire.available() <= 2) { //
Y0 = Wire.read(); // Reads the data from the register
Y1 = Wire.read();
}
Serial.print(" Y0= "); Serial.print(Y0); Serial.print(" Y1= "); Serial.print(Y1);
delay(100);
Wire.beginTransmission(ADXLAddress); // Begin transmission to the Sensor
Wire.write(Z_Axis_Register_DATAX0);
Wire.write(Z_Axis_Register_DATAX1);
Wire.endTransmission(); // Ends the transmission and transmits the data from the two registers
Wire.requestFrom(ADXLAddress, 6); // Request the transmitted two bytes from the two registers
if (Wire.available() <= 6) { //
Z0 = Wire.read(); // Reads the data from the register
Z1 = Wire.read();
}
Serial.print(" Z0= "); Serial.print(Z0); Serial.print(" Z1= "); Serial.print(Z1);
delay(200);
}
Please help us to get the final X, Y, and Z.
Raw values of X and Y are somewhat correct, but Z always shows - 0.
Also, we are not able to calculate correctly X, Y, and Z to get the final G-force value.
Main point of datasheet :
The acceleration data of STK8321 is 12 bits and is given in two's complement format. The MSB in each axis will be stored in register XOUT2/YOUT2/ZOUT2 (0x03, 0x05, 0x07) individually, and the LSB will be stored in register XOUT1/YOUT1/ZOUT1 (0x02, 0x04, 0x06) individually. The NEW_X/NEW_Y/NEW_Z bit in register XOUT1/YOUT1/ZOUT1 (0x02, 0x04, 0x06) is used for new data flag, and it will be set to 1 if the data is updated, and reset if either the corresponding MSB or LSB is read. Reading the acceleration data registers shall always start with the LSB part due to the data protection function. When data protection function is enabled, the content of an MSB register will be updated by reading the corresponding LSB register.

