MMA8452Q, 3-axis, 12-bit/8-bit digital accelerometer library. Developed by aconno dev team. For example program with the library, contact us.
Dependents: acd52832_BLE_VF_GeoBeacon
mma8452.h@0:65b19bf1382a, 2017-07-02 (annotated)
- Committer:
- jurica238814
- Date:
- Sun Jul 02 16:04:27 2017 +0000
- Revision:
- 0:65b19bf1382a
- Child:
- 1:bda670d7a481
MMA8452 accelerometer library by aconno dev team. Basic functionalities are achieved. A lot to do.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jurica238814 | 0:65b19bf1382a | 1 | /* |
jurica238814 | 0:65b19bf1382a | 2 | * Library for mma8452 3-Axis, 12-bit/8-bit, Digital Accelerometer |
jurica238814 | 0:65b19bf1382a | 3 | * Made by Jurica Resetar |
jurica238814 | 0:65b19bf1382a | 4 | * jurica_resetar@yahoo.com |
jurica238814 | 0:65b19bf1382a | 5 | * |
jurica238814 | 0:65b19bf1382a | 6 | * All rights reserved |
jurica238814 | 0:65b19bf1382a | 7 | */ |
jurica238814 | 0:65b19bf1382a | 8 | |
jurica238814 | 0:65b19bf1382a | 9 | #include "mbed.h" |
jurica238814 | 0:65b19bf1382a | 10 | |
jurica238814 | 0:65b19bf1382a | 11 | #define SA0 1 |
jurica238814 | 0:65b19bf1382a | 12 | #if SA0 |
jurica238814 | 0:65b19bf1382a | 13 | #define MMA8452_ADDRESS 0x1D // SA0 is high, 0x1C if low - |
jurica238814 | 0:65b19bf1382a | 14 | #else |
jurica238814 | 0:65b19bf1382a | 15 | #define MMA8452_ADDRESS 0x1C |
jurica238814 | 0:65b19bf1382a | 16 | #endif |
jurica238814 | 0:65b19bf1382a | 17 | |
jurica238814 | 0:65b19bf1382a | 18 | #define STATUS 0x00 // Type 'read' : Real time status, should return 0x00 |
jurica238814 | 0:65b19bf1382a | 19 | #define OUT_X_MSB 0x01 // Type 'read' : x axis - 8 most significatn bit of a 12 bit sample |
jurica238814 | 0:65b19bf1382a | 20 | #define OUT_X_LSB 0x02 // Type 'read' : x axis - 4 least significatn bit of a 12 bit sample |
jurica238814 | 0:65b19bf1382a | 21 | #define OUT_Y_MSB 0x03 // Type 'read' : y axis - 8 most significatn bit of a 12 bit sample |
jurica238814 | 0:65b19bf1382a | 22 | #define OUT_Y_LSB 0x04 // Type 'read' : y axis - 4 least significatn bit of a 12 bit sample |
jurica238814 | 0:65b19bf1382a | 23 | #define OUT_Z_MSB 0x05 // Type 'read' : z axis - 8 most significatn bit of a 12 bit sample |
jurica238814 | 0:65b19bf1382a | 24 | #define OUT_Z_LSB 0x06 // Type 'read' : z axis - 4 least significatn bit of a 12 bit sample |
jurica238814 | 0:65b19bf1382a | 25 | |
jurica238814 | 0:65b19bf1382a | 26 | #define SYSMOD 0x0B // Type 'read' : This tells you if device is active, sleep or standy 0x00=STANDBY 0x01=WAKE 0x02=SLEEP |
jurica238814 | 0:65b19bf1382a | 27 | #define WHO_AM_I 0x0D // Type 'read' : This should return the device id of 0x2A |
jurica238814 | 0:65b19bf1382a | 28 | |
jurica238814 | 0:65b19bf1382a | 29 | #define PL_STATUS 0x10 // Type 'read' : This shows portrait landscape mode orientation |
jurica238814 | 0:65b19bf1382a | 30 | #define PL_CFG 0x11 // Type 'read/write' : This allows portrait landscape configuration |
jurica238814 | 0:65b19bf1382a | 31 | #define PL_COUNT 0x12 // Type 'read' : This is the portraint landscape debounce counter |
jurica238814 | 0:65b19bf1382a | 32 | #define PL_BF_ZCOMP 0x13 // Type 'read' : |
jurica238814 | 0:65b19bf1382a | 33 | #define PL_THS_REG 0x14 // Type 'read' : |
jurica238814 | 0:65b19bf1382a | 34 | |
jurica238814 | 0:65b19bf1382a | 35 | #define FF_MT_CFG 0X15 // Type 'read/write' : Freefaul motion functional block configuration |
jurica238814 | 0:65b19bf1382a | 36 | #define FF_MT_SRC 0X16 // Type 'read' : Freefaul motion event source register |
jurica238814 | 0:65b19bf1382a | 37 | #define FF_MT_THS 0X17 // Type 'read' : Freefaul motion threshold register |
jurica238814 | 0:65b19bf1382a | 38 | #define FF_COUNT 0X18 // Type 'read' : Freefaul motion debouce counter |
jurica238814 | 0:65b19bf1382a | 39 | |
jurica238814 | 0:65b19bf1382a | 40 | #define ASLP_COUNT 0x29 // Type 'read/write' : Counter settings for auto sleep |
jurica238814 | 0:65b19bf1382a | 41 | #define CTRL_REG_1 0x2A // Type 'read/write' : |
jurica238814 | 0:65b19bf1382a | 42 | #define CTRL_REG_2 0x2B // Type 'read/write' : |
jurica238814 | 0:65b19bf1382a | 43 | #define CTRL_REG_3 0x2C // Type 'read/write' : |
jurica238814 | 0:65b19bf1382a | 44 | #define CTRL_REG_4 0x2D // Type 'read/write' : |
jurica238814 | 0:65b19bf1382a | 45 | #define CTRL_REG_5 0x2E // Type 'read/write' : |
jurica238814 | 0:65b19bf1382a | 46 | |
jurica238814 | 0:65b19bf1382a | 47 | // Defined in table 13 of the Freescale PDF |
jurica238814 | 0:65b19bf1382a | 48 | #define STANDBY 0x00 // State value returned after a SYSMOD request, it can be in state STANDBY, WAKE or SLEEP |
jurica238814 | 0:65b19bf1382a | 49 | #define WAKE 0x01 // State value returned after a SYSMOD request, it can be in state STANDBY, WAKE or SLEEP |
jurica238814 | 0:65b19bf1382a | 50 | #define SLEEP 0x02 // State value returned after a SYSMOD request, it can be in state STANDBY, WAKE or SLEEP |
jurica238814 | 0:65b19bf1382a | 51 | #define ACTIVE 0x01 // Stage value returned and set in Control Register 1, it can be STANDBY=00, or ACTIVE=01 |
jurica238814 | 0:65b19bf1382a | 52 | |
jurica238814 | 0:65b19bf1382a | 53 | |
jurica238814 | 0:65b19bf1382a | 54 | |
jurica238814 | 0:65b19bf1382a | 55 | #define TILT_STATUS 0x03 // Tilt Status (Read only) |
jurica238814 | 0:65b19bf1382a | 56 | #define SRST_STATUS 0x04 // Sample Rate Status Register (Read only) |
jurica238814 | 0:65b19bf1382a | 57 | #define SPCNT_STATUS 0x05 // Sleep Count Register (Read/Write) |
jurica238814 | 0:65b19bf1382a | 58 | #define INTSU_STATUS 0x06 // Interrupt Setup Register |
jurica238814 | 0:65b19bf1382a | 59 | #define MODE_STATUS 0x07 // Mode Register (Read/Write) |
jurica238814 | 0:65b19bf1382a | 60 | #define SR_STATUS 0x08 // Auto-Wake and Active Mode Portrait/Landscape Samples per Seconds Register (Read/Write) |
jurica238814 | 0:65b19bf1382a | 61 | #define PDET_STATUS 0x09 // Tap/Pulse Detection Register (Read/Write) |
jurica238814 | 0:65b19bf1382a | 62 | #define PD_STATUS 0xA // Tap/Pulse Debounce Count Register (Read/Write) |
jurica238814 | 0:65b19bf1382a | 63 | |
jurica238814 | 0:65b19bf1382a | 64 | |
jurica238814 | 0:65b19bf1382a | 65 | class Acc_MMA8452{ |
jurica238814 | 0:65b19bf1382a | 66 | public: |
jurica238814 | 0:65b19bf1382a | 67 | Acc_MMA8452(PinName sda, PinName scl, char address); |
jurica238814 | 0:65b19bf1382a | 68 | ~Acc_MMA8452(); |
jurica238814 | 0:65b19bf1382a | 69 | //uint8_tinit(); |
jurica238814 | 0:65b19bf1382a | 70 | uint8_t set_register(char reg, char data); |
jurica238814 | 0:65b19bf1382a | 71 | uint8_t get_register(char reg, char *data); |
jurica238814 | 0:65b19bf1382a | 72 | uint8_t get_x_acc(char *data); |
jurica238814 | 0:65b19bf1382a | 73 | uint8_t get_y_acc(char *data); |
jurica238814 | 0:65b19bf1382a | 74 | uint8_t get_z_acc(char *data); |
jurica238814 | 0:65b19bf1382a | 75 | |
jurica238814 | 0:65b19bf1382a | 76 | char acc_address; |
jurica238814 | 0:65b19bf1382a | 77 | |
jurica238814 | 0:65b19bf1382a | 78 | private: |
jurica238814 | 0:65b19bf1382a | 79 | I2C i2c; |
jurica238814 | 0:65b19bf1382a | 80 | }; |
jurica238814 | 0:65b19bf1382a | 81 |