Library to communicate with a ST LIS331DLH
Revision 1:02c1f5bb1c90, committed 2010-11-13
- Comitter:
- atommota
- Date:
- Sat Nov 13 00:01:57 2010 +0000
- Parent:
- 0:d835d6cac146
- Child:
- 2:d4b810a888b5
- Commit message:
- fixed some declaration bugs
Changed in this revision
LIS331.cpp | Show annotated file Show diff for this revision Revisions of this file |
LIS331.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/LIS331.cpp Fri Nov 12 23:40:28 2010 +0000 +++ b/LIS331.cpp Sat Nov 13 00:01:57 2010 +0000 @@ -15,6 +15,7 @@ /** * Includes */ + #include "LIS331.h" LIS331::LIS331(PinName sda, PinName scl) : i2c_(sda, scl) { @@ -49,7 +50,18 @@ } -/* Needs to be implemented + + +void LIS331::setPowerMode(char power_mode){ +// Currently sets all 3 axis to enabled. Will be set to preserve existing status in future + char tx[2]; + tx[0] = CTRL_REG_1; + tx[1] = power_mode; + + i2c_.write((LIS331_I2C_ADDRESS << 1) & 0xFE, tx, 2); + +} + char LIS331::getPowerMode(void){ char tx = CTRL_REG_1; @@ -64,49 +76,6 @@ } -*/ - - - -void LIS331::setPowerMode(char power_mode){ -// Currently sets all 3 axis to enabled. Will be set to preserve existing status in future - char tx[2]; - tx[0] = CTRL_REG_1; - tx[1] = power_mode; - - i2c_.write((LIS331_I2C_ADDRESS << 1) & 0xFE, tx, 2); - -} - - -/* -int LIS331::getInternalSampleRate(void){ - - char tx = DLPF_FS_REG; - char rx; - - i2c_.write((LIS331_I2C_ADDRESS << 1) & 0xFE, &tx, 1); - - i2c_.read((LIS331_I2C_ADDRESS << 1) | 0x01, &rx, 1); - - //DLPF_CFG == 0 -> sample rate = 8kHz. - if(rx == 0){ - return 8; - } - //DLPF_CFG = 1..7 -> sample rate = 1kHz. - else if(rx >= 1 && rx <= 7){ - return 1; - } - //DLPF_CFG = anything else -> something's wrong! - else{ - return -1; - } - -} - - -*/ - char LIS331::getInterruptConfiguration(void){ @@ -124,50 +93,9 @@ - - -/* -void LIS331::setInterruptConfiguration(char config){ - - char tx[2]; - tx[0] = INT_CFG_REG; - tx[1] = config; - - i2c_.write((LIS331_I2C_ADDRESS << 1) & 0xFE, tx, 2); - -} - -*/ - - - -/* -bool LIS331::isPllReady(void){ - - char tx = INT_STATUS; - char rx; - - i2c_.write((LIS331_I2C_ADDRESS << 1) & 0xFE, &tx, 1); - - i2c_.read((LIS331_I2C_ADDRESS << 1) | 0x01, &rx, 1); - - //ITG_RDY bit is bit 4 of INT_STATUS register. - if(rx & 0x04){ - return true; - } - else{ - return false; - } - -} - -*/ - - - char LIS331::getAccelStatus(void){ - char tx = STATSUS_REG; + char tx = STATUS_REG; char rx; i2c_.write((LIS331_I2C_ADDRESS << 1) & 0xFE, &tx, 1); @@ -175,11 +103,10 @@ i2c_.read((LIS331_I2C_ADDRESS << 1) | 0x01, &rx, 1); return rx; - } - } + int LIS331::getAccelX(void){ char tx = ACCEL_XOUT_H_REG; @@ -222,6 +149,4 @@ int16_t output = ((int) rx[1] << 8) | ((int) rx[0]); return output; -} - - +} \ No newline at end of file
--- a/LIS331.h Fri Nov 12 23:40:28 2010 +0000 +++ b/LIS331.h Sat Nov 13 00:01:57 2010 +0000 @@ -88,13 +88,8 @@ - /** - * Get the current power mode - * - * @return - */ - //char getPowerMode(void); + @@ -119,10 +114,19 @@ * Low-power | 10 | -- | LOW_POWER_10HZ */ - //void setPowerMode(char powermode); + void setPowerMode(char power_mode); + + + + /** + * Get the current power mode + * + * @return + */ + char getPowerMode(void); - char getInterruptConfiguration(void); + char getInterruptConfiguration(void); /** * Set the interrupt configuration. @@ -200,80 +204,7 @@ */ int getAccelZ(void); - /** - * Get the power management configuration. - * - * See the datasheet for register contents details. - * - * 7 6 5 4 - * +---------+-------+---------+---------+ - * | H_RESET | SLEEP | STBY_XG | STBY_YG | - * +---------+-------+---------+---------+ - * - * 3 2 1 0 - * +---------+----------+----------+----------+ - * | STBY_ZG | CLK_SEL2 | CLK_SEL1 | CLK_SEL0 | - * +---------+----------+----------+----------+ - * - * H_RESET Reset device and internal registers to the power-up-default settings. - * SLEEP Enable low power sleep mode. - * STBY_XG Put gyro X in standby mode (1=standby, 0=normal). - * STBY_YG Put gyro Y in standby mode (1=standby, 0=normal). - * STBY_ZG Put gyro Z in standby mode (1=standby, 0=normal). - * CLK_SEL Select device clock source: - * - * CLK_SEL | Clock Source - * --------+-------------- - * 0 Internal oscillator - * 1 PLL with X Gyro reference - * 2 PLL with Y Gyro reference - * 3 PLL with Z Gyro reference - * 4 PLL with external 32.768kHz reference - * 5 PLL with external 19.2MHz reference - * 6 Reserved - * 7 Reserved - * - * @return The contents of the PWR_MGM register. - */ - // char getPowerManagement(void); - - /** - * Set power management configuration. - * - * See the datasheet for configuration byte details - * - * 7 6 5 4 - * +---------+-------+---------+---------+ - * | H_RESET | SLEEP | STBY_XG | STBY_YG | - * +---------+-------+---------+---------+ - * - * 3 2 1 0 - * +---------+----------+----------+----------+ - * | STBY_ZG | CLK_SEL2 | CLK_SEL1 | CLK_SEL0 | - * +---------+----------+----------+----------+ - * - * H_RESET Reset device and internal registers to the power-up-default settings. - * SLEEP Enable low power sleep mode. - * STBY_XG Put gyro X in standby mode (1=standby, 0=normal). - * STBY_YG Put gyro Y in standby mode (1=standby, 0=normal). - * STBY_ZG Put gyro Z in standby mode (1=standby, 0=normal). - * CLK_SEL Select device clock source: - * - * CLK_SEL | Clock Source - * --------+-------------- - * 0 Internal oscillator - * 1 PLL with X Gyro reference - * 2 PLL with Y Gyro reference - * 3 PLL with Z Gyro reference - * 4 PLL with external 32.768kHz reference - * 5 PLL with external 19.2MHz reference - * 6 Reserved - * 7 Reserved - * - * @param config The configuration byte to write to the PWR_MGM register. - */ - // void setPowerManagement(char config); - + private: I2C i2c_;