初めてのライブラリなので中身は....
Dependents: LowpassFilter_test
LIS3DH.h@1:afcf1d34de29, 2015-03-30 (annotated)
- Committer:
- tknara
- Date:
- Mon Mar 30 15:33:16 2015 +0000
- Revision:
- 1:afcf1d34de29
- Parent:
- 0:40a6dc4f47d1
OK; ;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
tknara | 1:afcf1d34de29 | 1 | #ifndef LIS3DH_H |
tknara | 1:afcf1d34de29 | 2 | #define LIS3DH_H |
tknara | 0:40a6dc4f47d1 | 3 | |
tknara | 0:40a6dc4f47d1 | 4 | #include "mbed.h" |
tknara | 0:40a6dc4f47d1 | 5 | |
tknara | 0:40a6dc4f47d1 | 6 | // addr |
tknara | 0:40a6dc4f47d1 | 7 | #define WRITE_ADDR 0x30 |
tknara | 0:40a6dc4f47d1 | 8 | #define READ_ADDR 0x31 |
tknara | 0:40a6dc4f47d1 | 9 | // LIS3DH ID |
tknara | 0:40a6dc4f47d1 | 10 | #define I_AM_LIS3DH 0x33 |
tknara | 0:40a6dc4f47d1 | 11 | |
tknara | 0:40a6dc4f47d1 | 12 | // Register's definition |
tknara | 0:40a6dc4f47d1 | 13 | #define LIS3DH_STATUS_REG_AUX 0x07 |
tknara | 0:40a6dc4f47d1 | 14 | #define LIS3DH_OUT_ADC1_L 0x08 |
tknara | 0:40a6dc4f47d1 | 15 | #define LIS3DH_OUT_ADC1_H 0x09 |
tknara | 0:40a6dc4f47d1 | 16 | #define LIS3DH_OUT_ADC2_L 0x0a |
tknara | 0:40a6dc4f47d1 | 17 | #define LIS3DH_OUT_ADC2_H 0x0b |
tknara | 0:40a6dc4f47d1 | 18 | #define LIS3DH_OUT_ADC3_L 0x0c |
tknara | 0:40a6dc4f47d1 | 19 | #define LIS3DH_OUT_ADC3_H 0x0d |
tknara | 0:40a6dc4f47d1 | 20 | #define LIS3DH_INT_COUNTER_REG 0x0e |
tknara | 0:40a6dc4f47d1 | 21 | #define LIS3DH_WHO_AM_I 0x0f |
tknara | 0:40a6dc4f47d1 | 22 | #define LIS3DH_TEMP_CFG_REG 0x1f |
tknara | 0:40a6dc4f47d1 | 23 | #define LIS3DH_CTRL_REG1 0x20 |
tknara | 0:40a6dc4f47d1 | 24 | #define LIS3DH_CTRL_REG2 0x21 |
tknara | 0:40a6dc4f47d1 | 25 | #define LIS3DH_CTRL_REG3 0x22 |
tknara | 0:40a6dc4f47d1 | 26 | #define LIS3DH_CTRL_REG4 0x23 |
tknara | 0:40a6dc4f47d1 | 27 | #define LIS3DH_CTRL_REG5 0x24 |
tknara | 0:40a6dc4f47d1 | 28 | #define LIS3DH_CTRL_REG6 0x25 |
tknara | 0:40a6dc4f47d1 | 29 | #define LIS3DH_REFERENCE 0x26 |
tknara | 0:40a6dc4f47d1 | 30 | #define LIS3DH_STATUS_REG2 0x27 |
tknara | 0:40a6dc4f47d1 | 31 | #define LIS3DH_OUT_X_L 0x28 |
tknara | 0:40a6dc4f47d1 | 32 | #define LIS3DH_OUT_X_H 0x29 |
tknara | 0:40a6dc4f47d1 | 33 | #define LIS3DH_OUT_Y_L 0x2a |
tknara | 0:40a6dc4f47d1 | 34 | #define LIS3DH_OUT_Y_H 0x2b |
tknara | 0:40a6dc4f47d1 | 35 | #define LIS3DH_OUT_Z_L 0x2c |
tknara | 0:40a6dc4f47d1 | 36 | #define LIS3DH_OUT_Z_H 0x2d |
tknara | 0:40a6dc4f47d1 | 37 | #define LIS3DH_FIFO_CTRL_REG 0x2e |
tknara | 0:40a6dc4f47d1 | 38 | #define LIS3DH_FIFO_SRC_REG 0x2f |
tknara | 0:40a6dc4f47d1 | 39 | #define LIS3DH_INT1_CFG 0x30 |
tknara | 0:40a6dc4f47d1 | 40 | #define LIS3DH_INT1_SOURCE 0x31 |
tknara | 0:40a6dc4f47d1 | 41 | #define LIS3DH_INT1_THS 0x32 |
tknara | 0:40a6dc4f47d1 | 42 | #define LIS3DH_INT1_DURATION 0x33 |
tknara | 0:40a6dc4f47d1 | 43 | #define LIS3DH_CLICK_CFG 0x38 |
tknara | 0:40a6dc4f47d1 | 44 | #define LIS3DH_CLICK_SRC 0x39 |
tknara | 0:40a6dc4f47d1 | 45 | #define LIS3DH_CLICK_THS 0x3a |
tknara | 0:40a6dc4f47d1 | 46 | #define LIS3DH_TIME_LIMIT 0x3b |
tknara | 0:40a6dc4f47d1 | 47 | #define LIS3DH_TIME_LATENCY 0x3c |
tknara | 0:40a6dc4f47d1 | 48 | #define LIS3DH_TIME_WINDOW 0x3d |
tknara | 0:40a6dc4f47d1 | 49 | |
tknara | 0:40a6dc4f47d1 | 50 | // definition for Nomalization |
tknara | 0:40a6dc4f47d1 | 51 | #define LIS3DH_SENSITIVITY_2G (0.001F) |
tknara | 0:40a6dc4f47d1 | 52 | #define LIS3DH_SENSITIVITY_4G (0.002F) |
tknara | 0:40a6dc4f47d1 | 53 | #define LIS3DH_SENSITIVITY_8G (0.004F) |
tknara | 0:40a6dc4f47d1 | 54 | #define LIS3DH_SENSITIVITY_16G (0.012F) |
tknara | 0:40a6dc4f47d1 | 55 | /** Create a LIS3DH instance connected to specified I2C pins with specified address |
tknara | 0:40a6dc4f47d1 | 56 | * |
tknara | 0:40a6dc4f47d1 | 57 | * @param sda I2C-bus SDA pin |
tknara | 0:40a6dc4f47d1 | 58 | * @param scl I2C-bus SCL pin |
tknara | 0:40a6dc4f47d1 | 59 | */ |
tknara | 0:40a6dc4f47d1 | 60 | class LIS3DH |
tknara | 0:40a6dc4f47d1 | 61 | { |
tknara | 0:40a6dc4f47d1 | 62 | public: |
tknara | 1:afcf1d34de29 | 63 | LIS3DH(PinName sda, PinName scl ); |
tknara | 0:40a6dc4f47d1 | 64 | int start(void); |
tknara | 0:40a6dc4f47d1 | 65 | void read_data(float a[]); |
tknara | 0:40a6dc4f47d1 | 66 | private: |
tknara | 0:40a6dc4f47d1 | 67 | I2C i2c; |
tknara | 0:40a6dc4f47d1 | 68 | char dbf[2],addr; |
tknara | 0:40a6dc4f47d1 | 69 | }; |
tknara | 0:40a6dc4f47d1 | 70 | #endif //LIS3DH |
tknara | 0:40a6dc4f47d1 | 71 | /*sample main.cpp code |
tknara | 0:40a6dc4f47d1 | 72 | |
tknara | 0:40a6dc4f47d1 | 73 | #include "mbed.h" |
tknara | 0:40a6dc4f47d1 | 74 | #include "LIS3DH.h" |
tknara | 0:40a6dc4f47d1 | 75 | |
tknara | 0:40a6dc4f47d1 | 76 | LIS3DH I2c(p9,p10); //sda,scl |
tknara | 0:40a6dc4f47d1 | 77 | Serial pc(USBTX,USBRX); |
tknara | 0:40a6dc4f47d1 | 78 | int main(){ |
tknara | 0:40a6dc4f47d1 | 79 | int check; |
tknara | 0:40a6dc4f47d1 | 80 | check = I2c.start(); |
tknara | 0:40a6dc4f47d1 | 81 | if (check == 1) { |
tknara | 0:40a6dc4f47d1 | 82 | while(1) { |
tknara | 0:40a6dc4f47d1 | 83 | float dt[2]; |
tknara | 0:40a6dc4f47d1 | 84 | I2c.read_data(dt); |
tknara | 0:40a6dc4f47d1 | 85 | pc.printf("X=%f __Y=%f __Z=%f \n",dt[0],dt[1],dt[2]); |
tknara | 0:40a6dc4f47d1 | 86 | wait(1); |
tknara | 0:40a6dc4f47d1 | 87 | } |
tknara | 0:40a6dc4f47d1 | 88 | } |
tknara | 0:40a6dc4f47d1 | 89 | } |
tknara | 0:40a6dc4f47d1 | 90 | */ |