Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
PQADXL375.cpp
00001 #include "mbed.h" 00002 #include "PQADXL375.h" 00003 00004 ADXL375 :: ADXL375 (I2C &i2c, ALT_ADDRESS_t ALT_ADDRESS) 00005 { 00006 _addr = ALT_ADDRESS; 00007 _i2c = &i2c; 00008 _i2c->frequency(400000); 00009 } 00010 00011 void ADXL375 :: begin() 00012 { 00013 cmd[0] = ADXL375_BW_RATE; 00014 cmd[1] = 0x0F; 00015 _i2c->write(_addr, cmd, 2); 00016 00017 cmd[0] = ADXL375_POWER_CTL; 00018 cmd[1] = 0x08; 00019 _i2c->write(_addr, cmd, 2); 00020 } 00021 00022 bool ADXL375 :: test() 00023 { 00024 cmd[0] = ADXL375_DEVID; 00025 _i2c->write(_addr, cmd, 1); 00026 _i2c->read(_addr, buff, 1); 00027 if (buff[0] == 0xE5) { 00028 return true; 00029 } else { 00030 return false; 00031 } 00032 } 00033 00034 void ADXL375 :: offset(float *high_accel) 00035 { 00036 for(int i = 0; i < 3; i++) { 00037 high_accel_offset[i] = high_accel[i]; 00038 } 00039 } 00040 00041 void ADXL375 :: read(float *high_accel) 00042 { 00043 cmd[0] = ADXL375_DATAX0; 00044 _i2c->write(_addr, cmd, 1); 00045 _i2c->read(_addr, buff, 6); 00046 high_accel[0] = (short)(buff[1] << 8 | buff[0]) * ADXL375_LSB - high_accel_offset[0]; 00047 high_accel[1] = (short)(buff[3] << 8 | buff[2]) * ADXL375_LSB - high_accel_offset[1]; 00048 high_accel[2] = (short)(buff[5] << 8 | buff[4]) * ADXL375_LSB - high_accel_offset[2]; 00049 }
Generated on Sun Jul 17 2022 10:35:44 by
1.7.2