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.
Dependents: acd52832_BLE_VF_GeoBeacon
mma8452.h
00001 /* 00002 * Library for mma8452 3-Axis, 12-bit/8-bit, Digital Accelerometer 00003 * Made by Jurica Resetar 00004 * jurica_resetar@yahoo.com 00005 * 00006 * All rights reserved 00007 */ 00008 00009 #include "mbed.h" 00010 00011 #define SA0 1 00012 #if SA0 00013 #define MMA8452_ADDRESS (0x1D << 1) // SA0 is high, 0x1C if low. Shifting address by 1 bit as i2c is a 7 bit encoding, and this is 8bit encoded 00014 #else 00015 #define MMA8452_ADDRESS (0x1C << 1) // SA0 is high, 0x1C if low. Shifting address by 1 bit as i2c is a 7 bit encoding, and this is 8bit encoded 00016 #endif 00017 00018 #define STATUS 0x00 // Type 'read' : Real time status, should return 0x00 00019 #define OUT_X_MSB 0x01 // Type 'read' : x axis - 8 most significatn bit of a 12 bit sample 00020 #define OUT_X_LSB 0x02 // Type 'read' : x axis - 4 least significatn bit of a 12 bit sample 00021 #define OUT_Y_MSB 0x03 // Type 'read' : y axis - 8 most significatn bit of a 12 bit sample 00022 #define OUT_Y_LSB 0x04 // Type 'read' : y axis - 4 least significatn bit of a 12 bit sample 00023 #define OUT_Z_MSB 0x05 // Type 'read' : z axis - 8 most significatn bit of a 12 bit sample 00024 #define OUT_Z_LSB 0x06 // Type 'read' : z axis - 4 least significatn bit of a 12 bit sample 00025 00026 #define SYSMOD 0x0B // Type 'read' : This tells you if device is active, sleep or standy 0x00=STANDBY 0x01=WAKE 0x02=SLEEP 00027 #define WHO_AM_I 0x0D // Type 'read' : This should return the device id of 0x2A 00028 00029 #define PL_STATUS 0x10 // Type 'read' : This shows portrait landscape mode orientation 00030 #define PL_CFG 0x11 // Type 'read/write' : This allows portrait landscape configuration 00031 #define PL_COUNT 0x12 // Type 'read' : This is the portraint landscape debounce counter 00032 #define PL_BF_ZCOMP 0x13 // Type 'read' : 00033 #define PL_THS_REG 0x14 // Type 'read' : 00034 00035 #define FF_MT_CFG 0X15 // Type 'read/write' : Freefaul motion functional block configuration 00036 #define FF_MT_SRC 0X16 // Type 'read' : Freefaul motion event source register 00037 #define FF_MT_THS 0X17 // Type 'read' : Freefaul motion threshold register 00038 #define FF_COUNT 0X18 // Type 'read' : Freefaul motion debouce counter 00039 00040 #define ASLP_COUNT 0x29 // Type 'read/write' : Counter settings for auto sleep 00041 #define CTRL_REG_1 0x2A // Type 'read/write' : 00042 #define CTRL_REG_2 0x2B // Type 'read/write' : 00043 #define CTRL_REG_3 0x2C // Type 'read/write' : 00044 #define CTRL_REG_4 0x2D // Type 'read/write' : 00045 #define CTRL_REG_5 0x2E // Type 'read/write' : 00046 00047 // Defined in table 13 of the Freescale PDF 00048 #define STANDBY 0x00 // State value returned after a SYSMOD request, it can be in state STANDBY, WAKE or SLEEP 00049 #define WAKE 0x01 // State value returned after a SYSMOD request, it can be in state STANDBY, WAKE or SLEEP 00050 #define SLEEP 0x02 // State value returned after a SYSMOD request, it can be in state STANDBY, WAKE or SLEEP 00051 #define ACTIVE 0x01 // Stage value returned and set in Control Register 1, it can be STANDBY=00, or ACTIVE=01 00052 00053 00054 00055 #define TILT_STATUS 0x03 // Tilt Status (Read only) 00056 #define SRST_STATUS 0x04 // Sample Rate Status Register (Read only) 00057 #define SPCNT_STATUS 0x05 // Sleep Count Register (Read/Write) 00058 #define INTSU_STATUS 0x06 // Interrupt Setup Register 00059 #define MODE_STATUS 0x07 // Mode Register (Read/Write) 00060 #define SR_STATUS 0x08 // Auto-Wake and Active Mode Portrait/Landscape Samples per Seconds Register (Read/Write) 00061 #define PDET_STATUS 0x09 // Tap/Pulse Detection Register (Read/Write) 00062 #define PD_STATUS 0xA // Tap/Pulse Debounce Count Register (Read/Write) 00063 00064 00065 class Acc_MMA8452{ 00066 public: 00067 Acc_MMA8452(PinName sda, PinName scl, char address); 00068 ~Acc_MMA8452(); 00069 //uint8_tinit(); 00070 uint8_t set_register(char reg, char data); 00071 uint8_t get_register(char reg, char *data); 00072 uint8_t get_x_acc(char *data); 00073 uint8_t get_y_acc(char *data); 00074 uint8_t get_z_acc(char *data); 00075 00076 char acc_address; 00077 00078 private: 00079 I2C i2c; 00080 }; 00081
Generated on Mon Jul 18 2022 03:41:50 by
1.7.2