HW
Fork of MMA8451Q by
Revision 5:df36b750371a, committed 2017-02-22
- Comitter:
- kennylujan42
- Date:
- Wed Feb 22 09:49:41 2017 +0000
- Parent:
- 4:c4d879a39775
- Commit message:
- HW
Changed in this revision
MMA8451Q.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r c4d879a39775 -r df36b750371a MMA8451Q.cpp --- a/MMA8451Q.cpp Fri Oct 12 11:35:07 2012 +0000 +++ b/MMA8451Q.cpp Wed Feb 22 09:49:41 2017 +0000 @@ -16,6 +16,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ + + #include "MMA8451Q.h" #define REG_WHO_AM_I 0x0D @@ -23,9 +25,16 @@ #define REG_OUT_X_MSB 0x01 #define REG_OUT_Y_MSB 0x03 #define REG_OUT_Z_MSB 0x05 +#define XYZ_DATA_CFG 0x0E #define UINT14_MAX 16383 +#define MAX_2G 0x00 +#define MAX_4G 0x01 +#define MAX_8G 0x10 + +#define GSCALING 1024.0 + MMA8451Q::MMA8451Q(PinName sda, PinName scl, int addr) : m_i2c(sda, scl), m_addr(addr) { // activate the peripheral uint8_t data[2] = {REG_CTRL_REG_1, 0x01}; @@ -40,6 +49,7 @@ return who_am_i; } + float MMA8451Q::getAccX() { return (float(getAccAxis(REG_OUT_X_MSB))/4096.0); } @@ -79,3 +89,13 @@ void MMA8451Q::writeRegs(uint8_t * data, int len) { m_i2c.write(m_addr, (char *)data, len); } +void MMA8451Q::setGLimit() { + uint8_t data[2] = {REG_CTRL_REG_1, 0x00}; + writeRegs(data, 2); + data[0] = XYZ_DATA_CFG; + data[1] = 0x02; + writeRegs(data, 2); + data[0] = REG_CTRL_REG_1; + data[1] = 0x01; + writeRegs(data, 2); +} \ No newline at end of file