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: FRDM-STBC-AGMP01_SensorStream Hexi_Accelero_Magneto_Example A_Dragonfly_Freescale_Accel_Mag_Gyro_Sensor_AGM01 A_Dragonfly_BlueMix_QuickStart_NXP_Sensor ... more
FXOS8700.cpp
00001 /* 00002 * Copyright (c) 2015 - 2016, Freescale Semiconductor, Inc. 00003 * Copyright 2016-2017 NXP 00004 * 00005 * Redistribution and use in source and binary forms, with or without modification, 00006 * are permitted provided that the following conditions are met: 00007 * 00008 * o Redistributions of source code must retain the above copyright notice, this list 00009 * of conditions and the following disclaimer. 00010 * 00011 * o Redistributions in binary form must reproduce the above copyright notice, this 00012 * list of conditions and the following disclaimer in the documentation and/or 00013 * other materials provided with the distribution. 00014 * 00015 * o Neither the name of the copyright holder nor the names of its 00016 * contributors may be used to endorse or promote products derived from this 00017 * software without specific prior written permission. 00018 * 00019 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 00020 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 00021 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00022 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 00023 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 00024 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00025 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 00026 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00027 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00028 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00029 */ 00030 00031 #include "FXOS8700.h" 00032 #include "mbed.h" 00033 00034 FXOS8700::FXOS8700(PinName sda, PinName scl) : accelmagi2c(sda,scl) 00035 { 00036 00037 } 00038 00039 void FXOS8700::accel_config(void) 00040 { 00041 char d[2]; 00042 d[0] = FXOS8700_CTRL_REG1; //Puts device in Standby mode 00043 d[1] = 0x00; 00044 accelmagi2c.write(FXOS8700_I2C_ADDRESS, d,2); 00045 00046 00047 d[0] = FXOS8700_CTRL_REG1; //Puts device in Active mode 00048 d[1] = 0x01; 00049 accelmagi2c.write(FXOS8700_I2C_ADDRESS, d, 2); 00050 00051 } 00052 00053 void FXOS8700::mag_config(void) 00054 { 00055 char d[2]; 00056 d[0] = FXOS8700_CTRL_REG1; //Puts device in Standby mode 00057 d[1] = 0x00; 00058 accelmagi2c.write(FXOS8700_I2C_ADDRESS, d,2); 00059 00060 00061 d[0] = FXOS8700_M_CTRL_REG1; //Puts device in hybrid mode (both accel and mag are active) 00062 d[1] = 0x03; 00063 accelmagi2c.write(FXOS8700_I2C_ADDRESS, d, 2); 00064 00065 00066 d[0] = FXOS8700_CTRL_REG1; //Puts device in Active mode 00067 d[1] = 0x01; 00068 accelmagi2c.write(FXOS8700_I2C_ADDRESS, d,2); 00069 00070 } 00071 00072 void FXOS8700::acquire_accel_data_g(float * a_data) 00073 { 00074 00075 char data_bytes[7]; 00076 char d[1]; 00077 d[0]=FXOS8700_STATUS; 00078 accelmagi2c.write(FXOS8700_I2C_ADDRESS,d,1,true); // Read the 6 data bytes - LSB and MSB for X, Y and Z Axes. 00079 accelmagi2c.read(FXOS8700_I2C_ADDRESS,data_bytes,7); 00080 00081 a_data[0] = ((float)((int16_t)(((data_bytes[1]*256) + (data_bytes[2])))>> 2) * 0.000244); 00082 a_data[1] = ((float)((int16_t)(((data_bytes[3]*256) + (data_bytes[4])))>> 2) * 0.000244); 00083 a_data[2] = ((float)((int16_t)(((data_bytes[5]*256) + (data_bytes[6])))>> 2) * 0.000244); 00084 00085 } 00086 00087 void FXOS8700::acquire_mag_data_uT(float * m_data) 00088 { 00089 00090 char data_bytes[7]; 00091 char d[1]; 00092 d[0]=FXOS8700_MDR_STATUS; 00093 accelmagi2c.write(FXOS8700_I2C_ADDRESS,d,1,true); // Read the 6 data bytes - LSB and MSB for X, Y and Z Axes. 00094 accelmagi2c.read(FXOS8700_I2C_ADDRESS,data_bytes,7); 00095 00096 m_data[0] = (float)((int16_t)((data_bytes[1]*256) + (data_bytes[2]))) * 0.1; 00097 m_data[1] = (float)((int16_t)((data_bytes[3]*256) + (data_bytes[4]))) * 0.1; 00098 m_data[2] = (float)((int16_t)((data_bytes[5]*256) + (data_bytes[6]))) * 0.1; 00099 00100 } 00101 00102
Generated on Wed Jul 13 2022 01:26:14 by
1.7.2
FRDM-STBC-AGM01: 9-Axis IMU