NOT FINISHED YET!!! My first try to get a self built fully working Quadrocopter based on an mbed, a self built frame and some other more or less cheap parts.
Sensors/Acc/ADXL345.h@26:96a072233d7a, 2012-11-27 (annotated)
- Committer:
- maetugr
- Date:
- Tue Nov 27 19:49:38 2012 +0000
- Revision:
- 26:96a072233d7a
- Parent:
- 20:e116e596e540
- Child:
- 33:fd98776b6cc7
IMU_Filter and Mixer now new appart from the main
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
maetugr | 2:93f703d2c4d7 | 1 | // based on http://mbed.org/users/Digixx/code/ADXL345/ |
maetugr | 2:93f703d2c4d7 | 2 | |
maetugr | 2:93f703d2c4d7 | 3 | #ifndef ADXL345_H |
maetugr | 2:93f703d2c4d7 | 4 | #define ADXL345_H |
maetugr | 2:93f703d2c4d7 | 5 | |
maetugr | 2:93f703d2c4d7 | 6 | #include "mbed.h" |
maetugr | 2:93f703d2c4d7 | 7 | |
maetugr | 2:93f703d2c4d7 | 8 | // register addresses |
maetugr | 20:e116e596e540 | 9 | #define ADXL345_DEVID_REG 0x00 |
maetugr | 20:e116e596e540 | 10 | #define ADXL345_THRESH_TAP_REG 0x1D |
maetugr | 20:e116e596e540 | 11 | #define ADXL345_OFSX_REG 0x1E |
maetugr | 20:e116e596e540 | 12 | #define ADXL345_OFSY_REG 0x1F |
maetugr | 20:e116e596e540 | 13 | #define ADXL345_OFSZ_REG 0x20 |
maetugr | 20:e116e596e540 | 14 | #define ADXL345_DUR_REG 0x21 |
maetugr | 20:e116e596e540 | 15 | #define ADXL345_LATENT_REG 0x22 |
maetugr | 20:e116e596e540 | 16 | #define ADXL345_WINDOW_REG 0x23 |
maetugr | 20:e116e596e540 | 17 | #define ADXL345_THRESH_ACT_REG 0x24 |
maetugr | 20:e116e596e540 | 18 | #define ADXL345_THRESH_INACT_REG 0x25 |
maetugr | 20:e116e596e540 | 19 | #define ADXL345_TIME_INACT_REG 0x26 |
maetugr | 20:e116e596e540 | 20 | #define ADXL345_ACT_INACT_CTL_REG 0x27 |
maetugr | 20:e116e596e540 | 21 | #define ADXL345_THRESH_FF_REG 0x28 |
maetugr | 20:e116e596e540 | 22 | #define ADXL345_TIME_FF_REG 0x29 |
maetugr | 20:e116e596e540 | 23 | #define ADXL345_TAP_AXES_REG 0x2A |
maetugr | 20:e116e596e540 | 24 | #define ADXL345_ACT_TAP_STATUS_REG 0x2B |
maetugr | 20:e116e596e540 | 25 | #define ADXL345_BW_RATE_REG 0x2C |
maetugr | 20:e116e596e540 | 26 | #define ADXL345_POWER_CTL_REG 0x2D |
maetugr | 20:e116e596e540 | 27 | #define ADXL345_INT_ENABLE_REG 0x2E |
maetugr | 20:e116e596e540 | 28 | #define ADXL345_INT_MAP_REG 0x2F |
maetugr | 20:e116e596e540 | 29 | #define ADXL345_INT_SOURCE_REG 0x30 |
maetugr | 20:e116e596e540 | 30 | #define ADXL345_DATA_FORMAT_REG 0x31 |
maetugr | 20:e116e596e540 | 31 | #define ADXL345_DATAX0_REG 0x32 |
maetugr | 20:e116e596e540 | 32 | #define ADXL345_DATAX1_REG 0x33 |
maetugr | 20:e116e596e540 | 33 | #define ADXL345_DATAY0_REG 0x34 |
maetugr | 20:e116e596e540 | 34 | #define ADXL345_DATAY1_REG 0x35 |
maetugr | 20:e116e596e540 | 35 | #define ADXL345_DATAZ0_REG 0x36 |
maetugr | 20:e116e596e540 | 36 | #define ADXL345_DATAZ1_REG 0x37 |
maetugr | 20:e116e596e540 | 37 | #define ADXL345_FIFO_CTL 0x38 |
maetugr | 20:e116e596e540 | 38 | #define ADXL345_FIFO_STATUS 0x39 |
maetugr | 2:93f703d2c4d7 | 39 | |
maetugr | 2:93f703d2c4d7 | 40 | // data rate codes |
maetugr | 2:93f703d2c4d7 | 41 | #define ADXL345_3200HZ 0x0F |
maetugr | 2:93f703d2c4d7 | 42 | #define ADXL345_1600HZ 0x0E |
maetugr | 2:93f703d2c4d7 | 43 | #define ADXL345_800HZ 0x0D |
maetugr | 2:93f703d2c4d7 | 44 | #define ADXL345_400HZ 0x0C |
maetugr | 2:93f703d2c4d7 | 45 | #define ADXL345_200HZ 0x0B |
maetugr | 2:93f703d2c4d7 | 46 | #define ADXL345_100HZ 0x0A |
maetugr | 2:93f703d2c4d7 | 47 | #define ADXL345_50HZ 0x09 |
maetugr | 2:93f703d2c4d7 | 48 | #define ADXL345_25HZ 0x08 |
maetugr | 2:93f703d2c4d7 | 49 | #define ADXL345_12HZ5 0x07 |
maetugr | 2:93f703d2c4d7 | 50 | #define ADXL345_6HZ25 0x06 |
maetugr | 2:93f703d2c4d7 | 51 | |
maetugr | 20:e116e596e540 | 52 | // read or write bytes |
maetugr | 20:e116e596e540 | 53 | #define ADXL345_READ 0xA7 |
maetugr | 20:e116e596e540 | 54 | #define ADXL345_WRITE 0xA6 |
maetugr | 20:e116e596e540 | 55 | #define ADXL345_ADDRESS 0x53 |
maetugr | 20:e116e596e540 | 56 | |
maetugr | 2:93f703d2c4d7 | 57 | //the ADXL345 7-bit address is 0x53 when ALT ADDRESS is low as it is on the sparkfun chip: when ALT ADDRESS is high the address is 0x1D |
maetugr | 2:93f703d2c4d7 | 58 | //when ALT ADDRESS pin is high: |
maetugr | 2:93f703d2c4d7 | 59 | //#define ADXL345_READ 0x3B |
maetugr | 2:93f703d2c4d7 | 60 | //#define ADXL345_WRITE 0x3A |
maetugr | 2:93f703d2c4d7 | 61 | //#define ADXL345_ADDRESS 0x1D |
maetugr | 2:93f703d2c4d7 | 62 | |
maetugr | 2:93f703d2c4d7 | 63 | #define ADXL345_X 0x00 |
maetugr | 2:93f703d2c4d7 | 64 | #define ADXL345_Y 0x01 |
maetugr | 2:93f703d2c4d7 | 65 | #define ADXL345_Z 0x02 |
maetugr | 2:93f703d2c4d7 | 66 | |
maetugr | 20:e116e596e540 | 67 | typedef char byte; |
maetugr | 20:e116e596e540 | 68 | |
maetugr | 20:e116e596e540 | 69 | class ADXL345 |
maetugr | 2:93f703d2c4d7 | 70 | { |
maetugr | 2:93f703d2c4d7 | 71 | public: |
maetugr | 20:e116e596e540 | 72 | ADXL345(PinName sda, PinName scl); // constructor, uses i2c |
maetugr | 20:e116e596e540 | 73 | void read(); // read all axis to array |
maetugr | 20:e116e596e540 | 74 | int data[3]; // where the measured data is saved |
maetugr | 2:93f703d2c4d7 | 75 | |
maetugr | 2:93f703d2c4d7 | 76 | private: |
maetugr | 20:e116e596e540 | 77 | I2C i2c; // i2c object to communicate |
maetugr | 20:e116e596e540 | 78 | void writeReg(byte reg, byte value); // write one single register to sensor |
maetugr | 20:e116e596e540 | 79 | byte readReg(byte reg); // read one single register from sensor |
maetugr | 20:e116e596e540 | 80 | void readMultiReg(char startAddress, char* ptr_output, int size); // read multiple regs |
maetugr | 20:e116e596e540 | 81 | void setDataRate(char rate); // data rate configuration (not only a reg to write) |
maetugr | 2:93f703d2c4d7 | 82 | }; |
maetugr | 2:93f703d2c4d7 | 83 | |
maetugr | 2:93f703d2c4d7 | 84 | #endif |