L3GD20 & L3G4200D / STMicroelectronics / MEMS motion sensor, three-axis gyroscope library
Dependents: GR-PEACH_test_wo_rtos GR-PEACH_test_on_rtos_works_well
Diff: L3GD20.h
- Revision:
- 5:81fc00bd76fe
- Parent:
- 4:7d0cec583aa3
- Child:
- 6:451811697299
--- a/L3GD20.h Sat Dec 27 07:43:49 2014 +0000 +++ b/L3GD20.h Tue Feb 24 12:21:41 2015 +0000 @@ -7,11 +7,11 @@ * http://www.st.com/web/catalog/sense_power/FM89/SC1288 * /PF250373?sc=internet/analog/product/250373.jsp * - * 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 13th, 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 @@ -27,19 +27,17 @@ // L3G4200DMEMS Address // 7bit address = 0b110100x(0x68 or 0x69 depends on SA0/SDO) -// -> 8bit = 0b1101000x0(0xd0,0xd2) -> 0xd1,0xd3(Read) or 0xd0,0xd2(Write) -#define L3G4200D_G_CHIP_ADDR 0xd0 // SA0(=SDO pin) = Ground -#define L3G4200D_V_CHIP_ADDR 0xd2 // SA0(=SDO pin) = Vdd +#define L3G4200D_G_CHIP_ADDR (0x68 << 1) // SA0(=SDO pin) = Ground +#define L3G4200D_V_CHIP_ADDR (0x69 << 1) // SA0(=SDO pin) = Vdd // L3GD20MEMS Address // 7bit address = 0b110101x(0x6a or 0x6b depends on SA0/SDO) -// -> 8bit = 0b1101001x0(0xd4,0xd6) -> 0xd5,0xd7(Read) or 0xd4,0xd6(Write) -#define L3GD20_G_CHIP_ADDR 0xd4 // SA0(=SDO pin) = Ground -#define L3GD20_V_CHIP_ADDR 0xd6 // SA0(=SDO pin) = Vdd +#define L3GD20_G_CHIP_ADDR (0x6a << 1) // SA0(=SDO pin) = Ground +#define L3GD20_V_CHIP_ADDR (0x6b << 1) // SA0(=SDO pin) = Vdd // L3G4200DMEMS ID -#define I_AM_L3G4200D 0xd3 +#define I_AM_L3G4200D 0xd3 // L3GD20MEMS ID -#define I_AM_L3GD20 0xd4 +#define I_AM_L3GD20 0xd4 // Register's definition #define L3GX_WHO_AM_I 0x0f @@ -146,6 +144,16 @@ */ L3GX_GYRO(PinName p_sda, PinName p_scl, uint8_t addr, uint8_t data_rate, uint8_t bandwidth, uint8_t fullscale); + + /** Configure data pin + * @param data SDA and SCL pins + * @param device address L3G4200D(SA0=0 or 1) or L3GD20(SA0=0 or 1) + * @param ->L3G4200D_G_CHIP_ADDR to L3GD20_V_CHIP_ADDR + * @default output data rate selection = DR_100HZ/DR_95HZ + * @default bandwidth selection = BW_HI + * @default full scale selection = FS_250DPS + */ + L3GX_GYRO(PinName p_sda, PinName p_scl, uint8_t addr); /** Configure data pin (with other devices on I2C line) * @param I2C previous definition @@ -154,6 +162,15 @@ L3GX_GYRO(I2C& p_i2c, uint8_t addr, uint8_t data_rate, uint8_t bandwidth, uint8_t fullscale); + /** Configure data pin (with other devices on I2C line) + * @param I2C previous definition + * @param other parameters -> please see L3GX_GYRO(PinName p_sda, PinName p_scl,...) + * @default output data rate selection = DR_100HZ/DR_95HZ + * @default bandwidth selection = BW_HI + * @default full scale selection = FS_250DPS + */ + L3GX_GYRO(I2C& p_i2c, uint8_t addr); + /** Read a tow's complemet type data from Gyro * @param none * @return temperature unit:degreeC(Celsius) @@ -161,11 +178,11 @@ int8_t read_temp(); /** Read a float type data from Gyro - * @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 Gyro motion data unit in param array:dps(degree per second) - * @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 Gyro ID number * @param none @@ -201,11 +218,11 @@ protected: void initialize(uint8_t, uint8_t, uint8_t, uint8_t); - 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 gyro_addr; // gyro sensor address uint8_t gyro_id; // gyro ID uint8_t gyro_ready; // gyro is on I2C line = 1, not = 0