LIS3DH / STMicroelectronics / MEMS motion sensor, 3-axis accelerometer library
Diff: LIS3DH.h
- Revision:
- 5:725df775f168
- Parent:
- 4:64dac49da306
- Child:
- 6:e269772dad35
--- a/LIS3DH.h Sat Dec 27 07:43:57 2014 +0000 +++ b/LIS3DH.h Tue Feb 24 12:21:54 2015 +0000 @@ -3,11 +3,11 @@ * LIS3DH MEMS motion sensor: 3-axis "nano" accelerometer, made by STMicroelectronics * http://www.st-japan.co.jp/web/jp/catalog/sense_power/FM89/SC444/PF250725 * - * Copyright (c) 2014 Kenji Arai / JH1PJL + * Copyright (c) 2014,'15 Kenji Arai / JH1PJL * http://www.page.sannet.ne.jp/kenjia/index.html * http://mbed.org/users/kenjiArai/ * Created: July 14th, 2014 - * Revised: December 27th, 2014 + * Revised: Feburary 24th, 2015 * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE @@ -23,13 +23,12 @@ // LIS3DH Address // 7bit address = 0b001100x(0x18 or 0x19 depends on SA0/SDO) -// -> 8bit = 0b001100x0(0x30,0x32) -> 0x31,0x33(Read) or 0x30,0x32(Write) -#define LIS3DH_G_CHIP_ADDR 0x30 // SA0(=SDO pin) = Ground -#define LIS3DH_V_CHIP_ADDR 0x32 // SA0(=SDO pin) = Vdd +#define LIS3DH_G_CHIP_ADDR (0x18 << 1) // SA0(=SDO pin) = Ground +#define LIS3DH_V_CHIP_ADDR (0x19 << 1) // SA0(=SDO pin) = Vdd // LIS3DH ID -#define I_AM_LIS3DH 0x33 +#define I_AM_LIS3DH 0x33 // Register's definition #define LIS3DH_STATUS_REG_AUX 0x07 @@ -147,27 +146,43 @@ */ LIS3DH(PinName p_sda, PinName p_scl, uint8_t addr, uint8_t data_rate, uint8_t fullscale); - + + /** Configure data pin + * @param data SDA and SCL pins + * @param device address LIS3DH(SA0=0 or 1), LIS3DH_G_CHIP_ADDR or LIS3DH_V_CHIP_ADDR + * @default output data rate selection = 50Hz + * @default full scale selection = +/-8g + */ + LIS3DH(PinName p_sda, PinName p_scl, uint8_t addr); + /** Configure data pin (with other devices on I2C line) * @param I2C previous definition * @param other parameters -> please see LIS3DH(PinName p_sda, PinName p_scl,...) */ LIS3DH(I2C& p_i2c, uint8_t addr, uint8_t data_rate, uint8_t fullscale); + + /** Configure data pin (with other devices on I2C line) + * @param I2C previous definition + * @param other parameters -> please see LIS3DH(PinName p_sda, PinName p_scl,...) + * @default output data rate selection = 50Hz + * @default full scale selection = +/-8g + */ + LIS3DH(I2C& p_i2c, uint8_t addr); /** Read a float type data from acc - * @param float type of three arry's address, e.g. float dt[3]; + * @param float type of three arry's address, e.g. float dt_usr[3]; * @return acc motion data unit: m/s/s(m/s2) - * @return dt[0]->x, dt[1]->y, dt[2]->z + * @return dt_usr[0]->x, dt_usr[1]->y, dt_usr[2]->z */ - void read_data(float *dt); + void read_data(float *dt_usr); /** Read a float type data from acc - * @param float type of three arry's address, e.g. float dt[3]; + * @param float type of three arry's address, e.g. float dt_usr[3]; * @return acc motion data unit: mg - * @return dt[0]->x, dt[1]->y, dt[2]->z + * @return dt_usr[0]->x, dt_usr[1]->y, dt_usr[2]->z */ - void read_mg_data(float *dt); + void read_mg_data(float *dt_usr); /** Read a acc ID number * @param none @@ -204,11 +219,11 @@ void initialize(uint8_t, uint8_t, uint8_t); void read_reg_data(char *data); - I2C i2c; + I2C _i2c; private: - float fs_factor; // full scale factor - char dbf[2]; // working buffer + float fs_factor; // full scale factor + char dt[2]; // working buffer uint8_t acc_addr; // acc sensor address uint8_t acc_id; // acc ID uint8_t acc_ready; // acc is on I2C line = 1, not = 0