Modification to FXOS8700Q for use in Data Logger project
Dependencies: FXOS8700Q MotionSensor
Dependents: GPS_6Axis_DataLogger_SD_UDP
Fork of FXOS8700Q by
FXOS8700Q.h@9:5553a64d0762, 2014-05-07 (annotated)
- Committer:
- JimCarver
- Date:
- Wed May 07 18:08:08 2014 +0000
- Revision:
- 9:5553a64d0762
- Parent:
- 6:cdc362f08339
Minor change to improve efficiency to I2C usage
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
JimCarver | 3:eb1271ef90bc | 1 | /* Copyright (c) 2010-2011 mbed.org, MIT License |
JimCarver | 3:eb1271ef90bc | 2 | * |
JimCarver | 3:eb1271ef90bc | 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
JimCarver | 3:eb1271ef90bc | 4 | * and associated documentation files (the "Software"), to deal in the Software without |
JimCarver | 3:eb1271ef90bc | 5 | * restriction, including without limitation the rights to use, copy, modify, merge, publish, |
JimCarver | 3:eb1271ef90bc | 6 | * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the |
JimCarver | 3:eb1271ef90bc | 7 | * Software is furnished to do so, subject to the following conditions: |
JimCarver | 3:eb1271ef90bc | 8 | * |
JimCarver | 3:eb1271ef90bc | 9 | * The above copyright notice and this permission notice shall be included in all copies or |
JimCarver | 3:eb1271ef90bc | 10 | * substantial portions of the Software. |
JimCarver | 3:eb1271ef90bc | 11 | * |
JimCarver | 3:eb1271ef90bc | 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
JimCarver | 3:eb1271ef90bc | 13 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
JimCarver | 3:eb1271ef90bc | 14 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
JimCarver | 3:eb1271ef90bc | 15 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
JimCarver | 3:eb1271ef90bc | 16 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
JimCarver | 3:eb1271ef90bc | 17 | */ |
JimCarver | 3:eb1271ef90bc | 18 | |
JimCarver | 0:2562215f5bc0 | 19 | #ifndef FXOS8700Q_H |
JimCarver | 0:2562215f5bc0 | 20 | #define FXOS8700Q_H |
JimCarver | 0:2562215f5bc0 | 21 | |
JimCarver | 0:2562215f5bc0 | 22 | #include "mbed.h" |
JimCarver | 5:c4176a12f7d5 | 23 | #include "MotionSensor.h" |
JimCarver | 0:2562215f5bc0 | 24 | // FXOS8700CQ I2C address |
JimCarver | 1:8b53edef272f | 25 | #define FXOS8700CQ_SLAVE_ADDR0 (0x1E<<1) // with pins SA0=0, SA1=0 |
JimCarver | 1:8b53edef272f | 26 | #define FXOS8700CQ_SLAVE_ADDR1 (0x1D<<1) // with pins SA0=1, SA1=0 |
JimCarver | 1:8b53edef272f | 27 | #define FXOS8700CQ_SLAVE_ADDR2 (0x1C<<1) // with pins SA0=0, SA1=1 |
JimCarver | 1:8b53edef272f | 28 | #define FXOS8700CQ_SLAVE_ADDR3 (0x1F<<1) // with pins SA0=1, SA1=1 |
JimCarver | 0:2562215f5bc0 | 29 | // FXOS8700CQ internal register addresses |
JimCarver | 1:8b53edef272f | 30 | #define FXOS8700Q_STATUS 0x00 |
JimCarver | 1:8b53edef272f | 31 | #define FXOS8700Q_OUT_X_MSB 0x01 |
JimCarver | 1:8b53edef272f | 32 | #define FXOS8700Q_OUT_Y_MSB 0x03 |
JimCarver | 1:8b53edef272f | 33 | #define FXOS8700Q_OUT_Z_MSB 0x05 |
JimCarver | 1:8b53edef272f | 34 | #define FXOS8700Q_M_OUT_X_MSB 0x33 |
JimCarver | 1:8b53edef272f | 35 | #define FXOS8700Q_M_OUT_Y_MSB 0x35 |
JimCarver | 1:8b53edef272f | 36 | #define FXOS8700Q_M_OUT_Z_MSB 0x37 |
JimCarver | 1:8b53edef272f | 37 | #define FXOS8700Q_WHOAMI 0x0D |
JimCarver | 1:8b53edef272f | 38 | #define FXOS8700Q_XYZ_DATA_CFG 0x0E |
JimCarver | 1:8b53edef272f | 39 | #define FXOS8700Q_CTRL_REG1 0x2A |
JimCarver | 1:8b53edef272f | 40 | #define FXOS8700Q_M_CTRL_REG1 0x5B |
JimCarver | 1:8b53edef272f | 41 | #define FXOS8700Q_M_CTRL_REG2 0x5C |
JimCarver | 1:8b53edef272f | 42 | #define FXOS8700Q_WHOAMI_VAL 0xC7 |
JimCarver | 0:2562215f5bc0 | 43 | |
JimCarver | 3:eb1271ef90bc | 44 | |
JimCarver | 3:eb1271ef90bc | 45 | /** |
JimCarver | 3:eb1271ef90bc | 46 | * MMA8451Q accelerometer example |
JimCarver | 3:eb1271ef90bc | 47 | * |
JimCarver | 3:eb1271ef90bc | 48 | * @code |
JimCarver | 3:eb1271ef90bc | 49 | * #include "mbed.h" |
JimCarver | 3:eb1271ef90bc | 50 | * #include "FXOS8700Q.h" |
JimCarver | 3:eb1271ef90bc | 51 | * |
JimCarver | 3:eb1271ef90bc | 52 | * |
JimCarver | 3:eb1271ef90bc | 53 | * int main(void) { |
JimCarver | 3:eb1271ef90bc | 54 | * |
JimCarver | 3:eb1271ef90bc | 55 | * FXOS8700Q combo( A4, A5, FXOS8700Q_I2C_ADDRESS0); |
JimCarver | 3:eb1271ef90bc | 56 | * PwmOut rled(LED_RED); |
JimCarver | 3:eb1271ef90bc | 57 | * PwmOut gled(LED_GREEN); |
JimCarver | 3:eb1271ef90bc | 58 | * PwmOut bled(LED_BLUE); |
JimCarver | 3:eb1271ef90bc | 59 | * |
JimCarver | 3:eb1271ef90bc | 60 | * while (true) { |
JimCarver | 6:cdc362f08339 | 61 | * rled1.0 - combo(acc.getAccX()); |
JimCarver | 6:cdc362f08339 | 62 | * gled1.0 - combo(acc.getAccY()); |
JimCarver | 6:cdc362f08339 | 63 | * bled1.0 - combo(acc.getAccZ()); |
JimCarver | 3:eb1271ef90bc | 64 | * wait(0.1); |
JimCarver | 3:eb1271ef90bc | 65 | * } |
JimCarver | 3:eb1271ef90bc | 66 | * } |
JimCarver | 3:eb1271ef90bc | 67 | * @endcode |
JimCarver | 3:eb1271ef90bc | 68 | */ |
JimCarver | 3:eb1271ef90bc | 69 | |
JimCarver | 6:cdc362f08339 | 70 | class FXOS8700Q_acc : public MotionSensor |
JimCarver | 0:2562215f5bc0 | 71 | { |
JimCarver | 0:2562215f5bc0 | 72 | public: |
JimCarver | 1:8b53edef272f | 73 | /** |
JimCarver | 1:8b53edef272f | 74 | * FXOS8700Q constructor |
JimCarver | 1:8b53edef272f | 75 | * |
JimCarver | 1:8b53edef272f | 76 | * @param sda SDA pin |
JimCarver | 1:8b53edef272f | 77 | * @param sdl SCL pin |
JimCarver | 1:8b53edef272f | 78 | * @param addr addr of the I2C peripheral |
JimCarver | 1:8b53edef272f | 79 | */ |
JimCarver | 1:8b53edef272f | 80 | |
JimCarver | 6:cdc362f08339 | 81 | FXOS8700Q_acc(PinName sda, PinName scl, int addr); |
JimCarver | 1:8b53edef272f | 82 | |
JimCarver | 1:8b53edef272f | 83 | /** |
JimCarver | 1:8b53edef272f | 84 | * FXOS8700Q destructor |
JimCarver | 1:8b53edef272f | 85 | */ |
JimCarver | 6:cdc362f08339 | 86 | ~FXOS8700Q_acc(); |
JimCarver | 1:8b53edef272f | 87 | |
JimCarver | 6:cdc362f08339 | 88 | void enable(void); |
JimCarver | 6:cdc362f08339 | 89 | void disable(void); |
JimCarver | 6:cdc362f08339 | 90 | uint32_t sampleRate(uint32_t frequency); |
JimCarver | 6:cdc362f08339 | 91 | uint32_t whoAmI(void); |
JimCarver | 6:cdc362f08339 | 92 | uint32_t dataReady(void); |
JimCarver | 6:cdc362f08339 | 93 | void getX(int16_t * x); |
JimCarver | 6:cdc362f08339 | 94 | void getY(int16_t * y); |
JimCarver | 6:cdc362f08339 | 95 | void getZ(int16_t * z); |
JimCarver | 6:cdc362f08339 | 96 | void getX(float * x); |
JimCarver | 6:cdc362f08339 | 97 | void getY(float * y); |
JimCarver | 6:cdc362f08339 | 98 | void getZ(float * z); |
JimCarver | 6:cdc362f08339 | 99 | void getAxis(MotionSensorDataCounts &data); |
JimCarver | 6:cdc362f08339 | 100 | void getAxis(MotionSensorDataUnits &data); |
JimCarver | 6:cdc362f08339 | 101 | |
JimCarver | 6:cdc362f08339 | 102 | void readRegs(int addr, uint8_t * data, int len); |
JimCarver | 6:cdc362f08339 | 103 | |
JimCarver | 6:cdc362f08339 | 104 | private: |
JimCarver | 6:cdc362f08339 | 105 | I2C m_i2c; |
JimCarver | 6:cdc362f08339 | 106 | int m_addr; |
JimCarver | 0:2562215f5bc0 | 107 | |
JimCarver | 6:cdc362f08339 | 108 | void writeRegs(uint8_t * data, int len); |
JimCarver | 6:cdc362f08339 | 109 | int16_t getAccAxis(uint8_t addr); |
JimCarver | 6:cdc362f08339 | 110 | |
JimCarver | 6:cdc362f08339 | 111 | }; |
JimCarver | 1:8b53edef272f | 112 | |
JimCarver | 6:cdc362f08339 | 113 | class FXOS8700Q_mag : public MotionSensor |
JimCarver | 6:cdc362f08339 | 114 | { |
JimCarver | 6:cdc362f08339 | 115 | public: |
JimCarver | 6:cdc362f08339 | 116 | FXOS8700Q_mag(PinName sda, PinName scl, int addr); |
JimCarver | 0:2562215f5bc0 | 117 | |
JimCarver | 1:8b53edef272f | 118 | /** |
JimCarver | 6:cdc362f08339 | 119 | * FXOS8700Q destructor |
JimCarver | 6:cdc362f08339 | 120 | */ |
JimCarver | 6:cdc362f08339 | 121 | ~FXOS8700Q_mag(); |
JimCarver | 6:cdc362f08339 | 122 | |
JimCarver | 6:cdc362f08339 | 123 | void enable(void); |
JimCarver | 6:cdc362f08339 | 124 | void disable(void); |
JimCarver | 6:cdc362f08339 | 125 | uint32_t sampleRate(uint32_t fequency); |
JimCarver | 6:cdc362f08339 | 126 | uint32_t whoAmI(void); |
JimCarver | 6:cdc362f08339 | 127 | uint32_t dataReady(void); |
JimCarver | 6:cdc362f08339 | 128 | void getX(int16_t * x); |
JimCarver | 6:cdc362f08339 | 129 | void getY(int16_t * y); |
JimCarver | 6:cdc362f08339 | 130 | void getZ(int16_t * z); |
JimCarver | 6:cdc362f08339 | 131 | void getX(float * x); |
JimCarver | 6:cdc362f08339 | 132 | void getY(float * y); |
JimCarver | 6:cdc362f08339 | 133 | void getZ(float * z); |
JimCarver | 6:cdc362f08339 | 134 | void getAxis(MotionSensorDataCounts &data); |
JimCarver | 6:cdc362f08339 | 135 | void getAxis(MotionSensorDataUnits &data); |
JimCarver | 4:be6abf9f2d59 | 136 | |
JimCarver | 1:8b53edef272f | 137 | void readRegs(int addr, uint8_t * data, int len); |
JimCarver | 1:8b53edef272f | 138 | |
JimCarver | 1:8b53edef272f | 139 | private: |
JimCarver | 1:8b53edef272f | 140 | I2C m_i2c; |
JimCarver | 1:8b53edef272f | 141 | int m_addr; |
JimCarver | 9:5553a64d0762 | 142 | char sbuf[12]; |
JimCarver | 9:5553a64d0762 | 143 | int sstatus; |
JimCarver | 9:5553a64d0762 | 144 | |
JimCarver | 1:8b53edef272f | 145 | void writeRegs(uint8_t * data, int len); |
JimCarver | 1:8b53edef272f | 146 | int16_t getAccAxis(uint8_t addr); |
JimCarver | 0:2562215f5bc0 | 147 | |
JimCarver | 0:2562215f5bc0 | 148 | }; |
JimCarver | 0:2562215f5bc0 | 149 | |
JimCarver | 0:2562215f5bc0 | 150 | #endif |