9 void __lis3dh_write_regsiter(uint8_t i2c_addr,uint8_t reg_addr,uint8_t reg_value)
14 uint8_t __lis3dh_read_register(uint8_t i2c_addr,uint8_t reg_addr)
28 void LIS3DH_EnableXYZ(uint8_t i2c_addr,uint8_t data_rate,uint8_t fullscale,uint8_t hi_res)
30 __lis3dh_write_regsiter(i2c_addr,LIS3SH_REG_CTRL_REG1,((data_rate & 0x0F) << 4) | 0x07);
31 __lis3dh_write_regsiter(i2c_addr,LIS3DH_REG_CTRL_REG4,((fullscale & 0x03) << 4) | ((hi_res & 0x01) << 3));
34 void LIS3DH_EnableDRDYonINT2(uint8_t i2c_addr)
37 __lis3dh_write_regsiter(i2c_addr,LIS3DH_REG_CTRL_REG3,(1<<4));
39 __lis3dh_write_regsiter(i2c_addr,LIS3DH_REG_CTRL_REG6,(1<<6));
42 inline int16_t extend_sign_10bit(uint16_t value)
46 return value | 0xFC00;
62 inline uint16_t collect_int_10bit(uint8_t data_L,uint8_t data_H)
64 return ((((uint16_t)data_L) >> 6) | (((uint16_t)data_H) << 2));
73 #ifndef INVERT_XY_AXES
74 (*X) = extend_sign_10bit(collect_int_10bit(data_XYZ[0],data_XYZ[1]));
75 (*Y) = extend_sign_10bit(collect_int_10bit(data_XYZ[2],data_XYZ[3]));
77 (*X) = -extend_sign_10bit(collect_int_10bit(data_XYZ[0],data_XYZ[1]));
78 (*Y) = -extend_sign_10bit(collect_int_10bit(data_XYZ[2],data_XYZ[3]));
80 (*Z) = extend_sign_10bit(collect_int_10bit(data_XYZ[4],data_XYZ[5]));
83 uint8_t LIS3DH_XYZ_DataReady(uint8_t i2c_addr)
87 reg_value = __lis3dh_read_register(i2c_addr,LIS3DH_REG_STATUS_REG);
89 if (reg_value & (1<<3))