my own one
Fork of FXAS21002 by
Embed:
(wiki syntax)
Show/hide line numbers
FXAS21002.cpp
00001 /* Copyright (c) 2015 NXP Semiconductors. MIT License 00002 * 00003 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software 00004 * and associated documentation files (the "Software"), to deal in the Software without 00005 * restriction, including without limitation the rights to use, copy, modify, merge, publish, 00006 * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the 00007 * Software is furnished to do so, subject to the following conditions: 00008 * 00009 * The above copyright notice and this permission notice shall be included in all copies or 00010 * substantial portions of the Software. 00011 * 00012 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING 00013 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 00014 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 00015 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00016 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 00017 */ 00018 00019 #include "FXAS21002.h" 00020 #include "mbed.h" 00021 00022 FXAS21002::FXAS21002(PinName sda, PinName scl) : gyroi2c(sda,scl) 00023 { 00024 00025 } 00026 00027 void FXAS21002::gyro_config(void) 00028 { 00029 char d[2]; 00030 d[0] = FXAS21002_CTRL_REG1; //Puts device in standby mode 00031 d[1] = 0x08; 00032 gyroi2c.write(FXAS21002_I2C_ADDRESS, d,2); 00033 00034 00035 d[0] = FXAS21002_CTRL_REG0; //sets FS =+/- 1000 dps 00036 d[1] = 0x00; 00037 gyroi2c.write(FXAS21002_I2C_ADDRESS, d, 2); 00038 00039 00040 d[0] = FXAS21002_CTRL_REG1; //Puts device in active mode 00041 d[1] = 0x0A; 00042 gyroi2c.write(FXAS21002_I2C_ADDRESS, d,2); 00043 00044 } 00045 00046 void FXAS21002::acquire_gyro_data_dps(float * g_data) 00047 { 00048 00049 char data_bytes[7]; 00050 gyroi2c.write(FXAS21002_I2C_ADDRESS,FXAS21002_STATUS,1,true); // Read the 6 data bytes - LSB and MSB for X, Y and Z Axes. 00051 gyroi2c.read(FXAS21002_I2C_ADDRESS,data_bytes,7); 00052 00053 g_data[0] = (float)((int16_t)((data_bytes[1]*256) + (data_bytes[2]))) * 0.0625; 00054 g_data[1] = (float)((int16_t)((data_bytes[3]*256) + (data_bytes[4]))) * 0.0625; 00055 g_data[2] = (float)((int16_t)((data_bytes[5]*256) + (data_bytes[6]))) * 0.0625; 00056 00057 } 00058 00059 00060 00061
Generated on Thu Aug 18 2022 14:36:08 by
1.7.2
