A basic library for the FXOS8700Q combination accelerometer / magnetometer

Dependencies:   MotionSensor

Dependents:   K64F_eCompass_LCD Hello_FXOS8700Q rtos_compass K64F_eCompass ... more

This library supports the 6 axis combination Accelerometer / Magnetometer. Functions are provided to retrieve data in raw 16 bit signed integers or unit converted G's and micro-teslas



File content as of revision 2:ab84f99086e5:

#ifndef FXOS8700Q_H
#define FXOS8700Q_H

#include "mbed.h"
// FXOS8700CQ I2C address
#define FXOS8700CQ_SLAVE_ADDR0 (0x1E<<1) // with pins SA0=0, SA1=0
#define FXOS8700CQ_SLAVE_ADDR1 (0x1D<<1) // with pins SA0=1, SA1=0
#define FXOS8700CQ_SLAVE_ADDR2 (0x1C<<1) // with pins SA0=0, SA1=1
#define FXOS8700CQ_SLAVE_ADDR3 (0x1F<<1) // with pins SA0=1, SA1=1
// FXOS8700CQ internal register addresses
#define FXOS8700Q_STATUS 0x00
#define FXOS8700Q_OUT_X_MSB 0x01
#define FXOS8700Q_OUT_Y_MSB 0x03
#define FXOS8700Q_OUT_Z_MSB 0x05
#define FXOS8700Q_M_OUT_X_MSB 0x33
#define FXOS8700Q_M_OUT_Y_MSB 0x35
#define FXOS8700Q_M_OUT_Z_MSB 0x37
#define FXOS8700Q_WHOAMI 0x0D
#define FXOS8700Q_XYZ_DATA_CFG 0x0E
#define FXOS8700Q_CTRL_REG1 0x2A
#define FXOS8700Q_M_CTRL_REG1 0x5B
#define FXOS8700Q_M_CTRL_REG2 0x5C
#define FXOS8700Q_WHOAMI_VAL 0xC7

class FXOS8700Q
  * FXOS8700Q constructor
  * @param sda SDA pin
  * @param sdl SCL pin
  * @param addr addr of the I2C peripheral
  FXOS8700Q(PinName sda, PinName scl, int addr);

  * FXOS8700Q destructor

   * Get the value of the WHO_AM_I register
   * @returns WHO_AM_I value
  uint8_t getWhoAmI();

   * Get X axis acceleration
   * @returns X axis acceleration
  float getAccX();

   * Get Y axis acceleration
   * @returns Y axis acceleration
  float getAccY();

   * Get Z axis acceleration
   * @returns Z axis acceleration
  float getAccZ();

   * Get XYZ axis acceleration
   * @param res array where acceleration data will be stored
   void enable(void);
  void getAccAllAxis(float * res);
  void AccXYZraw(int16_t * d);
  void MagXYZraw(int16_t * d);
  void readRegs(int addr, uint8_t * data, int len);
  I2C m_i2c;
  int m_addr;

  void writeRegs(uint8_t * data, int len);
  int16_t getAccAxis(uint8_t addr);