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