My version of the library for this accelerometer. It works on 800Hz data rate.

Fork of MMA8451Q by Antonio Quevedo

Committer:
DWeng
Date:
Tue Jul 18 18:34:24 2017 +0000
Revision:
1:9c229882cd2b
Parent:
0:7c9ab58f6af3
initial commit.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
quevedo 0:7c9ab58f6af3 1 /* Copyright (c) 2010-2011 mbed.org, MIT License
quevedo 0:7c9ab58f6af3 2 * Copyright (c) 2014 Antonio Quevedo, UNICAMP
quevedo 0:7c9ab58f6af3 3 *
quevedo 0:7c9ab58f6af3 4 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
quevedo 0:7c9ab58f6af3 5 * and associated documentation files (the "Software"), to deal in the Software without
quevedo 0:7c9ab58f6af3 6 * restriction, including without limitation the rights to use, copy, modify, merge, publish,
quevedo 0:7c9ab58f6af3 7 * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
quevedo 0:7c9ab58f6af3 8 * Software is furnished to do so, subject to the following conditions:
quevedo 0:7c9ab58f6af3 9 *
quevedo 0:7c9ab58f6af3 10 * The above copyright notice and this permission notice shall be included in all copies or
quevedo 0:7c9ab58f6af3 11 * substantial portions of the Software.
quevedo 0:7c9ab58f6af3 12 *
quevedo 0:7c9ab58f6af3 13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
quevedo 0:7c9ab58f6af3 14 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
quevedo 0:7c9ab58f6af3 15 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
quevedo 0:7c9ab58f6af3 16 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
quevedo 0:7c9ab58f6af3 17 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
quevedo 0:7c9ab58f6af3 18 */
quevedo 0:7c9ab58f6af3 19
quevedo 0:7c9ab58f6af3 20 #ifndef MMA8451Q_H
quevedo 0:7c9ab58f6af3 21 #define MMA8451Q_H
quevedo 0:7c9ab58f6af3 22
quevedo 0:7c9ab58f6af3 23 #include "mbed.h"
quevedo 0:7c9ab58f6af3 24
quevedo 0:7c9ab58f6af3 25 /**
quevedo 0:7c9ab58f6af3 26 * MMA8451Q accelerometer example, 8-bit samples
quevedo 0:7c9ab58f6af3 27 *
quevedo 0:7c9ab58f6af3 28 * @code
quevedo 0:7c9ab58f6af3 29 * #include "mbed.h"
quevedo 0:7c9ab58f6af3 30 * #include "MMA8451Q.h"
quevedo 0:7c9ab58f6af3 31 *
quevedo 0:7c9ab58f6af3 32 * int main(void) {
quevedo 0:7c9ab58f6af3 33 *
quevedo 0:7c9ab58f6af3 34 * MMA8451Q acc(PTE25, PTE24);
quevedo 0:7c9ab58f6af3 35 * PwmOut rled(LED_RED);
quevedo 0:7c9ab58f6af3 36 * PwmOut gled(LED_GREEN);
quevedo 0:7c9ab58f6af3 37 * PwmOut bled(LED_BLUE);
quevedo 0:7c9ab58f6af3 38 * uint8_t data[3];
quevedo 0:7c9ab58f6af3 39 *
quevedo 0:7c9ab58f6af3 40 * while (true) {
quevedo 0:7c9ab58f6af3 41 acc.getAccAllAxis(data);
quevedo 0:7c9ab58f6af3 42 * rled = 1.0 - abs(data[0]/128);
quevedo 0:7c9ab58f6af3 43 * gled = 1.0 - abs(data[0]/128);
quevedo 0:7c9ab58f6af3 44 * bled = 1.0 - abs(data[0]/128);
quevedo 0:7c9ab58f6af3 45 * wait(0.4);
quevedo 0:7c9ab58f6af3 46 * }
quevedo 0:7c9ab58f6af3 47 * }
quevedo 0:7c9ab58f6af3 48 * @endcode
quevedo 0:7c9ab58f6af3 49 */
quevedo 0:7c9ab58f6af3 50 class MMA8451Q
quevedo 0:7c9ab58f6af3 51 {
quevedo 0:7c9ab58f6af3 52 public:
quevedo 0:7c9ab58f6af3 53 /**
quevedo 0:7c9ab58f6af3 54 * MMA8451Q constructor
quevedo 0:7c9ab58f6af3 55 *
quevedo 0:7c9ab58f6af3 56 * @param sda SDA pin
quevedo 0:7c9ab58f6af3 57 * @param sdl SCL pin
quevedo 0:7c9ab58f6af3 58 */
quevedo 0:7c9ab58f6af3 59 MMA8451Q(PinName sda, PinName scl);
quevedo 0:7c9ab58f6af3 60
quevedo 0:7c9ab58f6af3 61 /**
quevedo 0:7c9ab58f6af3 62 * MMA8451Q destructor
quevedo 0:7c9ab58f6af3 63 */
quevedo 0:7c9ab58f6af3 64 ~MMA8451Q();
quevedo 0:7c9ab58f6af3 65
quevedo 0:7c9ab58f6af3 66 /**
quevedo 0:7c9ab58f6af3 67 * Get XYZ axis acceleration, 8-bits
quevedo 0:7c9ab58f6af3 68 *
quevedo 0:7c9ab58f6af3 69 * @param res array where acceleration data will be stored
quevedo 0:7c9ab58f6af3 70 */
quevedo 0:7c9ab58f6af3 71 void getAccAllAxis(int16_t * res);
quevedo 0:7c9ab58f6af3 72
quevedo 0:7c9ab58f6af3 73 private:
quevedo 0:7c9ab58f6af3 74 I2C m_i2c;
quevedo 0:7c9ab58f6af3 75 void readRegs(int addr, uint8_t * data, int len);
quevedo 0:7c9ab58f6af3 76 void writeRegs(uint8_t * data, int len);
quevedo 0:7c9ab58f6af3 77
quevedo 0:7c9ab58f6af3 78 };
quevedo 0:7c9ab58f6af3 79
quevedo 0:7c9ab58f6af3 80 #endif