初めてのライブラリなので中身は....
Dependents: LowpassFilter_test
LIS3DH.cpp@0:40a6dc4f47d1, 2015-02-18 (annotated)
- Committer:
- tknara
- Date:
- Wed Feb 18 16:40:57 2015 +0000
- Revision:
- 0:40a6dc4f47d1
- Child:
- 1:afcf1d34de29
ver1;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
tknara | 0:40a6dc4f47d1 | 1 | #include "LIS3DH.h" |
tknara | 0:40a6dc4f47d1 | 2 | |
tknara | 0:40a6dc4f47d1 | 3 | LIS3DH::LIS3DH( PinName sda, PinName scl ) : i2c(sda, scl ) |
tknara | 0:40a6dc4f47d1 | 4 | { |
tknara | 0:40a6dc4f47d1 | 5 | } |
tknara | 0:40a6dc4f47d1 | 6 | |
tknara | 0:40a6dc4f47d1 | 7 | |
tknara | 0:40a6dc4f47d1 | 8 | int LIS3DH::start(void) |
tknara | 0:40a6dc4f47d1 | 9 | { |
tknara | 0:40a6dc4f47d1 | 10 | addr = WRITE_ADDR; |
tknara | 0:40a6dc4f47d1 | 11 | dbf[0] = LIS3DH_WHO_AM_I; |
tknara | 0:40a6dc4f47d1 | 12 | i2c.write(addr, dbf,1); |
tknara | 0:40a6dc4f47d1 | 13 | i2c.read(addr | 1, dbf, 1); |
tknara | 0:40a6dc4f47d1 | 14 | if (dbf[0] == I_AM_LIS3DH) { |
tknara | 0:40a6dc4f47d1 | 15 | return 1; |
tknara | 0:40a6dc4f47d1 | 16 | } |
tknara | 0:40a6dc4f47d1 | 17 | else { |
tknara | 0:40a6dc4f47d1 | 18 | return 0; |
tknara | 0:40a6dc4f47d1 | 19 | } |
tknara | 0:40a6dc4f47d1 | 20 | } |
tknara | 0:40a6dc4f47d1 | 21 | |
tknara | 0:40a6dc4f47d1 | 22 | void LIS3DH::read_data(float a[]) |
tknara | 0:40a6dc4f47d1 | 23 | { |
tknara | 0:40a6dc4f47d1 | 24 | char data[6]; |
tknara | 0:40a6dc4f47d1 | 25 | dbf[0] = LIS3DH_CTRL_REG1; |
tknara | 0:40a6dc4f47d1 | 26 | dbf[1] = 0x7f; |
tknara | 0:40a6dc4f47d1 | 27 | i2c.write(addr , dbf , 2); |
tknara | 0:40a6dc4f47d1 | 28 | dbf[0] = LIS3DH_OUT_X_L | 0x80; |
tknara | 0:40a6dc4f47d1 | 29 | i2c.write(addr, dbf, 1); |
tknara | 0:40a6dc4f47d1 | 30 | i2c.read(addr | 1, data, 6); |
tknara | 0:40a6dc4f47d1 | 31 | a[0] = float(short((data[1]<<8) | data[0])) *LIS3DH_SENSITIVITY_2G / 15; |
tknara | 0:40a6dc4f47d1 | 32 | a[1] = float(short((data[3]<<8) | data[2])) *LIS3DH_SENSITIVITY_2G / 15; |
tknara | 0:40a6dc4f47d1 | 33 | a[2] = float(short((data[5]<<8) | data[4])) *LIS3DH_SENSITIVITY_2G / 15; |
tknara | 0:40a6dc4f47d1 | 34 | } |