Library for interfacing with NXP FXOS8700CQ accelerometer/magnetometer

Dependents:   Stick_Runner Stick_Runner 2645_FXOS8700CQ_Library AccGyroTest ... more

Committer:
eencae
Date:
Mon Feb 06 08:41:24 2017 +0000
Revision:
2:1a98f69712e8
Parent:
1:09311e0a2c64
Removed unused method declarations from the library header.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
eencae 1:09311e0a2c64 1 /** @file FXOS8700CQ.h
eencae 1:09311e0a2c64 2
eencae 1:09311e0a2c64 3 @ brief FXOS8700CQ Library
eencae 1:09311e0a2c64 4
eencae 1:09311e0a2c64 5 @author Dr Craig A. Evans
eencae 1:09311e0a2c64 6 @brief (c) University of Leeds, Jan 2017
eencae 1:09311e0a2c64 7
eencae 1:09311e0a2c64 8 @code
eencae 1:09311e0a2c64 9
eencae 1:09311e0a2c64 10 #include "mbed.h"
eencae 1:09311e0a2c64 11 #include "FXOS8700CQ.h"
eencae 1:09311e0a2c64 12
eencae 1:09311e0a2c64 13 // create object and specifiy pins
eencae 1:09311e0a2c64 14 FXOS8700CQ device(I2C_SDA,I2C_SCL);
eencae 0:f66eda6a492a 15
eencae 1:09311e0a2c64 16 int main()
eencae 1:09311e0a2c64 17 {
eencae 1:09311e0a2c64 18 // call initialisation method
eencae 1:09311e0a2c64 19 device.init();
eencae 0:f66eda6a492a 20
eencae 1:09311e0a2c64 21 while (1) {
eencae 1:09311e0a2c64 22
eencae 1:09311e0a2c64 23 // poll the sensor and get the values, storing in a struct
eencae 1:09311e0a2c64 24 Data values = device.get_values();
eencae 1:09311e0a2c64 25
eencae 1:09311e0a2c64 26 // print each struct member over serial
eencae 1:09311e0a2c64 27 printf("ax = %f ay = %f az = %f | mx = %f my = %f mz = %f\n"
eencae 1:09311e0a2c64 28 ,values.ax, values.ay, values.az
eencae 1:09311e0a2c64 29 ,values.mx, values.my, values.mz);
eencae 1:09311e0a2c64 30
eencae 1:09311e0a2c64 31 wait(0.5);
eencae 1:09311e0a2c64 32 }
eencae 1:09311e0a2c64 33 }
eencae 1:09311e0a2c64 34
eencae 1:09311e0a2c64 35 @endcode
eencae 0:f66eda6a492a 36
eencae 0:f66eda6a492a 37 */
eencae 0:f66eda6a492a 38
eencae 0:f66eda6a492a 39 #ifndef FXOS8700CQ_H
eencae 0:f66eda6a492a 40 #define FXOS8700CQ_H
eencae 0:f66eda6a492a 41
eencae 0:f66eda6a492a 42 #include "mbed.h"
eencae 0:f66eda6a492a 43
eencae 0:f66eda6a492a 44 // mbed API uses 8-bit addresses so need to left-shift 7-bit addresses by 1
eencae 0:f66eda6a492a 45 #define FXOS8700CQ_ADDR (0x1D << 1) // for K64F board
eencae 0:f66eda6a492a 46 // values from 13.2 datasheet
eencae 0:f66eda6a492a 47 #define FXOS8700CQ_STATUS 0x00
eencae 0:f66eda6a492a 48 #define FXOS8700CQ_WHO_AM_I 0x0D
eencae 0:f66eda6a492a 49 #define FXOS8700CQ_XYZ_DATA_CFG 0x0E
eencae 0:f66eda6a492a 50 #define FXOS8700CQ_CTRL_REG1 0x2A
eencae 0:f66eda6a492a 51 #define FXOS8700CQ_M_CTRL_REG1 0x5B
eencae 0:f66eda6a492a 52 #define FXOS8700CQ_M_CTRL_REG2 0x5C
eencae 0:f66eda6a492a 53 #define FXOS8700CQ_WHO_AM_I_VAL 0xC7
eencae 0:f66eda6a492a 54 #define FXOS8700CQ_READ_LEN 13
eencae 0:f66eda6a492a 55
eencae 0:f66eda6a492a 56 #define PI 3.14159265359f
eencae 0:f66eda6a492a 57 #define RAD2DEG 57.2957795131f
eencae 0:f66eda6a492a 58
eencae 0:f66eda6a492a 59 struct Data {
eencae 0:f66eda6a492a 60 float ax;
eencae 0:f66eda6a492a 61 float ay;
eencae 0:f66eda6a492a 62 float az;
eencae 0:f66eda6a492a 63 float mx;
eencae 0:f66eda6a492a 64 float my;
eencae 0:f66eda6a492a 65 float mz;
eencae 0:f66eda6a492a 66 };
eencae 0:f66eda6a492a 67
eencae 0:f66eda6a492a 68 class FXOS8700CQ
eencae 0:f66eda6a492a 69 {
eencae 0:f66eda6a492a 70
eencae 0:f66eda6a492a 71 public:
eencae 0:f66eda6a492a 72 FXOS8700CQ(PinName sda, PinName scl);
eencae 0:f66eda6a492a 73 ~FXOS8700CQ();
eencae 0:f66eda6a492a 74 void init();
eencae 0:f66eda6a492a 75 Data get_values();
eencae 0:f66eda6a492a 76
eencae 0:f66eda6a492a 77 private:
eencae 0:f66eda6a492a 78 I2C* i2c;
eencae 0:f66eda6a492a 79
eencae 0:f66eda6a492a 80 void send_byte_to_reg(char byte,char reg);
eencae 0:f66eda6a492a 81 char read_byte_from_reg(char reg);
eencae 0:f66eda6a492a 82 void read_bytes_from_reg(char reg,int number_of_bytes,char bytes[]);
eencae 0:f66eda6a492a 83 };
eencae 0:f66eda6a492a 84
eencae 0:f66eda6a492a 85 #endif