my own one

Fork of FXAS21002 by Weiqian Xu

Committer:
AswinSivakumar
Date:
Wed Dec 09 06:30:23 2015 +0000
Revision:
0:9c9e8aaad4ff
Child:
1:b774372b3913
Initial commit;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
AswinSivakumar 0:9c9e8aaad4ff 1 /* Copyright (c) 2010-2011 mbed.org, MIT License
AswinSivakumar 0:9c9e8aaad4ff 2 *
AswinSivakumar 0:9c9e8aaad4ff 3 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
AswinSivakumar 0:9c9e8aaad4ff 4 * and associated documentation files (the "Software"), to deal in the Software without
AswinSivakumar 0:9c9e8aaad4ff 5 * restriction, including without limitation the rights to use, copy, modify, merge, publish,
AswinSivakumar 0:9c9e8aaad4ff 6 * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
AswinSivakumar 0:9c9e8aaad4ff 7 * Software is furnished to do so, subject to the following conditions:
AswinSivakumar 0:9c9e8aaad4ff 8 *
AswinSivakumar 0:9c9e8aaad4ff 9 * The above copyright notice and this permission notice shall be included in all copies or
AswinSivakumar 0:9c9e8aaad4ff 10 * substantial portions of the Software.
AswinSivakumar 0:9c9e8aaad4ff 11 *
AswinSivakumar 0:9c9e8aaad4ff 12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
AswinSivakumar 0:9c9e8aaad4ff 13 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
AswinSivakumar 0:9c9e8aaad4ff 14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
AswinSivakumar 0:9c9e8aaad4ff 15 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
AswinSivakumar 0:9c9e8aaad4ff 16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
AswinSivakumar 0:9c9e8aaad4ff 17 */
AswinSivakumar 0:9c9e8aaad4ff 18
AswinSivakumar 0:9c9e8aaad4ff 19 #include "FXAS21002.h"
AswinSivakumar 0:9c9e8aaad4ff 20 #include "mbed.h"
AswinSivakumar 0:9c9e8aaad4ff 21
AswinSivakumar 0:9c9e8aaad4ff 22 FXAS21002::FXAS21002(PinName sda, PinName scl) : gyroi2c(sda,scl)
AswinSivakumar 0:9c9e8aaad4ff 23 {
AswinSivakumar 0:9c9e8aaad4ff 24
AswinSivakumar 0:9c9e8aaad4ff 25 }
AswinSivakumar 0:9c9e8aaad4ff 26
AswinSivakumar 0:9c9e8aaad4ff 27 void FXAS21002::gyro_config(void)
AswinSivakumar 0:9c9e8aaad4ff 28 {
AswinSivakumar 0:9c9e8aaad4ff 29 char d[2];
AswinSivakumar 0:9c9e8aaad4ff 30 d[0] = FXAS21002_CTRL_REG1; //Puts device in standby mode
AswinSivakumar 0:9c9e8aaad4ff 31 d[1] = 0x08;
AswinSivakumar 0:9c9e8aaad4ff 32 gyroi2c.write(FXAS21002_I2C_ADDRESS, d,2);
AswinSivakumar 0:9c9e8aaad4ff 33
AswinSivakumar 0:9c9e8aaad4ff 34
AswinSivakumar 0:9c9e8aaad4ff 35 d[0] = FXAS21002_CTRL_REG0; //sets FS =+/- 2000 dps
AswinSivakumar 0:9c9e8aaad4ff 36 d[1] = 0x00;
AswinSivakumar 0:9c9e8aaad4ff 37 gyroi2c.write(FXAS21002_I2C_ADDRESS, d, 2);
AswinSivakumar 0:9c9e8aaad4ff 38
AswinSivakumar 0:9c9e8aaad4ff 39
AswinSivakumar 0:9c9e8aaad4ff 40 d[0] = FXAS21002_CTRL_REG1; //Puts device in active mode
AswinSivakumar 0:9c9e8aaad4ff 41 d[1] = 0x0A;
AswinSivakumar 0:9c9e8aaad4ff 42 gyroi2c.write(FXAS21002_I2C_ADDRESS, d,2);
AswinSivakumar 0:9c9e8aaad4ff 43
AswinSivakumar 0:9c9e8aaad4ff 44 }
AswinSivakumar 0:9c9e8aaad4ff 45
AswinSivakumar 0:9c9e8aaad4ff 46 void FXAS21002::acquire_gyro_data_dps(float * g_data)
AswinSivakumar 0:9c9e8aaad4ff 47 {
AswinSivakumar 0:9c9e8aaad4ff 48
AswinSivakumar 0:9c9e8aaad4ff 49 char data_bytes[7];
AswinSivakumar 0:9c9e8aaad4ff 50 gyroi2c.write(FXAS21002_I2C_ADDRESS,FXAS21002_STATUS,1,true); // Read the 6 data bytes - LSB and MSB for X, Y and Z Axes.
AswinSivakumar 0:9c9e8aaad4ff 51 gyroi2c.read(FXAS21002_I2C_ADDRESS,data_bytes,7);
AswinSivakumar 0:9c9e8aaad4ff 52
AswinSivakumar 0:9c9e8aaad4ff 53 g_data[0] = (float)((int16_t)((data_bytes[1]*256) + (data_bytes[2]))) * 0.0625;
AswinSivakumar 0:9c9e8aaad4ff 54 g_data[1] = (float)((int16_t)((data_bytes[3]*256) + (data_bytes[4]))) * 0.0625;
AswinSivakumar 0:9c9e8aaad4ff 55 g_data[2] = (float)((int16_t)((data_bytes[5]*256) + (data_bytes[6]))) * 0.0625;
AswinSivakumar 0:9c9e8aaad4ff 56
AswinSivakumar 0:9c9e8aaad4ff 57 }
AswinSivakumar 0:9c9e8aaad4ff 58
AswinSivakumar 0:9c9e8aaad4ff 59
AswinSivakumar 0:9c9e8aaad4ff 60
AswinSivakumar 0:9c9e8aaad4ff 61