Taylor Helton / FXOS8700

Dependents:   Hexi

Fork of FXOS8700 by Aswin Sivakumar

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers FXOS8700.cpp Source File

FXOS8700.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 "FXOS8700.h"
00020  #include "mbed.h"
00021 
00022 FXOS8700::FXOS8700(PinName sda, PinName scl) : accelmagi2c(sda,scl)
00023  {
00024        
00025  }
00026     
00027  void FXOS8700::accel_config(void)
00028  {
00029    char d[2]; 
00030    d[0] = FXOS8700_CTRL_REG1;                     //Puts device in Standby mode
00031    d[1] = 0x00; 
00032    accelmagi2c.write(FXOS8700_I2C_ADDRESS, d,2);   
00033           
00034    
00035    d[0] = FXOS8700_CTRL_REG1;                     //Puts device in Active mode
00036    d[1] = 0x01;
00037    accelmagi2c.write(FXOS8700_I2C_ADDRESS, d, 2);   
00038       
00039  }
00040  
00041  
00042  void FXOS8700::acquire_accel_data_g(float * a_data)
00043  {
00044   
00045    char data_bytes[7];
00046    char d[1];
00047    d[0]=FXOS8700_STATUS;
00048    accelmagi2c.write(FXOS8700_I2C_ADDRESS,d,1,true);  // Read the 6 data bytes - LSB and MSB for X, Y and Z Axes.
00049    accelmagi2c.read(FXOS8700_I2C_ADDRESS,data_bytes,7);
00050    
00051    a_data[0] =  (((int16_t)(((data_bytes[1]*256) + (data_bytes[2])))>> 2) * 0.000244);
00052    a_data[1] =  (((int16_t)(((data_bytes[3]*256) + (data_bytes[4])))>> 2) * 0.000244);
00053    a_data[2] =  (((int16_t)(((data_bytes[5]*256) + (data_bytes[6])))>> 2) * 0.000244);
00054    
00055  }
00056      
00057