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: test_FXAS21002 testSensor RD-KL25Z-AGMP01_SensorStream pelion-example-frdm ... more
FXAS21002.h
00001 /** 00002 * FXAS21002 00003 * 3-Axis Digital Angular Rate Gyroscope 00004 */ 00005 #ifndef FXAS21002_H 00006 #define FXAS21002_H 00007 00008 #include "mbed.h" 00009 00010 /** 00011 * 00012 * 00013 * @code 00014 #include "mbed.h" 00015 #include "FXAS21002.h" 00016 #define FXAS21002_I2C_ADDRESS (0x20) 00017 00018 #if defined (TARGET_KL25Z) 00019 #define PIN_SCL PTE1 00020 #define PIN_SDA PTE0 00021 #elif defined (TARGET_KL46Z) 00022 #define PIN_SCL PTE1 00023 #define PIN_SDA PTE0 00024 #elif defined (TARGET_K64F) 00025 #define PIN_SCL PTE24 00026 #define PIN_SDA PTE25 00027 #elif defined (TARGET_K22F) 00028 #define PIN_SCL PTE1 00029 #define PIN_SDA PTE0 00030 #elif defined (TARGET_KL05Z) 00031 #define PIN_SCL PTB3 00032 #define PIN_SDA PTB4 00033 #elif defined (TARGET_NUCLEO_F411RE) 00034 #define PIN_SCL PB_8 00035 #define PIN_SDA PB_9 00036 #else 00037 #error TARGET NOT DEFINED 00038 #endif 00039 00040 int main() { 00041 uint16_t result = 0 ; 00042 int16_t temperature = 0 ; 00043 FXAS21002 FXAS21002(PIN_SDA, PIN_SCL, FXAS21002_I2C_ADDRESS) ; 00044 00045 while(1) { 00046 result = FXAS21002.getValue(&temperature) ; 00047 printf("Temp %d C\n", temperature) ; 00048 wait(1) ; 00049 } 00050 } 00051 * @endcode 00052 */ 00053 class FXAS21002 00054 { 00055 public: 00056 /** 00057 * FXAS21002 constructor 00058 * 00059 * @param sda SDA pin 00060 * @param sdl SCL pin 00061 * @param addr addr of the I2C peripheral 00062 */ 00063 FXAS21002(PinName sda, PinName scl, int addr); 00064 00065 /** 00066 * FXAS21002 destructor 00067 */ 00068 ~FXAS21002(); 00069 00070 /** 00071 * status register 00072 */ 00073 uint8_t getStatus(void) ; 00074 00075 /** 00076 * getX returns the value of 00077 * REG_OUT_X_MSB 00078 * REG_OUT_X_LSB 00079 * as a signed 16bit integer 00080 */ 00081 int16_t getX(void) ; 00082 00083 /** 00084 * getY returns the value of 00085 * REG_OUT_Y_MSB 00086 * REG_OUT_Y_LSB 00087 * as a signed 16bit integer 00088 */ 00089 int16_t getY(void) ; 00090 00091 /** 00092 * getZ returns the value of 00093 * REG_OUT_Z_MSB 00094 * REG_OUT_Z_LSB 00095 * as a signed 16bit integer 00096 */ 00097 int16_t getZ(void) ; 00098 00099 /** 00100 * activate/deactivate the sensor 00101 * 00102 * @param mode true: Active false: Standby 00103 */ 00104 void activate(bool mode) ; 00105 00106 /** 00107 * Self-Test enable 00108 * 00109 * @param mode true: Self-Test enabled, false: Self-Test disabled 00110 */ 00111 void selftest(bool mode) ; 00112 00113 /** 00114 * Standby/Ready mode selection 00115 * 00116 * @param mode true: Ready, false: Standby 00117 */ 00118 void ready(bool mode) ; 00119 00120 /** 00121 * get value of CTRL_REG1 00122 */ 00123 uint8_t getCTRL1(void) ; 00124 00125 /** 00126 * set value to CTRL_REG1 00127 * 00128 * @param value value for CTRL_REG1 00129 */ 00130 void setCTRL1(uint8_t value) ; 00131 00132 /** 00133 * get value of CTRL_REG2 00134 */ 00135 uint8_t getCTRL2(void) ; 00136 00137 /** 00138 * set value to CTRL_REG2 00139 * 00140 * @param value value for CTRL_REG2 00141 */ 00142 void setCTRL2(uint8_t value) ; 00143 00144 /** 00145 * get value of CTRL_REG3 00146 */ 00147 uint8_t getCTRL3(void) ; 00148 00149 /** 00150 * set value to CTRL_REG3 00151 * 00152 * @param value value for CTRL_REG3 00153 */ 00154 void setCTRL3(uint8_t value) ; 00155 00156 00157 00158 private: 00159 I2C m_i2c; 00160 int m_addr; 00161 void readRegs(int addr, uint8_t * data, int len); 00162 void writeRegs(uint8_t * data, int len); 00163 00164 }; 00165 00166 #endif
Generated on Thu Jul 14 2022 03:46:15 by
