MPU6050 FreeIMU library
Dependents: FreeIMU FreeIMU_external_magnetometer
Fork of MPU6050_tmp by
Async MPU6050 library
My port of the MPU6050 library samples the chip at 500Hz using Timer. Async I2C is achieved using a custom I2C library, which supports I2C calls from interrupts. Link given below:
Import libraryMODI2C
Improvements to Olieman's MODI2C library. Supports calls from IRQ.
Difference between this port and the Arduino MPU6050 library
The getMotion6 function only returns a copy of the last obtained readings, which is sampled at a frequency of 500Hz (adjustable). Hence it can be called at any frequency without taxing the I2C.
I2Cdev.h@11:9549be34fa7f, 2014-09-24 (annotated)
- Committer:
- tyftyftyf
- Date:
- Wed Sep 24 01:10:42 2014 +0000
- Revision:
- 11:9549be34fa7f
- Parent:
- 10:11cc1b413f49
Allow starting and stopping MPU6050 sampling
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
garfieldsg | 0:662207e34fba | 1 | //ported from arduino library: https://github.com/jrowberg/i2cdevlib/tree/master/Arduino/MPU6050 |
pommzorz | 2:3cf70c42a784 | 2 | //written by szymon gaertig (email: szymon@gaertig.com.pl), small correction by Aloïs Wolff |
garfieldsg | 0:662207e34fba | 3 | // |
garfieldsg | 0:662207e34fba | 4 | //Changelog: |
garfieldsg | 0:662207e34fba | 5 | //2013-01-08 - first beta release |
pommzorz | 2:3cf70c42a784 | 6 | //2013-02-18 - fixed a malloc with no free in ::readBytes |
garfieldsg | 0:662207e34fba | 7 | |
garfieldsg | 0:662207e34fba | 8 | #ifndef I2Cdev_h |
garfieldsg | 0:662207e34fba | 9 | #define I2Cdev_h |
garfieldsg | 0:662207e34fba | 10 | |
tyftyftyf | 9:d879deb55ae1 | 11 | #ifndef I2C_SDA |
tyftyftyf | 9:d879deb55ae1 | 12 | #define I2C_SDA p28 |
tyftyftyf | 9:d879deb55ae1 | 13 | #define I2C_SCL p27 |
tyftyftyf | 9:d879deb55ae1 | 14 | #endif |
garfieldsg | 0:662207e34fba | 15 | |
tyftyftyf | 9:d879deb55ae1 | 16 | #include "mbed.h" |
tyftyftyf | 9:d879deb55ae1 | 17 | #include "MODI2C.h" |
garfieldsg | 0:662207e34fba | 18 | |
garfieldsg | 0:662207e34fba | 19 | class I2Cdev { |
garfieldsg | 0:662207e34fba | 20 | private: |
tyftyftyf | 9:d879deb55ae1 | 21 | |
garfieldsg | 0:662207e34fba | 22 | Serial debugSerial; |
garfieldsg | 0:662207e34fba | 23 | public: |
garfieldsg | 0:662207e34fba | 24 | I2Cdev(); |
garfieldsg | 0:662207e34fba | 25 | I2Cdev(PinName i2cSda, PinName i2cScl); |
tyftyftyf | 9:d879deb55ae1 | 26 | I2Cdev(MODI2C i2c_); |
garfieldsg | 0:662207e34fba | 27 | |
garfieldsg | 0:662207e34fba | 28 | int8_t readBit(uint8_t devAddr, uint8_t regAddr, uint8_t bitNum, uint8_t *data, uint16_t timeout=I2Cdev::readTimeout()); |
garfieldsg | 0:662207e34fba | 29 | int8_t readBitW(uint8_t devAddr, uint8_t regAddr, uint8_t bitNum, uint16_t *data, uint16_t timeout=I2Cdev::readTimeout()); |
garfieldsg | 0:662207e34fba | 30 | int8_t readBits(uint8_t devAddr, uint8_t regAddr, uint8_t bitStart, uint8_t length, uint8_t *data, uint16_t timeout=I2Cdev::readTimeout()); |
garfieldsg | 0:662207e34fba | 31 | int8_t readBitsW(uint8_t devAddr, uint8_t regAddr, uint8_t bitStart, uint8_t length, uint16_t *data, uint16_t timeout=I2Cdev::readTimeout()); |
garfieldsg | 0:662207e34fba | 32 | int8_t readByte(uint8_t devAddr, uint8_t regAddr, uint8_t *data, uint16_t timeout=I2Cdev::readTimeout()); |
garfieldsg | 0:662207e34fba | 33 | int8_t readWord(uint8_t devAddr, uint8_t regAddr, uint16_t *data, uint16_t timeout=I2Cdev::readTimeout()); |
garfieldsg | 0:662207e34fba | 34 | int8_t readBytes(uint8_t devAddr, uint8_t regAddr, uint8_t length, uint8_t *data, uint16_t timeout=I2Cdev::readTimeout()); |
garfieldsg | 0:662207e34fba | 35 | int8_t readWords(uint8_t devAddr, uint8_t regAddr, uint8_t length, uint16_t *data, uint16_t timeout=I2Cdev::readTimeout()); |
garfieldsg | 0:662207e34fba | 36 | |
garfieldsg | 0:662207e34fba | 37 | bool writeBit(uint8_t devAddr, uint8_t regAddr, uint8_t bitNum, uint8_t data); |
garfieldsg | 0:662207e34fba | 38 | bool writeBitW(uint8_t devAddr, uint8_t regAddr, uint8_t bitNum, uint16_t data); |
garfieldsg | 0:662207e34fba | 39 | bool writeBits(uint8_t devAddr, uint8_t regAddr, uint8_t bitStart, uint8_t length, uint8_t data); |
garfieldsg | 0:662207e34fba | 40 | bool writeBitsW(uint8_t devAddr, uint8_t regAddr, uint8_t bitStart, uint8_t length, uint16_t data); |
garfieldsg | 0:662207e34fba | 41 | bool writeByte(uint8_t devAddr, uint8_t regAddr, uint8_t data); |
garfieldsg | 0:662207e34fba | 42 | bool writeWord(uint8_t devAddr, uint8_t regAddr, uint16_t data); |
garfieldsg | 0:662207e34fba | 43 | bool writeBytes(uint8_t devAddr, uint8_t regAddr, uint8_t length, uint8_t *data); |
garfieldsg | 0:662207e34fba | 44 | bool writeWords(uint8_t devAddr, uint8_t regAddr, uint8_t length, uint16_t *data); |
tyftyftyf | 9:d879deb55ae1 | 45 | |
tyftyftyf | 9:d879deb55ae1 | 46 | void readBytes_nb(uint8_t devAddr, char *command, uint8_t length, uint8_t *data, uint32_t (*function)(uint32_t), void* param); |
garfieldsg | 0:662207e34fba | 47 | |
garfieldsg | 0:662207e34fba | 48 | static uint16_t readTimeout(void); |
tyftyftyf | 9:d879deb55ae1 | 49 | |
tyftyftyf | 9:d879deb55ae1 | 50 | MODI2C i2c; |
tyftyftyf | 9:d879deb55ae1 | 51 | |
tyftyftyf | 9:d879deb55ae1 | 52 | char* allocbuffer(); |
tyftyftyf | 9:d879deb55ae1 | 53 | void freebuffer(); |
tyftyftyf | 9:d879deb55ae1 | 54 | |
tyftyftyf | 10:11cc1b413f49 | 55 | MemoryPool<char[14], 16> pool; |
tyftyftyf | 10:11cc1b413f49 | 56 | Queue<char, 16> queue; |
garfieldsg | 0:662207e34fba | 57 | }; |
garfieldsg | 0:662207e34fba | 58 | |
garfieldsg | 0:662207e34fba | 59 | #endif |