Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ADXL343 support #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 23 additions & 17 deletions elisa3/sensors.c
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ void readAccelXY() {
// reg 0x03: 10 bits output value Y MSB
// reg 0x04: 10 bits output value Z LSB
// reg 0x05: 10 bits output value Z MSB
// The sensitivity is 64 LSB/g.

i2c_start(accelAddress+I2C_WRITE); // set device address and write mode
i2c_write(0x00); // sends address to read from (X LSB)
Expand Down Expand Up @@ -306,6 +307,7 @@ void readAccelXY() {
// reg 0x35: 10 bits output value Y MSB
// reg 0x36: 10 bits output value Z LSB
// reg 0x37: 10 bits output value Z MSB
// The sensitivity is 256 LSB/g so scale the values to be compatible with the MMA7455.

i2c_start(accelAddress+I2C_WRITE); // set device address and write mode
i2c_write(0x32); // sends address to read from (X LSB)
Expand All @@ -318,11 +320,11 @@ void readAccelXY() {
i2c_stop(); // set stop conditon = release bus

if(startCalibration) { // if performing the calibration, then return the raw values
accX = ((signed int)buff[1]<<8)|buff[0]; // X axis
accY = ((signed int)buff[3]<<8)|buff[2]; // Y axis
accX = (((int16_t)buff[1])<<6)|(((uint8_t)buff[0])>>2); // X axis
accY = (((int16_t)buff[3])<<6)|(((uint8_t)buff[2])>>2); // Y axis
} else { // else return the calibrated values
accX = (((signed int)buff[1]<<8)|buff[0])-accOffsetX; // X axis
accY = (((signed int)buff[3]<<8)|buff[2])-accOffsetY; // Y axis
accX = ((((int16_t)buff[1])<<6)|(((uint8_t)buff[0])>>2))-accOffsetX; // X axis
accY = ((((int16_t)buff[3])<<6)|(((uint8_t)buff[2])>>2))-accOffsetY; // Y axis
}

} else {
Expand All @@ -348,6 +350,7 @@ void readAccelXYZ() {
// reg 0x03: 10 bits output value Y MSB
// reg 0x04: 10 bits output value Z LSB
// reg 0x05: 10 bits output value Z MSB
// The sensitivity is 64 LSB/g.

i2c_start(accelAddress+I2C_WRITE); // set device address and write mode
i2c_write(0x00); // sends address to read from (X LSB)
Expand Down Expand Up @@ -378,6 +381,7 @@ void readAccelXYZ() {
// reg 0x35: 10 bits output value Y MSB
// reg 0x36: 10 bits output value Z LSB
// reg 0x37: 10 bits output value Z MSB
// The sensitivity is 256 LSB/g so scale the values to be compatible with the MMA7455.

i2c_start(accelAddress+I2C_WRITE); // set device address and write mode
i2c_write(0x32); // sends address to read from (X LSB)
Expand All @@ -387,16 +391,16 @@ void readAccelXYZ() {
buff[i] = i2c_readAck(); // read one byte at a time
}
buff[i] = i2c_readNak(); // read last byte sending NACK
i2c_stop(); // set stop conditon = release bus
i2c_stop(); // set stop conditon = release bus

if(startCalibration) { // if performing the calibration, then return the raw values
accX = ((signed int)buff[1]<<8)|buff[0]; // X axis
accY = ((signed int)buff[3]<<8)|buff[2]; // Y axis
accZ = ((signed int)buff[5]<<8)|buff[4]; // Z axis
accX = (((int16_t)buff[1])<<6)|(((uint8_t)buff[0])>>2); // X axis
accY = (((int16_t)buff[3])<<6)|(((uint8_t)buff[2])>>2); // Y axis
accZ = (((int16_t)buff[5])<<6)|(((uint8_t)buff[4])>>2); // Z axis
} else { // else return the calibrated values
accX = (((signed int)buff[1]<<8)|buff[0])-accOffsetX; // X axis
accY = (((signed int)buff[3]<<8)|buff[2])-accOffsetY; // Y axis
accZ = (((signed int)buff[5]<<8)|buff[4]); // Z axis
accX = ((((int16_t)buff[1])<<6)|(((uint8_t)buff[0])>>2))-accOffsetX; // X axis
accY = ((((int16_t)buff[3])<<6)|(((uint8_t)buff[2])>>2))-accOffsetY; // Y axis
accZ = (((int16_t)buff[5])<<6)|(((uint8_t)buff[4])>>2); // Z axis
}

} else {
Expand All @@ -422,6 +426,7 @@ void readAccelXYZ_1() {
// reg 0x03: 10 bits output value Y MSB
// reg 0x04: 10 bits output value Z LSB
// reg 0x05: 10 bits output value Z MSB
// The sensitivity is 64 LSB/g.

i2c_start(accelAddress+I2C_WRITE); // set device address and write mode
i2c_write(0x00); // sends address to read from (X LSB)
Expand All @@ -441,6 +446,7 @@ void readAccelXYZ_1() {
// reg 0x35: 10 bits output value Y MSB
// reg 0x36: 10 bits output value Z LSB
// reg 0x37: 10 bits output value Z MSB
// The sensitivity is 256 LSB/g so scale the values to be compatible with the MMA7455.

i2c_start(accelAddress+I2C_WRITE); // set device address and write mode
i2c_write(0x32); // sends address to read from (X LSB)
Expand Down Expand Up @@ -492,13 +498,13 @@ void readAccelXYZ_2() {
i2c_stop(); // set stop conditon = release bus

if(startCalibration) { // if performing the calibration, then return the raw values
accX = ((signed int)accBuff[1]<<8)|accBuff[0]; // X axis
accY = ((signed int)accBuff[3]<<8)|accBuff[2]; // Y axis
accZ = ((signed int)accBuff[5]<<8)|accBuff[4]; // Z axis
accX = (((int16_t)accBuff[1])<<6)|(((uint8_t)accBuff[0])>>2); // X axis
accY = (((int16_t)accBuff[3])<<6)|(((uint8_t)accBuff[2])>>2); // Y axis
accZ = (((int16_t)accBuff[5])<<6)|(((uint8_t)accBuff[4])>>2); // Z axis
} else { // else return the calibrated values
accX = (((signed int)accBuff[1]<<8)|accBuff[0])-accOffsetX; // X axis
accY = (((signed int)accBuff[3]<<8)|accBuff[2])-accOffsetY; // Y axis
accZ = (((signed int)accBuff[5]<<8)|accBuff[4]); // Z axis
accX = ((((int16_t)accBuff[1])<<6)|(((uint8_t)accBuff[0])>>2))-accOffsetX; // X axis
accY = ((((int16_t)accBuff[3])<<6)|(((uint8_t)accBuff[2])>>2))-accOffsetY; // Y axis
accZ = (((int16_t)accBuff[5])<<6)|(((uint8_t)accBuff[4])>>2); // Z axis
}

} else {
Expand Down