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