A basic library for the MMA8652 accelerometer, provides data in either floating point G's or as a signed 16 bit integer.
Dependents: Hello_MMA8652 Multi-Sensor Buddi_Blueband Freescale_Multi-Sensor_Shield ... more
MMA8652.h@1:ff30cc4759b4, 2014-04-19 (annotated)
- Committer:
- JimCarver
- Date:
- Sat Apr 19 01:28:26 2014 +0000
- Revision:
- 1:ff30cc4759b4
- Parent:
- 0:3ae1e808e61c
- Child:
- 2:29c2dd97ca95
Added features
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
JimCarver | 1:ff30cc4759b4 | 1 | /* Copyright (c) 2010-2011 mbed.org, MIT License |
JimCarver | 1:ff30cc4759b4 | 2 | * |
JimCarver | 1:ff30cc4759b4 | 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
JimCarver | 1:ff30cc4759b4 | 4 | * and associated documentation files (the "Software"), to deal in the Software without |
JimCarver | 1:ff30cc4759b4 | 5 | * restriction, including without limitation the rights to use, copy, modify, merge, publish, |
JimCarver | 1:ff30cc4759b4 | 6 | * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the |
JimCarver | 1:ff30cc4759b4 | 7 | * Software is furnished to do so, subject to the following conditions: |
JimCarver | 1:ff30cc4759b4 | 8 | * |
JimCarver | 1:ff30cc4759b4 | 9 | * The above copyright notice and this permission notice shall be included in all copies or |
JimCarver | 1:ff30cc4759b4 | 10 | * substantial portions of the Software. |
JimCarver | 1:ff30cc4759b4 | 11 | * |
JimCarver | 1:ff30cc4759b4 | 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
JimCarver | 1:ff30cc4759b4 | 13 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
JimCarver | 1:ff30cc4759b4 | 14 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
JimCarver | 1:ff30cc4759b4 | 15 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
JimCarver | 1:ff30cc4759b4 | 16 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
JimCarver | 1:ff30cc4759b4 | 17 | */ |
JimCarver | 1:ff30cc4759b4 | 18 | |
JimCarver | 0:3ae1e808e61c | 19 | #ifndef MMA8652_H |
JimCarver | 0:3ae1e808e61c | 20 | #define MMA8652_H |
JimCarver | 0:3ae1e808e61c | 21 | |
JimCarver | 0:3ae1e808e61c | 22 | #include "mbed.h" |
JimCarver | 0:3ae1e808e61c | 23 | |
JimCarver | 0:3ae1e808e61c | 24 | |
JimCarver | 0:3ae1e808e61c | 25 | // MMA8652 Slave Address |
JimCarver | 0:3ae1e808e61c | 26 | #define MMA8652_SLAVE_ADDR 0x3A |
JimCarver | 0:3ae1e808e61c | 27 | |
JimCarver | 0:3ae1e808e61c | 28 | // MMA8652 internal register addresses |
JimCarver | 0:3ae1e808e61c | 29 | #define MMA8652_STATUS 0x00 |
JimCarver | 1:ff30cc4759b4 | 30 | #define MMA8652_OUT_X_MSB 0x01 |
JimCarver | 0:3ae1e808e61c | 31 | #define MMA8652_WHOAMI 0x0D |
JimCarver | 0:3ae1e808e61c | 32 | #define MMA8652_XYZ_DATA_CFG 0x0E |
JimCarver | 0:3ae1e808e61c | 33 | #define MMA8652_CTRL_REG1 0x2A |
JimCarver | 0:3ae1e808e61c | 34 | #define MMA8652_WHOAMI_VAL 0x4A |
JimCarver | 0:3ae1e808e61c | 35 | |
JimCarver | 0:3ae1e808e61c | 36 | class MMA8652 |
JimCarver | 0:3ae1e808e61c | 37 | { |
JimCarver | 0:3ae1e808e61c | 38 | public: |
JimCarver | 0:3ae1e808e61c | 39 | /** |
JimCarver | 1:ff30cc4759b4 | 40 | * MMA8652 constructor |
JimCarver | 0:3ae1e808e61c | 41 | * |
JimCarver | 0:3ae1e808e61c | 42 | * @param sda SDA pin |
JimCarver | 0:3ae1e808e61c | 43 | * @param sdl SCL pin |
JimCarver | 0:3ae1e808e61c | 44 | * @param addr addr of the I2C peripheral |
JimCarver | 0:3ae1e808e61c | 45 | */ |
JimCarver | 0:3ae1e808e61c | 46 | MMA8652(PinName sda, PinName scl); |
JimCarver | 1:ff30cc4759b4 | 47 | |
JimCarver | 1:ff30cc4759b4 | 48 | /** |
JimCarver | 1:ff30cc4759b4 | 49 | * MMA8652 destructor |
JimCarver | 1:ff30cc4759b4 | 50 | */ |
JimCarver | 1:ff30cc4759b4 | 51 | ~MMA8652(); |
JimCarver | 1:ff30cc4759b4 | 52 | /** |
JimCarver | 1:ff30cc4759b4 | 53 | * Get XYZ axis acceleration in floating point G's |
JimCarver | 1:ff30cc4759b4 | 54 | * |
JimCarver | 1:ff30cc4759b4 | 55 | * @param res array where acceleration data will be stored |
JimCarver | 1:ff30cc4759b4 | 56 | */ |
JimCarver | 1:ff30cc4759b4 | 57 | void ReadXYZ(float * a); |
JimCarver | 0:3ae1e808e61c | 58 | |
JimCarver | 1:ff30cc4759b4 | 59 | /** |
JimCarver | 1:ff30cc4759b4 | 60 | * Get XYZ axis acceleration, signed 16 bit values |
JimCarver | 1:ff30cc4759b4 | 61 | * |
JimCarver | 1:ff30cc4759b4 | 62 | * @param res array where acceleration data will be stored |
JimCarver | 1:ff30cc4759b4 | 63 | */ |
JimCarver | 1:ff30cc4759b4 | 64 | void ReadXYZraw(int16_t * d); |
JimCarver | 1:ff30cc4759b4 | 65 | char getWhoAmI(void); |
JimCarver | 0:3ae1e808e61c | 66 | |
JimCarver | 0:3ae1e808e61c | 67 | private: |
JimCarver | 0:3ae1e808e61c | 68 | |
JimCarver | 0:3ae1e808e61c | 69 | I2C _i2c; |
JimCarver | 0:3ae1e808e61c | 70 | /** Set the device in active mode |
JimCarver | 0:3ae1e808e61c | 71 | */ |
JimCarver | 0:3ae1e808e61c | 72 | void begin( void); |
JimCarver | 0:3ae1e808e61c | 73 | |
JimCarver | 0:3ae1e808e61c | 74 | void RegRead( char reg, char * d, int len); |
JimCarver | 0:3ae1e808e61c | 75 | |
JimCarver | 0:3ae1e808e61c | 76 | }; |
JimCarver | 0:3ae1e808e61c | 77 | |
JimCarver | 0:3ae1e808e61c | 78 | #endif |