An in-development library to provide effective access to all features of the FXOS8700CQ on the FRDM-K64F mbed-enabled development board. As of 28 May 2014 1325EDT, the code should be generally usable and modifiable.

Dependents:   fxos8700cq_example frdm_fxos8700_logger AVC_test1 frdm_accel ... more

A basic implementation of accessing the FXOS8700CQ. This should be useable, but as the Apache License says, don't expect it to be good at doing anything, even what it's supposed to do.

Committer:
trm
Date:
Wed May 28 13:40:59 2014 +0000
Revision:
1:3ec7e2676e48
Parent:
0:cf6299acfe98
Child:
2:4c2f8a3549a9
Added comments for API documentation.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
trm 0:cf6299acfe98 1 #ifndef FXOS8700CQ_H
trm 0:cf6299acfe98 2 #define FXOS8700CQ_H
trm 0:cf6299acfe98 3
trm 0:cf6299acfe98 4 #include "mbed.h" // Building this for the mbed platform
trm 0:cf6299acfe98 5
trm 0:cf6299acfe98 6 #define I2C_400K 400000
trm 0:cf6299acfe98 7
trm 0:cf6299acfe98 8 // FXOS8700CQ I2C address
trm 0:cf6299acfe98 9 #define FXOS8700CQ_SLAVE_ADDR0 (0x1E<<1) // with pins SA0=0, SA1=0
trm 0:cf6299acfe98 10 #define FXOS8700CQ_SLAVE_ADDR1 (0x1D<<1) // with pins SA0=1, SA1=0
trm 0:cf6299acfe98 11 #define FXOS8700CQ_SLAVE_ADDR2 (0x1C<<1) // with pins SA0=0, SA1=1
trm 0:cf6299acfe98 12 #define FXOS8700CQ_SLAVE_ADDR3 (0x1F<<1) // with pins SA0=1, SA1=1
trm 0:cf6299acfe98 13
trm 0:cf6299acfe98 14 // FXOS8700CQ internal register addresses
trm 0:cf6299acfe98 15 #define FXOS8700CQ_STATUS 0x00
trm 0:cf6299acfe98 16 #define FXOS8700CQ_OUT_X_MSB 0x01
trm 0:cf6299acfe98 17 #define FXOS8700CQ_WHOAMI 0x0D
trm 0:cf6299acfe98 18 #define FXOS8700CQ_XYZ_DATA_CFG 0x0E
trm 0:cf6299acfe98 19 #define FXOS8700CQ_CTRL_REG1 0x2A
trm 0:cf6299acfe98 20 #define FXOS8700CQ_CTRL_REG2 0x2B
trm 0:cf6299acfe98 21 #define FXOS8700CQ_CTRL_REG3 0x2C
trm 0:cf6299acfe98 22 #define FXOS8700CQ_CTRL_REG4 0x2D
trm 0:cf6299acfe98 23 #define FXOS8700CQ_CTRL_REG5 0x2E
trm 0:cf6299acfe98 24
trm 0:cf6299acfe98 25 #define FXOS8700CQ_M_OUT_X_MSB 0x34
trm 0:cf6299acfe98 26
trm 0:cf6299acfe98 27 #define FXOS8700CQ_M_CTRL_REG1 0x5B
trm 0:cf6299acfe98 28 #define FXOS8700CQ_M_CTRL_REG2 0x5C
trm 0:cf6299acfe98 29 #define FXOS8700CQ_M_CTRL_REG3 0x5D
trm 0:cf6299acfe98 30
trm 0:cf6299acfe98 31 // FXOS8700CQ WHOAMI production register value
trm 0:cf6299acfe98 32 #define FXOS8700CQ_WHOAMI_VAL 0xC7
trm 0:cf6299acfe98 33
trm 0:cf6299acfe98 34 // 6 channels of two bytes = 12 bytes; read from FXOS8700CQ_OUT_X_MSB
trm 0:cf6299acfe98 35 #define FXOS8700CQ_READ_LEN 12
trm 0:cf6299acfe98 36
trm 0:cf6299acfe98 37 // From mbed I2C documentation for complete read/write transactions
trm 0:cf6299acfe98 38 #define I2C_SUCCESS 0
trm 0:cf6299acfe98 39 #define I2C_FAILURE 1
trm 0:cf6299acfe98 40
trm 0:cf6299acfe98 41 // For processing the accelerometer data to right-justified 2's complement
trm 0:cf6299acfe98 42 #define UINT14_MAX 16383
trm 0:cf6299acfe98 43
trm 0:cf6299acfe98 44 // TODO: struct to hold the data out of the sensor
trm 0:cf6299acfe98 45 typedef struct {
trm 0:cf6299acfe98 46 int16_t x;
trm 0:cf6299acfe98 47 int16_t y;
trm 0:cf6299acfe98 48 int16_t z;
trm 0:cf6299acfe98 49 } SRAWDATA;
trm 0:cf6299acfe98 50
trm 1:3ec7e2676e48 51
trm 1:3ec7e2676e48 52 /**
trm 1:3ec7e2676e48 53 * A driver on top of mbed-I2C to operate the FXOS8700CQ accelerometer/magnetometer
trm 1:3ec7e2676e48 54 * on the FRDM-K64F.
trm 1:3ec7e2676e48 55 *
trm 1:3ec7e2676e48 56 * Warning: incomplete code!
trm 1:3ec7e2676e48 57 */
trm 0:cf6299acfe98 58 class FXOS8700CQ
trm 0:cf6299acfe98 59 {
trm 0:cf6299acfe98 60 public:
trm 0:cf6299acfe98 61 /**
trm 0:cf6299acfe98 62 * FXOS8700CQ constructor
trm 0:cf6299acfe98 63 *
trm 0:cf6299acfe98 64 * @param sda SDA pin
trm 0:cf6299acfe98 65 * @param sdl SCL pin
trm 0:cf6299acfe98 66 * @param addr address of the I2C peripheral in (7-bit << 1) form
trm 0:cf6299acfe98 67 */
trm 0:cf6299acfe98 68
trm 0:cf6299acfe98 69 FXOS8700CQ(PinName sda, PinName scl, int addr);
trm 0:cf6299acfe98 70
trm 0:cf6299acfe98 71 /**
trm 0:cf6299acfe98 72 * FXOS8700CQ destructor
trm 0:cf6299acfe98 73 */
trm 0:cf6299acfe98 74 ~FXOS8700CQ();
trm 0:cf6299acfe98 75
trm 0:cf6299acfe98 76 void enable(void);
trm 0:cf6299acfe98 77 void disable(void);
trm 0:cf6299acfe98 78 uint8_t get_whoami(void);
trm 0:cf6299acfe98 79 uint8_t status(void);
trm 1:3ec7e2676e48 80
trm 1:3ec7e2676e48 81 /**
trm 1:3ec7e2676e48 82 * Data retrieval from the FXOS8700CQ
trm 1:3ec7e2676e48 83 *
trm 1:3ec7e2676e48 84 * @param accel_data destination XYZ accelerometer data struct
trm 1:3ec7e2676e48 85 * @param magn_data destination XYZ magnetometer data struct
trm 1:3ec7e2676e48 86 */
trm 0:cf6299acfe98 87 void get_data(SRAWDATA *accel_data, SRAWDATA *magn_data);
trm 0:cf6299acfe98 88
trm 0:cf6299acfe98 89
trm 0:cf6299acfe98 90
trm 0:cf6299acfe98 91 private:
trm 0:cf6299acfe98 92 I2C dev_i2c; // instance of the mbed I2C class
trm 0:cf6299acfe98 93 uint8_t dev_addr; // Device I2C address, in (7-bit << 1) form
trm 0:cf6299acfe98 94
trm 0:cf6299acfe98 95 // I2C helper methods
trm 0:cf6299acfe98 96 void read_regs(int reg_addr, uint8_t* data, int len);
trm 0:cf6299acfe98 97 void write_regs(uint8_t* data, int len);
trm 0:cf6299acfe98 98
trm 0:cf6299acfe98 99 };
trm 0:cf6299acfe98 100
trm 0:cf6299acfe98 101 #endif