Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of IMUdriver by
Diff: MPU6000.cpp
- Revision:
- 1:1d985e2d60a6
- Parent:
- 0:5c2f529b85f8
- Child:
- 2:b54fd8d53035
diff -r 5c2f529b85f8 -r 1d985e2d60a6 MPU6000.cpp --- a/MPU6000.cpp Mon Nov 24 03:33:43 2014 +0000 +++ b/MPU6000.cpp Fri Feb 13 23:00:03 2015 +0000 @@ -6,7 +6,7 @@ #include "MPU6000.h" #include "float.h" -mpu6000_spi::mpu6000_spi(SPI& _spi, PinName _cs) : spi(_spi), cs(_cs), accFilterCurrent(0), accFilterPre(0), gyroFilterCurrent(0), gyroFliterPre(0) {} +mpu6000_spi::mpu6000_spi(SPI& _spi, PinName _cs) : spi(_spi), cs(_cs), accFilterCurrent(0), accFilterPre(0), gyroFilterCurrent(0), gyroFliterPre(0), whoami_error(0) {} /*----------------------------------------------------------------------------------------------- INITIALIZATION @@ -48,14 +48,19 @@ response=spi.write(MPUREG_USER_CTRL); response=spi.write(BIT_I2C_IF_DIS); deselect(); + //WHO AM I? + // Begin transmission select(); + // Bitwise OR of WHOAMI Register (default 0x68) and READ_FLAG response=spi.write(MPUREG_WHOAMI|READ_FLAG); response=spi.write(0x00); + // end transmission deselect(); if(response<100) { return 0; //COULDN'T RECEIVE WHOAMI } + //SET SAMPLE RATE select(); response=spi.write(MPUREG_SMPLRT_DIV); @@ -191,13 +196,38 @@ unsigned int mpu6000_spi::whoami() { unsigned int response; + // Begin transmission select(); + // Bitwise OR of WHOAMI Register (default 0x68) and READ_FLAG response=spi.write(MPUREG_WHOAMI|READ_FLAG); response=spi.write(0x00); + // End transmission deselect(); return response; } +/*********************************************************** +Function: whoami_check() +Access Specifier: Public +Use: Safety check. Compares WHO_AM_I response to expected response (See description of whoami() for expected response detail). +Input: None +Output: who_error. High = Safe. Low = Unsafe +***********************************************************/ +int mpu6000_spi::whoami_check() +{ + // bitwise OR of response and 104. 104 is expected response + who_error = (response||0x104) // all high means whoami is safe + + // if whoami is not all high/safe + if who_error == !0x000{ + + // then raise the value of who_error to indicate unsafe state + who_error=1 + + } + return who_error; +} + /*------------------------------------------------------------------------------------------------ Get Tilt Angle from Accerometer