Temperature/humidity/pressure values broadcast using BMP180 & Si7021 and onboard temperature sensor

Dependencies:   BLE_API TMP_nrf51 mbed nRF51822

Fork of VTT_NODEV3_LIS3DH by Juho Eskeli

Files at this revision

API Documentation at this revision

Comitter:
jejuho
Date:
Mon Jan 25 14:36:57 2016 +0000
Parent:
1:bd7fd35251ab
Commit message:
Initial version. Values from sensors not verified. Some problems with Si7021.

Changed in this revision

BMP180.h Show annotated file Show diff for this revision Revisions of this file
LEDService.h Show diff for this revision Revisions of this file
LIS3DH.cpp Show diff for this revision Revisions of this file
LIS3DH.h Show diff for this revision Revisions of this file
Si7021.cpp Show annotated file Show diff for this revision Revisions of this file
Si7021.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r bd7fd35251ab -r b221ba23b37f BMP180.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/BMP180.h	Mon Jan 25 14:36:57 2016 +0000
@@ -0,0 +1,164 @@
+#ifndef BMP180_H
+#define BMP180_H
+ 
+#include "mbed.h"
+
+#define BMP180_ADDRESS          0x77<<1 // I2C address of BMP180, eight bit address on mbed
+#define BMP180_WHO_AM_I         0xD0    // WHO_AM_I id of BMP180, should return 0x55
+#define BMP180_RESET            0xE0
+#define BMP180_CONTROL          0xF4
+#define BMP180_OUT_MSB          0xF6
+#define BMP180_OUT_LSB          0xF7
+#define BMP180_OUT_XLSB         0xF8
+
+// Set initial input parameters
+
+enum OSS {  // BMP-085 sampling rate
+  OSS_0 = 0,  // 4.5 ms conversion time
+  OSS_1,      // 7.5
+  OSS_2,      // 13.5
+  OSS_3       // 25.5
+};
+
+uint8_t OSS = OSS_3;           // maximum pressure resolution
+    
+// These are constants used to calculate the temperature and pressure from the BMP-180 sensor
+int16_t ac1, ac2, ac3, b1, b2, mb, mc, md, b5;  
+uint16_t ac4, ac5, ac6;
+
+class BMP180 {
+
+  private:
+    //Set up I2C, (SDA,SCL)
+    I2C i2c;
+ 
+    protected:
+ 
+    public:
+
+    BMP180(PinName sda, PinName scl) : i2c(sda, scl) {
+     
+    }
+
+
+
+  //===================================================================================================================
+//====== Set of useful function to access pressure and temperature data
+//===================================================================================================================
+
+    void writeByte(uint8_t address, uint8_t subAddress, uint8_t data)
+{
+   char data_write[2];
+   data_write[0] = subAddress;
+   data_write[1] = data;
+   i2c.write(address, data_write, 2, 0);
+}
+
+    char readByte(uint8_t address, uint8_t subAddress)
+{
+    char data[1]; // `data` will store the register data     
+    char data_write[1];
+    data_write[0] = subAddress;
+    i2c.write(address, data_write, 1, 1); // no stop
+    i2c.read(address, data, 1, 0); 
+    return data[0]; 
+}
+
+    void readBytes(uint8_t address, uint8_t subAddress, uint8_t count, uint8_t * dest)
+{     
+    char data[14];
+    char data_write[1];
+    data_write[0] = subAddress;
+    i2c.write(address, data_write, 1, 1); // no stop
+    i2c.read(address, data, count, 0); 
+    for(int ii = 0; ii < count; ii++) {
+     dest[ii] = data[ii];
+    }
+} 
+ 
+
+// Stores all of the BMP180's calibration values into global variables
+// Calibration values are required to calculate temp and pressure
+// This function should be called at the beginning of the program
+// These BMP-180 functions were adapted from Jim Lindblom of SparkFun Electronics
+void BMP180Calibration()
+{
+  ac1 = readByte(BMP180_ADDRESS, 0xAA) << 8 | readByte(BMP180_ADDRESS, 0xAB);
+  ac2 = readByte(BMP180_ADDRESS, 0xAC) << 8 | readByte(BMP180_ADDRESS, 0xAD);
+  ac3 = readByte(BMP180_ADDRESS, 0xAE) << 8 | readByte(BMP180_ADDRESS, 0xAF);
+  ac4 = readByte(BMP180_ADDRESS, 0xB0) << 8 | readByte(BMP180_ADDRESS, 0xB1);
+  ac5 = readByte(BMP180_ADDRESS, 0xB2) << 8 | readByte(BMP180_ADDRESS, 0xB3);
+  ac6 = readByte(BMP180_ADDRESS, 0xB4) << 8 | readByte(BMP180_ADDRESS, 0xB5);
+  b1  = readByte(BMP180_ADDRESS, 0xB6) << 8 | readByte(BMP180_ADDRESS, 0xB7);
+  b2  = readByte(BMP180_ADDRESS, 0xB8) << 8 | readByte(BMP180_ADDRESS, 0xB9);
+  mb  = readByte(BMP180_ADDRESS, 0xBA) << 8 | readByte(BMP180_ADDRESS, 0xBB);
+  mc  = readByte(BMP180_ADDRESS, 0xBC) << 8 | readByte(BMP180_ADDRESS, 0xBD);
+  md  = readByte(BMP180_ADDRESS, 0xBE) << 8 | readByte(BMP180_ADDRESS, 0xBF);
+}
+
+  // Temperature returned will be in units of 0.1 deg C
+  int16_t BMP180GetTemperature()
+  {
+  int16_t ut = 0;
+  writeByte(BMP180_ADDRESS, 0xF4, 0x2E); // start temperature measurement
+  wait(0.005);
+
+  uint8_t rawData[2] = {0, 0};
+  readBytes(BMP180_ADDRESS, 0xF6, 2, &rawData[0]); // read raw temperature measurement
+  ut = (((int16_t) rawData[0] << 8) | rawData[1]);
+ 
+ long x1, x2;
+  
+  x1 = (((long)ut - (long)ac6)*(long)ac5) >> 15;
+  x2 = ((long)mc << 11)/(x1 + md);
+  b5 = x1 + x2;
+
+  return  ((b5 + 8)>>4);  
+}
+
+// Calculate pressure read calibration values  
+// b5 is also required so BMP180GetTemperature() must be called first.
+// Value returned will be pressure in units of Pa.
+long BMP180GetPressure()
+{
+  long up = 0;
+  writeByte(BMP180_ADDRESS, 0xF4, 0x34 | OSS << 6); // Configure pressure measurement for highest resolution
+  wait((5.0f + 8.0f*3.0f)/1000.0f);  
+  uint8_t rawData[3] = {0, 0, 0};
+  readBytes(BMP180_ADDRESS, 0xF6, 3, &rawData[0]); // read raw pressure measurement of 19 bits
+  up = (((long) rawData[0] << 16) | ((long)rawData[1] << 8) | rawData[2]) >> (8 - OSS);
+
+  long x1, x2, x3, b3, b6, p;
+  unsigned long b4, b7;
+  
+  b6 = b5 - 4000;
+  // Calculate B3
+  x1 = (b2 * (b6 * b6)>>12)>>11;
+  x2 = (ac2 * b6)>>11;
+  x3 = x1 + x2;
+  b3 = (((((long)ac1)*4 + x3)<<OSS) + 2)>>2;
+  
+  // Calculate B4
+  x1 = (ac3 * b6)>>13;
+  x2 = (b1 * ((b6 * b6)>>12))>>16;
+  x3 = ((x1 + x2) + 2)>>2;
+  b4 = (ac4 * (unsigned long)(x3 + 32768))>>15;
+  
+  b7 = ((unsigned long)(up - b3) * (50000>>OSS));
+  if (b7 < 0x80000000)
+    p = (b7<<1)/b4;
+  else
+    p = (b7/b4)<<1;
+    
+  x1 = (p>>8) * (p>>8);
+  x1 = (x1 * 3038)>>16;
+  x2 = (-7357 * p)>>16;
+  p += (x1 + x2 + 3791)>>4;
+  
+  return p;
+}      
+
+ 
+ 
+  };
+#endif
diff -r bd7fd35251ab -r b221ba23b37f LEDService.h
--- a/LEDService.h	Mon Jan 25 13:27:15 2016 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,42 +0,0 @@
-/* mbed Microcontroller Library
- * Copyright (c) 2006-2013 ARM Limited
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef __BLE_LED_SERVICE_H__
-#define __BLE_LED_SERVICE_H__
-
-class LEDService {
-public:
-    const static uint16_t LED_SERVICE_UUID              = 0xA000;
-    const static uint16_t LED_STATE_CHARACTERISTIC_UUID = 0xA001;
-
-    LEDService(BLEDevice &_ble, bool initialValueForLEDCharacteristic) :
-        ble(_ble), ledState(LED_STATE_CHARACTERISTIC_UUID, &initialValueForLEDCharacteristic)
-    {
-        GattCharacteristic *charTable[] = {&ledState};
-        GattService         ledService(LED_SERVICE_UUID, charTable, sizeof(charTable) / sizeof(GattCharacteristic *));
-        ble.addService(ledService);
-    }
-
-    GattAttribute::Handle_t getValueHandle() const {
-        return ledState.getValueHandle();
-    }
-
-private:
-    BLEDevice                         &ble;
-    ReadWriteGattCharacteristic<bool>  ledState;
-};
-
-#endif /* #ifndef __BLE_LED_SERVICE_H__ */
diff -r bd7fd35251ab -r b221ba23b37f LIS3DH.cpp
--- a/LIS3DH.cpp	Mon Jan 25 13:27:15 2016 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1614 +0,0 @@
-#include "LIS3DH.h"
-
-LIS3DH::LIS3DH(PinName mosi, PinName miso, PinName ss, PinName sck):  _spi(mosi,miso,sck), _ss(ss){
-    // Make sure CS is high
-    _ss = 1; 
-    // Setup the spi for 8 bit data, high steady state clock,
-    // second edge capture, with a 1MHz clock rate
-    _spi.format(8,3);                   
-    _spi.frequency(8000000);        
-
-  
-}
-
-u8_t LIS3DH::InitLIS3DH(LIS3DH_Mode_t Mode, LIS3DH_ODR_t Odr, LIS3DH_Fullscale_t Grange)
-{
-    uint8_t response;
-    uint8_t Tmp;
-    
-    LIS3DH_GetWHO_AM_I(&Tmp);
-    
-    response = LIS3DH_SetODR(Odr);
-    
-    //set PowerMode 
-    response = LIS3DH_SetMode(Mode);
-    
-    //set Fullscale
-    response = LIS3DH_SetFullScale(Grange);
-    
-    //set axis Enable
-    response = LIS3DH_SetAxis(LIS3DH_X_ENABLE | LIS3DH_Y_ENABLE | LIS3DH_Z_ENABLE);
-    
-    return response;
-}
-
-/*******************************************************************************
-* Function Name  : LIS3DH_GetStatusAUX
-* Description    : Read the AUX status register
-* Input          : Char to empty by status register buffer
-* Output         : None
-* Return         : Status [MEMS_ERROR, MEMS_SUCCESS]
-*******************************************************************************/
-status_t LIS3DH::LIS3DH_GetStatusAUX(u8_t* val) {
-  
-  if( !LIS3DH_ReadReg(LIS3DH_STATUS_AUX, val) )
-    return MEMS_ERROR;
-  
-  return MEMS_SUCCESS;  
-}
-
-/*******************************************************************************
-* Function Name  : LIS3DH_GetStatusAUXBIT
-* Description    : Read the AUX status register BIT
-* Input          : LIS3DH_STATUS_AUX_321OR, LIS3DH_STATUS_AUX_3OR, LIS3DH_STATUS_AUX_2OR, LIS3DH_STATUS_AUX_1OR,
-                   LIS3DH_STATUS_AUX_321DA, LIS3DH_STATUS_AUX_3DA, LIS3DH_STATUS_AUX_2DA, LIS3DH_STATUS_AUX_1DA
-* Output         : None
-* Return         : Status of BIT [MEMS_ERROR, MEMS_SUCCESS]
-*******************************************************************************/
-status_t LIS3DH::LIS3DH_GetStatusAUXBit(u8_t statusBIT, u8_t* val) {
-  u8_t value;  
-  
-  if( !LIS3DH_ReadReg(LIS3DH_STATUS_AUX, &value) )
-    return MEMS_ERROR;
-  
-  if(statusBIT == LIS3DH_STATUS_AUX_321OR){
-    if(value &= LIS3DH_STATUS_AUX_321OR){     
-      *val = MEMS_SET;
-      return MEMS_SUCCESS;
-    }
-    else{  
-      *val = MEMS_RESET;
-      return MEMS_SUCCESS;
-    }   
-  }
-  
-  if(statusBIT == LIS3DH_STATUS_AUX_3OR){
-    if(value &= LIS3DH_STATUS_AUX_3OR){     
-      *val = MEMS_SET;
-      return MEMS_SUCCESS;
-    }
-    else{  
-      *val = MEMS_RESET;
-      return MEMS_SUCCESS;
-    }     
-  }
-  
-  if(statusBIT == LIS3DH_STATUS_AUX_2OR){
-    if(value &= LIS3DH_STATUS_AUX_2OR){     
-      *val = MEMS_SET;
-      return MEMS_SUCCESS;
-    }
-    else{  
-      *val = MEMS_RESET;
-      return MEMS_SUCCESS;
-    }    
-  }
-  
-  if(statusBIT == LIS3DH_STATUS_AUX_1OR){
-    if(value &= LIS3DH_STATUS_AUX_1OR){     
-      *val = MEMS_SET;
-      return MEMS_SUCCESS;
-    }
-    else{  
-      *val = MEMS_RESET;
-      return MEMS_SUCCESS;
-    }   
-  }
-  
-  if(statusBIT == LIS3DH_STATUS_AUX_321DA){
-    if(value &= LIS3DH_STATUS_AUX_321DA) {     
-      *val = MEMS_SET;
-      return MEMS_SUCCESS;
-    }
-    else{  
-      *val = MEMS_RESET;
-      return MEMS_SUCCESS;
-    }   
-  }
-  
-  if(statusBIT == LIS3DH_STATUS_AUX_3DA){
-    if(value &= LIS3DH_STATUS_AUX_3DA){     
-      *val = MEMS_SET;
-      return MEMS_SUCCESS;
-    }
-    else{  
-      *val = MEMS_RESET;
-      return MEMS_SUCCESS;
-    }   
-  }
-  
-  if(statusBIT == LIS3DH_STATUS_AUX_2DA){
-    if(value &= LIS3DH_STATUS_AUX_2DA){     
-      *val = MEMS_SET;
-      return MEMS_SUCCESS;
-    }
-    else{  
-      *val = MEMS_RESET;
-      return MEMS_SUCCESS;
-    }  
-  }
-  
-  if(statusBIT == LIS3DH_STATUS_AUX_1DA){
-    if(value &= LIS3DH_STATUS_AUX_1DA){     
-      *val = MEMS_SET;
-      return MEMS_SUCCESS;
-    }
-    else{  
-      *val = MEMS_RESET;
-      return MEMS_SUCCESS;
-    }  
-  }  
-  return MEMS_ERROR;
-}
-
-u8_t LIS3DH::SetLIS3DHActivityDetection(uint8_t Th, LIS3DH_Int1Mode_t Mode, uint8_t OnOff)
-{
-    uint8_t response;
-    
-    response = LIS3DH_SetInt1Pin(LIS3DH_CLICK_ON_PIN_INT1_DISABLE | LIS3DH_I1_INT1_ON_PIN_INT1_ENABLE |              
-                    LIS3DH_I1_INT2_ON_PIN_INT1_DISABLE | LIS3DH_I1_DRDY1_ON_INT1_DISABLE | LIS3DH_I1_DRDY2_ON_INT1_DISABLE |
-                    LIS3DH_WTM_ON_INT1_DISABLE | LIS3DH_INT1_OVERRUN_DISABLE );
-    
-    //set Interrupt Threshold   
-    response = LIS3DH_SetInt1Threshold(Th);
-        
- //set Interrupt configuration (all enabled)
-    if(OnOff)
-    {
-        response = LIS3DH_SetIntConfiguration(LIS3DH_INT1_ZHIE_ENABLE | LIS3DH_INT1_ZLIE_ENABLE |
-                                       LIS3DH_INT1_YHIE_ENABLE | LIS3DH_INT1_YLIE_ENABLE |
-                                       LIS3DH_INT1_XHIE_ENABLE | LIS3DH_INT1_XLIE_ENABLE ); 
-    }
-    else
-    {
-        response = LIS3DH_SetIntConfiguration(LIS3DH_INT1_ZHIE_DISABLE | LIS3DH_INT1_ZLIE_DISABLE |
-                                       LIS3DH_INT1_YHIE_DISABLE | LIS3DH_INT1_YLIE_DISABLE |
-                                       LIS3DH_INT1_XHIE_DISABLE | LIS3DH_INT1_XLIE_DISABLE ); 
-    }
-    
-    //set Interrupt Mode
-    response = LIS3DH_SetIntMode(Mode);
-    
-    return response;
-}
-
-/*******************************************************************************
-* Function Name  : LIS3DH_SetODR
-* Description    : Sets LIS3DH Output Data Rate
-* Input          : Output Data Rate
-* Output         : None
-* Return         : Status [MEMS_ERROR, MEMS_SUCCESS]
-*******************************************************************************/
-status_t LIS3DH::LIS3DH_SetODR(LIS3DH_ODR_t ov){
-  u8_t value;
-  
-  if( !LIS3DH_ReadReg(LIS3DH_CTRL_REG1, &value) )
-    return MEMS_ERROR;
-  
-  value &= 0x0f;
-  value |= ov<<LIS3DH_ODR_BIT;
-  
-  if( !LIS3DH_WriteReg(LIS3DH_CTRL_REG1, value) )
-    return MEMS_ERROR;
-  
-  return MEMS_SUCCESS;
-}
-
-/*******************************************************************************
-* Function Name  : LIS3DH_SetMode
-* Description    : Sets LIS3DH Operating Mode
-* Input          : Modality (LIS3DH_NORMAL, LIS3DH_LOW_POWER, LIS3DH_POWER_DOWN)
-* Output         : None
-* Return         : Status [MEMS_ERROR, MEMS_SUCCESS]
-*******************************************************************************/
-status_t LIS3DH::LIS3DH_SetMode(LIS3DH_Mode_t md) {
-  u8_t value;
-  u8_t value2;
-  static   u8_t ODR_old_value;
-  
-  if( !LIS3DH_ReadReg(LIS3DH_CTRL_REG1, &value) )
-    return MEMS_ERROR;
-  
-  if( !LIS3DH_ReadReg(LIS3DH_CTRL_REG4, &value2) )
-    return MEMS_ERROR;
-  
-  if((value & 0xF0)==0) 
-    value = value | (ODR_old_value & 0xF0); //if it comes from POWERDOWN  
-  
-  switch(md) {
-    
-  case LIS3DH_POWER_DOWN:
-    ODR_old_value = value;
-    value &= 0x0F;
-    break;
-    
-  case LIS3DH_NORMAL:
-    value &= 0xF7;
-    value |= (MEMS_RESET<<LIS3DH_LPEN);
-    value2 &= 0xF7;
-    value2 |= (MEMS_SET<<LIS3DH_HR);   //set HighResolution_BIT
-    break;
-    
-  case LIS3DH_LOW_POWER:        
-    value &= 0xF7;
-    value |=  (MEMS_SET<<LIS3DH_LPEN);
-    value2 &= 0xF7;
-    value2 |= (MEMS_RESET<<LIS3DH_HR); //reset HighResolution_BIT
-    break;
-    
-  default:
-    return MEMS_ERROR;
-  }
-  
-  if( !LIS3DH_WriteReg(LIS3DH_CTRL_REG1, value) )
-    return MEMS_ERROR;
-  
-  if( !LIS3DH_WriteReg(LIS3DH_CTRL_REG4, value2) )
-    return MEMS_ERROR;  
-  
-  return MEMS_SUCCESS;
-}
-
-/*******************************************************************************
-* Function Name  : LIS3DH_SetAxis
-* Description    : Enable/Disable LIS3DH Axis
-* Input          : LIS3DH_X_ENABLE/DISABLE | LIS3DH_Y_ENABLE/DISABLE | LIS3DH_Z_ENABLE/DISABLE
-* Output         : None
-* Note           : You MUST use all input variable in the argument, as example
-* Return         : Status [MEMS_ERROR, MEMS_SUCCESS]
-*******************************************************************************/
-status_t LIS3DH::LIS3DH_SetAxis(LIS3DH_Axis_t axis) {
-  u8_t value;
-  
-  if( !LIS3DH_ReadReg(LIS3DH_CTRL_REG1, &value) )
-    return MEMS_ERROR;
-  value &= 0xF8;
-  value |= (0x07 & axis);
-  
-  if( !LIS3DH_WriteReg(LIS3DH_CTRL_REG1, value) )
-    return MEMS_ERROR;   
-  
-  return MEMS_SUCCESS;
-}
-
-/*******************************************************************************
-* Function Name  : LIS3DH_SetFullScale
-* Description    : Sets the LIS3DH FullScale
-* Input          : LIS3DH_FULLSCALE_2/LIS3DH_FULLSCALE_4/LIS3DH_FULLSCALE_8/LIS3DH_FULLSCALE_16
-* Output         : None
-* Return         : Status [MEMS_ERROR, MEMS_SUCCESS]
-*******************************************************************************/
-status_t LIS3DH::LIS3DH_SetFullScale(LIS3DH_Fullscale_t fs) {
-  u8_t value;
-  
-  if( !LIS3DH_ReadReg(LIS3DH_CTRL_REG4, &value) )
-    return MEMS_ERROR;
-  
-  value &= 0xCF;    
-  value |= (fs<<LIS3DH_FS);
-  
-  if( !LIS3DH_WriteReg(LIS3DH_CTRL_REG4, value) )
-    return MEMS_ERROR;
-  
-  return MEMS_SUCCESS;
-}
-
-/*******************************************************************************
-* Function Name  : LIS3DH_SetBDU
-* Description    : Enable/Disable Block Data Update Functionality
-* Input          : ENABLE/DISABLE
-* Output         : None
-* Return         : Status [MEMS_ERROR, MEMS_SUCCESS]
-*******************************************************************************/
-status_t LIS3DH::LIS3DH_SetBDU(State_t bdu) {
-  u8_t value;
-  
-  if( !LIS3DH_ReadReg(LIS3DH_CTRL_REG4, &value) )
-    return MEMS_ERROR;
-  
-  value &= 0x7F;
-  value |= (bdu<<LIS3DH_BDU);
-  
-  if( !LIS3DH_WriteReg(LIS3DH_CTRL_REG4, value) )
-    return MEMS_ERROR;
-  
-  return MEMS_SUCCESS;
-}
-
-/*******************************************************************************
-* Function Name  : LIS3DH_SetBLE
-* Description    : Set Endianess (MSB/LSB)
-* Input          : BLE_LSB / BLE_MSB
-* Output         : None
-* Return         : Status [MEMS_ERROR, MEMS_SUCCESS]
-*******************************************************************************/
-status_t LIS3DH::LIS3DH_SetBLE(LIS3DH_Endianess_t ble) {
-  u8_t value;
-  
-  if( !LIS3DH_ReadReg(LIS3DH_CTRL_REG4, &value) )
-    return MEMS_ERROR;
-  
-  value &= 0xBF;  
-  value |= (ble<<LIS3DH_BLE);
-  
-  if( !LIS3DH_WriteReg(LIS3DH_CTRL_REG4, value) )
-    return MEMS_ERROR;
-  
-  return MEMS_SUCCESS;
-}
-
-/*******************************************************************************
-* Function Name  : LIS3DH_SetSelfTest
-* Description    : Set Self Test Modality
-* Input          : LIS3DH_SELF_TEST_DISABLE/ST_0/ST_1
-* Output         : None
-* Return         : Status [MEMS_ERROR, MEMS_SUCCESS]
-*******************************************************************************/
-status_t LIS3DH::LIS3DH_SetSelfTest(LIS3DH_SelfTest_t st) {
-  u8_t value;
-  
-  if( !LIS3DH_ReadReg(LIS3DH_CTRL_REG4, &value) )
-    return MEMS_ERROR;
-  
-  value &= 0xF9;
-  value |= (st<<LIS3DH_ST);
-  
-  if( !LIS3DH_WriteReg(LIS3DH_CTRL_REG4, value) )
-    return MEMS_ERROR;
-  
-  return MEMS_SUCCESS;
-}
-
-/*******************************************************************************
-* Function Name  : LIS3DH_HPFClick
-* Description    : Enable/Disable High Pass Filter for click
-* Input          : MEMS_ENABLE/MEMS_DISABLE
-* Output         : None
-* Return         : Status [MEMS_ERROR, MEMS_SUCCESS]
-*******************************************************************************/
-status_t LIS3DH::LIS3DH_HPFClickEnable(State_t hpfe) {
-  u8_t value;
-  
-  if( !LIS3DH_ReadReg(LIS3DH_CTRL_REG2, &value) )
-    return MEMS_ERROR;
-  
-  value &= 0xFB;
-  value |= (hpfe<<LIS3DH_HPCLICK);
-  
-  if( !LIS3DH_WriteReg(LIS3DH_CTRL_REG2, value) )
-    return MEMS_ERROR;
-  
-  return MEMS_SUCCESS;
-}
-
-
-/*******************************************************************************
-* Function Name  : LIS3DH_HPFAOI1
-* Description    : Enable/Disable High Pass Filter for AOI on INT_1
-* Input          : MEMS_ENABLE/MEMS_DISABLE
-* Output         : None
-* Return         : Status [MEMS_ERROR, MEMS_SUCCESS]
-*******************************************************************************/
-status_t LIS3DH::LIS3DH_HPFAOI1Enable(State_t hpfe) {
-  u8_t value;
-  
-  if( !LIS3DH_ReadReg(LIS3DH_CTRL_REG2, &value) )
-    return MEMS_ERROR;
-  
-  value &= 0xFE;
-  value |= (hpfe<<LIS3DH_HPIS1);
-  
-  if( !LIS3DH_WriteReg(LIS3DH_CTRL_REG2, value) )
-    return MEMS_ERROR;
-  
-  return MEMS_SUCCESS;
-}
-
-
-/*******************************************************************************
-* Function Name  : LIS3DH_HPFAOI2
-* Description    : Enable/Disable High Pass Filter for AOI on INT_2
-* Input          : MEMS_ENABLE/MEMS_DISABLE
-* Output         : None
-* Return         : Status [MEMS_ERROR, MEMS_SUCCESS]
-*******************************************************************************/
-status_t LIS3DH::LIS3DH_HPFAOI2Enable(State_t hpfe) {
-  u8_t value;
-  
-  if( !LIS3DH_ReadReg(LIS3DH_CTRL_REG2, &value) )
-    return MEMS_ERROR;
-  
-  value &= 0xFD;
-  value |= (hpfe<<LIS3DH_HPIS2);
-  
-  if( !LIS3DH_WriteReg(LIS3DH_CTRL_REG2, value) )
-    return MEMS_ERROR;
-  
-  return MEMS_SUCCESS;
-}
-
-/*******************************************************************************
-* Function Name  : LIS3DH_SetHPFMode
-* Description    : Set High Pass Filter Modality
-* Input          : LIS3DH_HPM_NORMAL_MODE_RES/LIS3DH_HPM_REF_SIGNAL/
-           LIS3DH_HPM_NORMAL_MODE/LIS3DH_HPM_AUTORESET_INT
-* Output         : None
-* Return         : Status [MEMS_ERROR, MEMS_SUCCESS]
-*******************************************************************************/
-status_t LIS3DH::LIS3DH_SetHPFMode(LIS3DH_HPFMode_t hpm) {
-  u8_t value;
-  
-  if( !LIS3DH_ReadReg(LIS3DH_CTRL_REG2, &value) )
-    return MEMS_ERROR;
-  
-  value &= 0x3F;
-  value |= (hpm<<LIS3DH_HPM);
-  
-  if( !LIS3DH_WriteReg(LIS3DH_CTRL_REG2, value) )
-    return MEMS_ERROR;
-  
-  return MEMS_SUCCESS;
-}
-
-
-/*******************************************************************************
-* Function Name  : LIS3DH_SetHPFCutOFF
-* Description    : Set High Pass CUT OFF Freq
-* Input          : HPFCF [0,3]
-* Output         : None
-* Return         : Status [MEMS_ERROR, MEMS_SUCCESS]
-*******************************************************************************/
-status_t LIS3DH::LIS3DH_SetHPFCutOFF(LIS3DH_HPFCutOffFreq_t hpf) {
-  u8_t value;
-  
-  if (hpf > 3)
-    return MEMS_ERROR;
-  
-  if( !LIS3DH_ReadReg(LIS3DH_CTRL_REG2, &value) )
-    return MEMS_ERROR;
-  
-  value &= 0xCF;
-  value |= (hpf<<LIS3DH_HPCF);
-  
-  if( !LIS3DH_WriteReg(LIS3DH_CTRL_REG2, value) )
-    return MEMS_ERROR;
-  
-  return MEMS_SUCCESS;
-  
-}
-
-/*******************************************************************************
-* Function Name  : LIS3DH_SetFilterDataSel
-* Description    : Set Filter Data Selection bypassed or sent to FIFO OUT register
-* Input          : MEMS_SET, MEMS_RESET
-* Output         : None
-* Return         : Status [MEMS_ERROR, MEMS_SUCCESS]
-*******************************************************************************/
-status_t LIS3DH::LIS3DH_SetFilterDataSel(State_t state) {
-  u8_t value;
-  
-  if( !LIS3DH_ReadReg(LIS3DH_CTRL_REG2, &value) )
-    return MEMS_ERROR;
-  
-  value &= 0xF7;
-  value |= (state<<LIS3DH_FDS);
-  
-  if( !LIS3DH_WriteReg(LIS3DH_CTRL_REG2, value) )
-    return MEMS_ERROR;
-  
-  return MEMS_SUCCESS;
-  
-}
-
-/*******************************************************************************
-* Function Name  : LIS3DH_SetTemperature
-* Description    : Sets LIS3DH Output Temperature
-* Input          : MEMS_ENABLE, MEMS_DISABLE
-* Output         : None
-* Note           : For Read Temperature by LIS3DH_OUT_AUX_3, LIS3DH_SetADCAux and LIS3DH_SetBDU 
-                   functions must be ENABLE
-* Return         : Status [MEMS_ERROR, MEMS_SUCCESS]
-*******************************************************************************/
-status_t LIS3DH::LIS3DH_SetTemperature(State_t state){
-  u8_t value;
-  
-  if( !LIS3DH_ReadReg(LIS3DH_TEMP_CFG_REG, &value) )
-    return MEMS_ERROR;
-  
-  value &= 0xBF;
-  value |= state<<LIS3DH_TEMP_EN;
-  
-  if( !LIS3DH_WriteReg(LIS3DH_TEMP_CFG_REG, value) )
-    return MEMS_ERROR;
-  
-  return MEMS_SUCCESS;
-}
-
-/*******************************************************************************
-* Function Name  : LIS3DH_SetADCAux
-* Description    : Sets LIS3DH Output ADC
-* Input          : MEMS_ENABLE, MEMS_DISABLE
-* Output         : None
-* Return         : Status [MEMS_ERROR, MEMS_SUCCESS]
-*******************************************************************************/
-status_t LIS3DH::LIS3DH_SetADCAux(State_t state){
-  u8_t value;
-  
-  if( !LIS3DH_ReadReg(LIS3DH_TEMP_CFG_REG, &value) )
-    return MEMS_ERROR;
-  
-  value &= 0x7F;
-  value |= state<<LIS3DH_ADC_PD;
-  
-  if( !LIS3DH_WriteReg(LIS3DH_TEMP_CFG_REG, value) )
-    return MEMS_ERROR;
-  
-  return MEMS_SUCCESS;
-}
-
-/*******************************************************************************
-* Function Name  : LIS3DH_GetAuxRaw
-* Description    : Read the Aux Values Output Registers
-* Input          : Buffer to empty
-* Output         : Aux Values Registers buffer
-* Return         : Status [MEMS_ERROR, MEMS_SUCCESS]
-*******************************************************************************/
-status_t LIS3DH::LIS3DH_GetAuxRaw(LIS3DH_Aux123Raw_t* buff) {
-  u8_t valueL;
-  u8_t valueH;
-  
-  if( !LIS3DH_ReadReg(LIS3DH_OUT_1_L, &valueL) )
-    return MEMS_ERROR;
-  
-  if( !LIS3DH_ReadReg(LIS3DH_OUT_1_H, &valueH) )
-    return MEMS_ERROR;
-  
-  buff->AUX_1 = (u16_t)( (valueH << 8) | valueL )/16;
-  
-  if( !LIS3DH_ReadReg(LIS3DH_OUT_2_L, &valueL) )
-    return MEMS_ERROR;
-  
-  if( !LIS3DH_ReadReg(LIS3DH_OUT_2_H, &valueH) )
-    return MEMS_ERROR;
-  
-  buff->AUX_2 = (u16_t)( (valueH << 8) | valueL )/16;
-  
-  if( !LIS3DH_ReadReg(LIS3DH_OUT_3_L, &valueL) )
-    return MEMS_ERROR;
-  
-  if( !LIS3DH_ReadReg(LIS3DH_OUT_3_H, &valueH) )
-    return MEMS_ERROR;
-  
-  buff->AUX_3 = (u16_t)( (valueH << 8) | valueL )/16;
-  
-  return MEMS_SUCCESS;  
-}
-
-/*******************************************************************************
-* Function Name  : LIS3DH_SetInt1Pin
-* Description    : Set Interrupt1 pin Function
-* Input          :  LIS3DH_CLICK_ON_PIN_INT1_ENABLE/DISABLE    | LIS3DH_I1_INT1_ON_PIN_INT1_ENABLE/DISABLE |              
-                    LIS3DH_I1_INT2_ON_PIN_INT1_ENABLE/DISABLE  | LIS3DH_I1_DRDY1_ON_INT1_ENABLE/DISABLE    |              
-                    LIS3DH_I1_DRDY2_ON_INT1_ENABLE/DISABLE     | LIS3DH_WTM_ON_INT1_ENABLE/DISABLE         |           
-                    LIS3DH_INT1_OVERRUN_ENABLE/DISABLE  
-* example        : SetInt1Pin(LIS3DH_CLICK_ON_PIN_INT1_ENABLE | LIS3DH_I1_INT1_ON_PIN_INT1_ENABLE |              
-                    LIS3DH_I1_INT2_ON_PIN_INT1_DISABLE | LIS3DH_I1_DRDY1_ON_INT1_ENABLE | LIS3DH_I1_DRDY2_ON_INT1_ENABLE |
-                    LIS3DH_WTM_ON_INT1_DISABLE | LIS3DH_INT1_OVERRUN_DISABLE   ) 
-* Note           : To enable Interrupt signals on INT1 Pad (You MUST use all input variable in the argument, as example)
-* Output         : None
-* Return         : Status [MEMS_ERROR, MEMS_SUCCESS]
-*******************************************************************************/
-status_t LIS3DH::LIS3DH_SetInt1Pin(LIS3DH_IntPinConf_t pinConf) {
-  u8_t value;
-  
-  if( !LIS3DH_ReadReg(LIS3DH_CTRL_REG3, &value) )
-    return MEMS_ERROR;
-  
-  value &= 0x00;
-  value |= pinConf;
-  
-  if( !LIS3DH_WriteReg(LIS3DH_CTRL_REG3, value) )
-    return MEMS_ERROR;
-  
-  return MEMS_SUCCESS;
-}
-
-
-/*******************************************************************************
-* Function Name  : LIS3DH_SetInt2Pin
-* Description    : Set Interrupt2 pin Function
-* Input          : LIS3DH_CLICK_ON_PIN_INT2_ENABLE/DISABLE   | LIS3DH_I2_INT1_ON_PIN_INT2_ENABLE/DISABLE |               
-                   LIS3DH_I2_INT2_ON_PIN_INT2_ENABLE/DISABLE | LIS3DH_I2_BOOT_ON_INT2_ENABLE/DISABLE |                   
-                   LIS3DH_INT_ACTIVE_HIGH/LOW
-* example        : LIS3DH_SetInt2Pin(LIS3DH_CLICK_ON_PIN_INT2_ENABLE/DISABLE | LIS3DH_I2_INT1_ON_PIN_INT2_ENABLE/DISABLE |               
-                   LIS3DH_I2_INT2_ON_PIN_INT2_ENABLE/DISABLE | LIS3DH_I2_BOOT_ON_INT2_ENABLE/DISABLE |                   
-                   LIS3DH_INT_ACTIVE_HIGH/LOW)
-* Note           : To enable Interrupt signals on INT2 Pad (You MUST use all input variable in the argument, as example)
-* Output         : None
-* Return         : Status [MEMS_ERROR, MEMS_SUCCESS]
-*******************************************************************************/
-status_t LIS3DH::LIS3DH_SetInt2Pin(LIS3DH_IntPinConf_t pinConf) {
-  u8_t value;
-  
-  if( !LIS3DH_ReadReg(LIS3DH_CTRL_REG6, &value) )
-    return MEMS_ERROR;
-  
-  value &= 0x00;
-  value |= pinConf;
-  
-  if( !LIS3DH_WriteReg(LIS3DH_CTRL_REG6, value) )
-    return MEMS_ERROR;
-  
-  return MEMS_SUCCESS;
-}
-
-/*******************************************************************************
-* Function Name  : LIS3DH_SetClickCFG
-* Description    : Set Click Interrupt config Function
-* Input          : LIS3DH_ZD_ENABLE/DISABLE | LIS3DH_ZS_ENABLE/DISABLE  | LIS3DH_YD_ENABLE/DISABLE  | 
-                   LIS3DH_YS_ENABLE/DISABLE | LIS3DH_XD_ENABLE/DISABLE  | LIS3DH_XS_ENABLE/DISABLE 
-* example        : LIS3DH_SetClickCFG( LIS3DH_ZD_ENABLE | LIS3DH_ZS_DISABLE | LIS3DH_YD_ENABLE | 
-                               LIS3DH_YS_DISABLE | LIS3DH_XD_ENABLE | LIS3DH_XS_ENABLE)
-* Note           : You MUST use all input variable in the argument, as example
-* Output         : None
-* Return         : Status [MEMS_ERROR, MEMS_SUCCESS]
-*******************************************************************************/
-status_t LIS3DH::LIS3DH_SetClickCFG(u8_t status) {
-  u8_t value;
-  
-  if( !LIS3DH_ReadReg(LIS3DH_CLICK_CFG, &value) )
-    return MEMS_ERROR;
-  
-  value &= 0xC0;
-  value |= status;
-  
-  if( !LIS3DH_WriteReg(LIS3DH_CLICK_CFG, value) )
-    return MEMS_ERROR;
-  
-  return MEMS_SUCCESS;
-}  
-
-
-/*******************************************************************************
-* Function Name  : LIS3DH_SetClickTHS
-* Description    : Set Click Interrupt threshold
-* Input          : Click-click Threshold value [0-127]
-* Output         : None
-* Return         : Status [MEMS_ERROR, MEMS_SUCCESS]
-*******************************************************************************/
-status_t LIS3DH::LIS3DH_SetClickTHS(u8_t ths) {
-  
-  if(ths>127)     
-    return MEMS_ERROR;
-  
-  if( !LIS3DH_WriteReg(LIS3DH_CLICK_THS, ths) )
-    return MEMS_ERROR;
-  
-  return MEMS_SUCCESS;
-} 
-
-
-/*******************************************************************************
-* Function Name  : LIS3DH_SetClickLIMIT
-* Description    : Set Click Interrupt Time Limit
-* Input          : Click-click Time Limit value [0-127]
-* Output         : None
-* Return         : Status [MEMS_ERROR, MEMS_SUCCESS]
-*******************************************************************************/
-status_t LIS3DH::LIS3DH_SetClickLIMIT(u8_t t_limit) {
-  
-  if(t_limit>127)     
-    return MEMS_ERROR;
-  
-  if( !LIS3DH_WriteReg(LIS3DH_TIME_LIMIT, t_limit) )
-    return MEMS_ERROR;
-  
-  return MEMS_SUCCESS;
-} 
-
-
-/*******************************************************************************
-* Function Name  : LIS3DH_SetClickLATENCY
-* Description    : Set Click Interrupt Time Latency
-* Input          : Click-click Time Latency value [0-255]
-* Output         : None
-* Return         : Status [MEMS_ERROR, MEMS_SUCCESS]
-*******************************************************************************/
-status_t LIS3DH::LIS3DH_SetClickLATENCY(u8_t t_latency) {
-  
-  if( !LIS3DH_WriteReg(LIS3DH_TIME_LATENCY, t_latency) )
-    return MEMS_ERROR;
-  
-  return MEMS_SUCCESS;
-} 
-
-
-/*******************************************************************************
-* Function Name  : LIS3DH_SetClickWINDOW
-* Description    : Set Click Interrupt Time Window
-* Input          : Click-click Time Window value [0-255]
-* Output         : None
-* Return         : Status [MEMS_ERROR, MEMS_SUCCESS]
-*******************************************************************************/
-status_t LIS3DH::LIS3DH_SetClickWINDOW(u8_t t_window) {
-  
-  if( !LIS3DH_WriteReg(LIS3DH_TIME_WINDOW, t_window) )
-    return MEMS_ERROR;
-  
-  return MEMS_SUCCESS;
-}
-
-
-/*******************************************************************************
-* Function Name  : LIS3DH_GetClickResponse
-* Description    : Get Click Interrupt Response by CLICK_SRC REGISTER
-* Input          : char to empty by Click Response Typedef
-* Output         : None
-* Return         : Status [MEMS_ERROR, MEMS_SUCCESS]
-*******************************************************************************/
-status_t LIS3DH::LIS3DH_GetClickResponse(u8_t* res) {
-  u8_t value;
-  
-  if( !LIS3DH_ReadReg(LIS3DH_CLICK_SRC, &value) ) 
-    return MEMS_ERROR;
-  
-  value &= 0x7F;
-  
-  if((value & LIS3DH_IA)==0) {        
-    *res = LIS3DH_NO_CLICK;     
-    return MEMS_SUCCESS;
-  }
-  else {
-    if (value & LIS3DH_DCLICK){
-      if (value & LIS3DH_CLICK_SIGN){
-        if (value & LIS3DH_CLICK_Z) {
-          *res = LIS3DH_DCLICK_Z_N;   
-          return MEMS_SUCCESS;
-        }
-        if (value & LIS3DH_CLICK_Y) {
-          *res = LIS3DH_DCLICK_Y_N;   
-          return MEMS_SUCCESS;
-        }
-        if (value & LIS3DH_CLICK_X) {
-          *res = LIS3DH_DCLICK_X_N;   
-          return MEMS_SUCCESS;
-        }
-      }
-      else{
-        if (value & LIS3DH_CLICK_Z) {
-          *res = LIS3DH_DCLICK_Z_P;   
-          return MEMS_SUCCESS;
-        }
-        if (value & LIS3DH_CLICK_Y) {
-          *res = LIS3DH_DCLICK_Y_P;   
-          return MEMS_SUCCESS;
-        }
-        if (value & LIS3DH_CLICK_X) {
-          *res = LIS3DH_DCLICK_X_P;   
-          return MEMS_SUCCESS;
-        }
-      }       
-    }
-    else{
-      if (value & LIS3DH_CLICK_SIGN){
-        if (value & LIS3DH_CLICK_Z) {
-          *res = LIS3DH_SCLICK_Z_N;   
-          return MEMS_SUCCESS;
-        }
-        if (value & LIS3DH_CLICK_Y) {
-          *res = LIS3DH_SCLICK_Y_N;   
-          return MEMS_SUCCESS;
-        }
-        if (value & LIS3DH_CLICK_X) {
-          *res = LIS3DH_SCLICK_X_N;   
-          return MEMS_SUCCESS;
-        }
-      }
-      else{
-        if (value & LIS3DH_CLICK_Z) {
-          *res = LIS3DH_SCLICK_Z_P;   
-          return MEMS_SUCCESS;
-        }
-        if (value & LIS3DH_CLICK_Y) {
-          *res = LIS3DH_SCLICK_Y_P;   
-          return MEMS_SUCCESS;
-        }
-        if (value & LIS3DH_CLICK_X) {
-          *res = LIS3DH_SCLICK_X_P;   
-          return MEMS_SUCCESS;
-        }
-      }
-    }
-  }
-  return MEMS_ERROR;
-} 
-
-
-/*******************************************************************************
-* Function Name  : LIS3DH_Int1LatchEnable
-* Description    : Enable Interrupt 1 Latching function
-* Input          : ENABLE/DISABLE
-* Output         : None
-* Return         : Status [MEMS_ERROR, MEMS_SUCCESS]
-*******************************************************************************/
-status_t LIS3DH::LIS3DH_Int1LatchEnable(State_t latch) {
-  u8_t value;
-  
-  if( !LIS3DH_ReadReg(LIS3DH_CTRL_REG5, &value) )
-    return MEMS_ERROR;
-  
-  value &= 0xF7;
-  value |= latch<<LIS3DH_LIR_INT1;
-  
-  if( !LIS3DH_WriteReg(LIS3DH_CTRL_REG5, value) )
-    return MEMS_ERROR;
-  
-  return MEMS_SUCCESS;
-}
-
-status_t LIS3DH::LIS3DH_ResetInt1Latch(void) {
-  u8_t value;
-  
-  if( !LIS3DH_ReadReg(LIS3DH_INT1_SRC, &value) )
-    return MEMS_ERROR;
-  
-  return MEMS_SUCCESS;
-}
-
-/*******************************************************************************
-* Function Name  : LIS3DH_SetIntConfiguration
-* Description    : Interrupt 1 Configuration (without LIS3DH_6D_INT)
-* Input          : LIS3DH_INT1_AND/OR | LIS3DH_INT1_ZHIE_ENABLE/DISABLE | LIS3DH_INT1_ZLIE_ENABLE/DISABLE...
-* Output         : None
-* Note           : You MUST use all input variable in the argument, as example
-* Return         : Status [MEMS_ERROR, MEMS_SUCCESS]
-*******************************************************************************/
-status_t LIS3DH::LIS3DH_SetIntConfiguration(LIS3DH_Int1Conf_t ic) {
-  u8_t value;
-  
-  if( !LIS3DH_ReadReg(LIS3DH_INT1_CFG, &value) )
-    return MEMS_ERROR;
-  
-  value &= 0x40; 
-  value |= ic;
-  
-  if( !LIS3DH_WriteReg(LIS3DH_INT1_CFG, value) )
-    return MEMS_ERROR;
-  
-  return MEMS_SUCCESS;
-} 
-
-     
-/*******************************************************************************
-* Function Name  : LIS3DH_SetIntMode
-* Description    : Interrupt 1 Configuration mode (OR, 6D Movement, AND, 6D Position)
-* Input          : LIS3DH_INT_MODE_OR, LIS3DH_INT_MODE_6D_MOVEMENT, LIS3DH_INT_MODE_AND, 
-                   LIS3DH_INT_MODE_6D_POSITION
-* Output         : None
-* Return         : Status [MEMS_ERROR, MEMS_SUCCESS]
-*******************************************************************************/
-status_t LIS3DH::LIS3DH_SetIntMode(LIS3DH_Int1Mode_t int_mode) {
-  u8_t value;
-  
-  if( !LIS3DH_ReadReg(LIS3DH_INT1_CFG, &value) )
-    return MEMS_ERROR;
-  
-  value &= 0x3F; 
-  value |= (int_mode<<LIS3DH_INT_6D);
-  
-  if( !LIS3DH_WriteReg(LIS3DH_INT1_CFG, value) )
-    return MEMS_ERROR;
-  
-  return MEMS_SUCCESS;
-}
-
-/*******************************************************************************
-* Function Name  : LIS3DH_SetInt6D4DConfiguration
-* Description    : 6D, 4D Interrupt Configuration
-* Input          : LIS3DH_INT1_6D_ENABLE, LIS3DH_INT1_4D_ENABLE, LIS3DH_INT1_6D_4D_DISABLE
-* Output         : None
-* Return         : Status [MEMS_ERROR, MEMS_SUCCESS]
-*******************************************************************************/
-status_t LIS3DH::LIS3DH_SetInt6D4DConfiguration(LIS3DH_INT_6D_4D_t ic) {
-  u8_t value;
-  u8_t value2;
-  
-  if( !LIS3DH_ReadReg(LIS3DH_INT1_CFG, &value) )
-    return MEMS_ERROR;
-  if( !LIS3DH_ReadReg(LIS3DH_CTRL_REG5, &value2) )
-    return MEMS_ERROR;
-  
-  if(ic == LIS3DH_INT1_6D_ENABLE){
-    value &= 0xBF; 
-    value |= (MEMS_ENABLE<<LIS3DH_INT_6D);
-    value2 &= 0xFB; 
-    value2 |= (MEMS_DISABLE<<LIS3DH_D4D_INT1);
-  }
-  
-  if(ic == LIS3DH_INT1_4D_ENABLE){
-    value &= 0xBF; 
-    value |= (MEMS_ENABLE<<LIS3DH_INT_6D);
-    value2 &= 0xFB; 
-    value2 |= (MEMS_ENABLE<<LIS3DH_D4D_INT1);
-  }
-  
-  if(ic == LIS3DH_INT1_6D_4D_DISABLE){
-    value &= 0xBF; 
-    value |= (MEMS_DISABLE<<LIS3DH_INT_6D);
-    value2 &= 0xFB; 
-    value2 |= (MEMS_DISABLE<<LIS3DH_D4D_INT1);
-  }
-  
-  if( !LIS3DH_WriteReg(LIS3DH_INT1_CFG, value) )
-    return MEMS_ERROR;
-  if( !LIS3DH_WriteReg(LIS3DH_CTRL_REG5, value2) )
-    return MEMS_ERROR;
-  
-  return MEMS_SUCCESS;
-}
-
-/*******************************************************************************
-* Function Name  : LIS3DH_Get6DPosition
-* Description    : 6D, 4D Interrupt Position Detect
-* Input          : Byte to empty by POSITION_6D_t Typedef
-* Output         : None
-* Return         : Status [MEMS_ERROR, MEMS_SUCCESS]
-*******************************************************************************/
-status_t LIS3DH::LIS3DH_Get6DPosition(u8_t* val){
-  u8_t value;
-  
-  if( !LIS3DH_ReadReg(LIS3DH_INT1_SRC, &value) )
-    return MEMS_ERROR;
-  
-  value &= 0x7F;
-  
-  switch (value){
-  case LIS3DH_UP_SX:   
-    *val = LIS3DH_UP_SX;    
-    break;
-  case LIS3DH_UP_DX:   
-    *val = LIS3DH_UP_DX;    
-    break;
-  case LIS3DH_DW_SX:   
-    *val = LIS3DH_DW_SX;    
-    break;
-  case LIS3DH_DW_DX:   
-    *val = LIS3DH_DW_DX;    
-    break;
-  case LIS3DH_TOP:     
-    *val = LIS3DH_TOP;      
-    break;
-  case LIS3DH_BOTTOM:  
-    *val = LIS3DH_BOTTOM;   
-    break;
-  }
-  
-  return MEMS_SUCCESS;  
-}
-
-/*******************************************************************************
-* Function Name  : LIS3DH_SetInt1Threshold
-* Description    : Sets Interrupt 1 Threshold
-* Input          : Threshold = [0,31]
-* Output         : None
-* Return         : Status [MEMS_ERROR, MEMS_SUCCESS]
-*******************************************************************************/
-status_t LIS3DH::LIS3DH_SetInt1Threshold(u8_t ths) {
-  if (ths > 127)
-    return MEMS_ERROR;
-  
-  if( !LIS3DH_WriteReg(LIS3DH_INT1_THS, ths) )
-    return MEMS_ERROR;    
-  
-  return MEMS_SUCCESS;
-}
-
-/*******************************************************************************
-* Function Name  : LIS3DH_SetInt1Duration
-* Description    : Sets Interrupt 1 Duration
-* Input          : Duration value
-* Output         : None
-* Return         : Status [MEMS_ERROR, MEMS_SUCCESS]
-*******************************************************************************/
-status_t LIS3DH::LIS3DH_SetInt1Duration(LIS3DH_Int1Conf_t id) {
-  
-  if (id > 127)
-    return MEMS_ERROR;
-  
-  if( !LIS3DH_WriteReg(LIS3DH_INT1_DURATION, id) )
-    return MEMS_ERROR;
-  
-  return MEMS_SUCCESS;
-}
-
-/*******************************************************************************
-* Function Name  : LIS3DH_FIFOModeEnable
-* Description    : Sets Fifo Modality
-* Input          : LIS3DH_FIFO_DISABLE, LIS3DH_FIFO_BYPASS_MODE, LIS3DH_FIFO_MODE, 
-           LIS3DH_FIFO_STREAM_MODE, LIS3DH_FIFO_TRIGGER_MODE
-* Output         : None
-* Return         : Status [MEMS_ERROR, MEMS_SUCCESS]
-*******************************************************************************/
-status_t LIS3DH::LIS3DH_FIFOModeEnable(LIS3DH_FifoMode_t fm) {
-  u8_t value;  
-  
-  if(fm == LIS3DH_FIFO_DISABLE) { 
-    if( !LIS3DH_ReadReg(LIS3DH_FIFO_CTRL_REG, &value) )
-      return MEMS_ERROR;
-    
-    value &= 0x1F;
-    value |= (LIS3DH_FIFO_BYPASS_MODE<<LIS3DH_FM);                     
-    
-    if( !LIS3DH_WriteReg(LIS3DH_FIFO_CTRL_REG, value) )           //fifo mode bypass
-      return MEMS_ERROR;   
-    if( !LIS3DH_ReadReg(LIS3DH_CTRL_REG5, &value) )
-      return MEMS_ERROR;
-    
-    value &= 0xBF;    
-    
-    if( !LIS3DH_WriteReg(LIS3DH_CTRL_REG5, value) )               //fifo disable
-      return MEMS_ERROR;   
-  }
-  
-  if(fm == LIS3DH_FIFO_BYPASS_MODE)   {  
-    if( !LIS3DH_ReadReg(LIS3DH_CTRL_REG5, &value) )
-      return MEMS_ERROR;
-    
-    value &= 0xBF;
-    value |= MEMS_SET<<LIS3DH_FIFO_EN;
-    
-    if( !LIS3DH_WriteReg(LIS3DH_CTRL_REG5, value) )               //fifo enable
-      return MEMS_ERROR;  
-    if( !LIS3DH_ReadReg(LIS3DH_FIFO_CTRL_REG, &value) )
-      return MEMS_ERROR;
-    
-    value &= 0x1f;
-    value |= (fm<<LIS3DH_FM);                     //fifo mode configuration
-    
-    if( !LIS3DH_WriteReg(LIS3DH_FIFO_CTRL_REG, value) )
-      return MEMS_ERROR;
-  }
-  
-  if(fm == LIS3DH_FIFO_MODE)   {
-    if( !LIS3DH_ReadReg(LIS3DH_CTRL_REG5, &value) )
-      return MEMS_ERROR;
-    
-    value &= 0xBF;
-    value |= MEMS_SET<<LIS3DH_FIFO_EN;
-    
-    if( !LIS3DH_WriteReg(LIS3DH_CTRL_REG5, value) )               //fifo enable
-      return MEMS_ERROR;  
-    if( !LIS3DH_ReadReg(LIS3DH_FIFO_CTRL_REG, &value) )
-      return MEMS_ERROR;
-    
-    value &= 0x1f;
-    value |= (fm<<LIS3DH_FM);                      //fifo mode configuration
-    
-    if( !LIS3DH_WriteReg(LIS3DH_FIFO_CTRL_REG, value) )
-      return MEMS_ERROR;
-  }
-  
-  if(fm == LIS3DH_FIFO_STREAM_MODE)   {  
-    if( !LIS3DH_ReadReg(LIS3DH_CTRL_REG5, &value) )
-      return MEMS_ERROR;
-    
-    value &= 0xBF;
-    value |= MEMS_SET<<LIS3DH_FIFO_EN;
-    
-    if( !LIS3DH_WriteReg(LIS3DH_CTRL_REG5, value) )               //fifo enable
-      return MEMS_ERROR;   
-    if( !LIS3DH_ReadReg(LIS3DH_FIFO_CTRL_REG, &value) )
-      return MEMS_ERROR;
-    
-    value &= 0x1f;
-    value |= (fm<<LIS3DH_FM);                      //fifo mode configuration
-    
-    if( !LIS3DH_WriteReg(LIS3DH_FIFO_CTRL_REG, value) )
-      return MEMS_ERROR;
-  }
-  
-  if(fm == LIS3DH_FIFO_TRIGGER_MODE)   {  
-    if( !LIS3DH_ReadReg(LIS3DH_CTRL_REG5, &value) )
-      return MEMS_ERROR;
-    
-    value &= 0xBF;
-    value |= MEMS_SET<<LIS3DH_FIFO_EN;
-    
-    if( !LIS3DH_WriteReg(LIS3DH_CTRL_REG5, value) )               //fifo enable
-      return MEMS_ERROR;    
-    if( !LIS3DH_ReadReg(LIS3DH_FIFO_CTRL_REG, &value) )
-      return MEMS_ERROR;
-    
-    value &= 0x1f;
-    value |= (fm<<LIS3DH_FM);                      //fifo mode configuration
-    
-    if( !LIS3DH_WriteReg(LIS3DH_FIFO_CTRL_REG, value) )
-      return MEMS_ERROR;
-  }
-  
-  return MEMS_SUCCESS;
-}
-
-/*******************************************************************************
-* Function Name  : LIS3DH_SetTriggerInt
-* Description    : Trigger event liked to trigger signal INT1/INT2
-* Input          : LIS3DH_TRIG_INT1/LIS3DH_TRIG_INT2
-* Output         : None
-* Return         : Status [MEMS_ERROR, MEMS_SUCCESS]
-*******************************************************************************/
-status_t LIS3DH::LIS3DH_SetTriggerInt(LIS3DH_TrigInt_t tr) {
-  u8_t value;  
-  
-  if( !LIS3DH_ReadReg(LIS3DH_FIFO_CTRL_REG, &value) )
-    return MEMS_ERROR;
-  
-  value &= 0xDF;
-  value |= (tr<<LIS3DH_TR); 
-  
-  if( !LIS3DH_WriteReg(LIS3DH_FIFO_CTRL_REG, value) )
-    return MEMS_ERROR;
-  
-  return MEMS_SUCCESS;
-}
-
-/*******************************************************************************
-* Function Name  : LIS3DH_SetWaterMark
-* Description    : Sets Watermark Value
-* Input          : Watermark = [0,31]
-* Output         : None
-* Return         : Status [MEMS_ERROR, MEMS_SUCCESS]
-*******************************************************************************/
-status_t LIS3DH::LIS3DH_SetWaterMark(u8_t wtm) {
-  u8_t value;
-  
-  if(wtm > 31)
-    return MEMS_ERROR;  
-  
-  if( !LIS3DH_ReadReg(LIS3DH_FIFO_CTRL_REG, &value) )
-    return MEMS_ERROR;
-  
-  value &= 0xE0;
-  value |= wtm; 
-  
-  if( !LIS3DH_WriteReg(LIS3DH_FIFO_CTRL_REG, value) )
-    return MEMS_ERROR;
-  
-  return MEMS_SUCCESS;
-}
-
-/*******************************************************************************
-* Function Name  : LIS3DH_GetStatusReg
-* Description    : Read the status register
-* Input          : char to empty by Status Reg Value
-* Output         : None
-* Return         : Status [MEMS_ERROR, MEMS_SUCCESS]
-*******************************************************************************/
-status_t LIS3DH::LIS3DH_GetStatusReg(u8_t* val) {
-  if( !LIS3DH_ReadReg(LIS3DH_STATUS_REG, val) )
-    return MEMS_ERROR;
-  
-  return MEMS_SUCCESS;  
-}
-
-
-/*******************************************************************************
-* Function Name  : LIS3DH_GetStatusBIT
-* Description    : Read the status register BIT
-* Input          : LIS3DH_STATUS_REG_ZYXOR, LIS3DH_STATUS_REG_ZOR, LIS3DH_STATUS_REG_YOR, LIS3DH_STATUS_REG_XOR,
-                   LIS3DH_STATUS_REG_ZYXDA, LIS3DH_STATUS_REG_ZDA, LIS3DH_STATUS_REG_YDA, LIS3DH_STATUS_REG_XDA, 
-           LIS3DH_DATAREADY_BIT
-           val: Byte to be filled with the status bit 
-* Output         : status register BIT
-* Return         : Status [MEMS_ERROR, MEMS_SUCCESS]
-*******************************************************************************/
-status_t LIS3DH::LIS3DH_GetStatusBit(u8_t statusBIT, u8_t* val) {
-  u8_t value;  
-  
-  if( !LIS3DH_ReadReg(LIS3DH_STATUS_REG, &value) )
-    return MEMS_ERROR;
-  
-  switch (statusBIT){
-  case LIS3DH_STATUS_REG_ZYXOR:     
-    if(value &= LIS3DH_STATUS_REG_ZYXOR){     
-      *val = MEMS_SET;
-      return MEMS_SUCCESS;
-    }
-    else{  
-      *val = MEMS_RESET;
-      return MEMS_SUCCESS;
-    }  
-  case LIS3DH_STATUS_REG_ZOR:       
-    if(value &= LIS3DH_STATUS_REG_ZOR){     
-      *val = MEMS_SET;
-      return MEMS_SUCCESS;
-    }
-    else{  
-      *val = MEMS_RESET;
-      return MEMS_SUCCESS;
-    }  
-  case LIS3DH_STATUS_REG_YOR:       
-    if(value &= LIS3DH_STATUS_REG_YOR){     
-      *val = MEMS_SET;
-      return MEMS_SUCCESS;
-    }
-    else{  
-      *val = MEMS_RESET;
-      return MEMS_SUCCESS;
-    }                                 
-  case LIS3DH_STATUS_REG_XOR:       
-    if(value &= LIS3DH_STATUS_REG_XOR){     
-      *val = MEMS_SET;
-      return MEMS_SUCCESS;
-    }
-    else{  
-      *val = MEMS_RESET;
-      return MEMS_SUCCESS;
-    }     
-  case LIS3DH_STATUS_REG_ZYXDA:     
-    if(value &= LIS3DH_STATUS_REG_ZYXDA){     
-      *val = MEMS_SET;
-      return MEMS_SUCCESS;
-    }
-    else{  
-      *val = MEMS_RESET;
-      return MEMS_SUCCESS;
-    }   
-  case LIS3DH_STATUS_REG_ZDA:       
-    if(value &= LIS3DH_STATUS_REG_ZDA){     
-      *val = MEMS_SET;
-      return MEMS_SUCCESS;
-    }
-    else{  
-      *val = MEMS_RESET;
-      return MEMS_SUCCESS;
-    }   
-  case LIS3DH_STATUS_REG_YDA:       
-    if(value &= LIS3DH_STATUS_REG_YDA){     
-      *val = MEMS_SET;
-      return MEMS_SUCCESS;
-    }
-    else{  
-      *val = MEMS_RESET;
-      return MEMS_SUCCESS;
-    }   
-  case LIS3DH_STATUS_REG_XDA:       
-    if(value &= LIS3DH_STATUS_REG_XDA){     
-      *val = MEMS_SET;
-      return MEMS_SUCCESS;
-    }
-    else{  
-      *val = MEMS_RESET;
-      return MEMS_SUCCESS;
-    }                                  
-    
-  }
-  return MEMS_ERROR;
-}
-
-/*******************************************************************************
-* Function Name  : LIS3DH_GetAccAxesRaw
-* Description    : Read the Acceleration Values Output Registers
-* Input          : buffer to empity by AxesRaw_t Typedef
-* Output         : None
-* Return         : Status [MEMS_ERROR, MEMS_SUCCESS]
-*******************************************************************************/
-status_t LIS3DH::LIS3DH_GetAccAxesRaw(AxesRaw_t* buff) {
-  i16_t value;
-  u8_t *valueL = (u8_t *)(&value);
-  u8_t *valueH = ((u8_t *)(&value)+1);
-  
-  if( !LIS3DH_ReadReg(LIS3DH_OUT_X_L, valueL) )
-    return MEMS_ERROR;
-  
-  if( !LIS3DH_ReadReg(LIS3DH_OUT_X_H, valueH) )
-    return MEMS_ERROR;
-  
-  buff->AXIS_X = value;
-  
-  if( !LIS3DH_ReadReg(LIS3DH_OUT_Y_L, valueL) )
-    return MEMS_ERROR;
-  
-  if( !LIS3DH_ReadReg(LIS3DH_OUT_Y_H, valueH) )
-    return MEMS_ERROR;
-  
-  buff->AXIS_Y = value;
-  
-  if( !LIS3DH_ReadReg(LIS3DH_OUT_Z_L, valueL) )
-    return MEMS_ERROR;
-  
-  if( !LIS3DH_ReadReg(LIS3DH_OUT_Z_H, valueH) )
-    return MEMS_ERROR;
-  
-  buff->AXIS_Z = value;
-  
-  return MEMS_SUCCESS; 
-}
-
-/*******************************************************************************
-* Function Name  : LIS3DH_GetInt1Src
-* Description    : Reset Interrupt 1 Latching function
-* Input          : Char to empty by Int1 source value
-* Output         : None
-* Return         : Status [MEMS_ERROR, MEMS_SUCCESS]
-*******************************************************************************/
-status_t LIS3DH::LIS3DH_GetInt1Src(u8_t* val) {
-  
-  if( !LIS3DH_ReadReg(LIS3DH_INT1_SRC, val) )
-    return MEMS_ERROR;
-  
-  return MEMS_SUCCESS;
-}
-
-
-/*******************************************************************************
-* Function Name  : LIS3DH_GetInt1SrcBit
-* Description    : Reset Interrupt 1 Latching function
-* Input          : statusBIT: LIS3DH_INT_SRC_IA, LIS3DH_INT_SRC_ZH, LIS3DH_INT_SRC_ZL.....
-*                  val: Byte to be filled with the status bit
-* Output         : None
-* Return         : Status of BIT [MEMS_ERROR, MEMS_SUCCESS]
-*******************************************************************************/
-status_t LIS3DH::LIS3DH_GetInt1SrcBit(u8_t statusBIT, u8_t* val) {
-  u8_t value;  
-   
-  if( !LIS3DH_ReadReg(LIS3DH_INT1_SRC, &value) )
-      return MEMS_ERROR;
-   
-  if(statusBIT == LIS3DH_INT1_SRC_IA){
-    if(value &= LIS3DH_INT1_SRC_IA){     
-      *val = MEMS_SET;
-      return MEMS_SUCCESS;
-    }
-    else{  
-      *val = MEMS_RESET;
-      return MEMS_SUCCESS;
-    }  
-  }
-  
-  if(statusBIT == LIS3DH_INT1_SRC_ZH){
-    if(value &= LIS3DH_INT1_SRC_ZH){     
-      *val = MEMS_SET;
-      return MEMS_SUCCESS;
-    }
-    else{  
-      *val = MEMS_RESET;
-      return MEMS_SUCCESS;
-    }  
-  }
-  
-  if(statusBIT == LIS3DH_INT1_SRC_ZL){
-    if(value &= LIS3DH_INT1_SRC_ZL){     
-      *val = MEMS_SET;
-      return MEMS_SUCCESS;
-    }
-    else{  
-      *val = MEMS_RESET;
-      return MEMS_SUCCESS;
-    }  
-  }
-  
-  if(statusBIT == LIS3DH_INT1_SRC_YH){
-    if(value &= LIS3DH_INT1_SRC_YH){     
-      *val = MEMS_SET;
-      return MEMS_SUCCESS;
-    }
-    else{  
-      *val = MEMS_RESET;
-      return MEMS_SUCCESS;
-    }  
-  }
-  
-  if(statusBIT == LIS3DH_INT1_SRC_YL){
-    if(value &= LIS3DH_INT1_SRC_YL){     
-      *val = MEMS_SET;
-      return MEMS_SUCCESS;
-    }
-    else{  
-      *val = MEMS_RESET;
-      return MEMS_SUCCESS;
-    }  
-  }
-  if(statusBIT == LIS3DH_INT1_SRC_XH){
-    if(value &= LIS3DH_INT1_SRC_XH){     
-      *val = MEMS_SET;
-      return MEMS_SUCCESS;
-    }
-    else{  
-      *val = MEMS_RESET;
-      return MEMS_SUCCESS;
-    }  
-  }
-  
-  if(statusBIT == LIS3DH_INT1_SRC_XL){
-    if(value &= LIS3DH_INT1_SRC_XL){     
-      *val = MEMS_SET;
-      return MEMS_SUCCESS;
-    }
-    else{  
-      *val = MEMS_RESET;
-      return MEMS_SUCCESS;
-    }  
-  }
-  return MEMS_ERROR;
-}
-
-
-/*******************************************************************************
-* Function Name  : LIS3DH_GetFifoSourceReg
-* Description    : Read Fifo source Register
-* Input          : Byte to empty by FIFO source register value
-* Output         : None
-* Return         : Status [MEMS_ERROR, MEMS_SUCCESS]
-*******************************************************************************/
-status_t LIS3DH::LIS3DH_GetFifoSourceReg(u8_t* val) {
-  
-  if( !LIS3DH_ReadReg(LIS3DH_FIFO_SRC_REG, val) )
-    return MEMS_ERROR;
-  
-  return MEMS_SUCCESS;
-}
-
-
-/*******************************************************************************
-* Function Name  : LIS3DH_GetFifoSourceBit
-* Description    : Read Fifo WaterMark source bit
-* Input          : statusBIT: LIS3DH_FIFO_SRC_WTM, LIS3DH_FIFO_SRC_OVRUN, LIS3DH_FIFO_SRC_EMPTY
-*          val: Byte to fill  with the bit value
-* Output         : None
-* Return         : Status of BIT [MEMS_ERROR, MEMS_SUCCESS]
-*******************************************************************************/
-status_t LIS3DH::LIS3DH_GetFifoSourceBit(u8_t statusBIT,  u8_t* val){
-  u8_t value;  
-  
-  if( !LIS3DH_ReadReg(LIS3DH_FIFO_SRC_REG, &value) )
-    return MEMS_ERROR;
-  
-  
-  if(statusBIT == LIS3DH_FIFO_SRC_WTM){
-    if(value &= LIS3DH_FIFO_SRC_WTM){     
-      *val = MEMS_SET;
-      return MEMS_SUCCESS;
-    }
-    else{  
-      *val = MEMS_RESET;
-      return MEMS_SUCCESS;
-    }  
-  }
-  
-  if(statusBIT == LIS3DH_FIFO_SRC_OVRUN){
-    if(value &= LIS3DH_FIFO_SRC_OVRUN){     
-      *val = MEMS_SET;
-      return MEMS_SUCCESS;
-    }
-    else{  
-      *val = MEMS_RESET;
-      return MEMS_SUCCESS;
-    }  
-  }
-  if(statusBIT == LIS3DH_FIFO_SRC_EMPTY){
-    if(value &= statusBIT == LIS3DH_FIFO_SRC_EMPTY){     
-      *val = MEMS_SET;
-      return MEMS_SUCCESS;
-    }
-    else{  
-      *val = MEMS_RESET;
-      return MEMS_SUCCESS;
-    }  
-  }
-  return MEMS_ERROR;
-}
-
-
-/*******************************************************************************
-* Function Name  : LIS3DH_GetFifoSourceFSS
-* Description    : Read current number of unread samples stored in FIFO
-* Input          : Byte to empty by FIFO unread sample value
-* Output         : None
-* Return         : Status [value of FSS]
-*******************************************************************************/
-status_t LIS3DH::LIS3DH_GetFifoSourceFSS(u8_t* val){
-  u8_t value;
-  
-  if( !LIS3DH_ReadReg(LIS3DH_FIFO_SRC_REG, &value) )
-    return MEMS_ERROR;
-  
-  value &= 0x1F;
-  
-  *val = value;
-  
-  return MEMS_SUCCESS;
-}
-
-/*******************************************************************************
-* Function Name  : LIS3DH_GetTempRaw
-* Description    : Read the Temperature Values by AUX Output Registers OUT_3_H
-* Input          : Buffer to empty
-* Output         : Temperature Values Registers buffer
-* Return         : Status [MEMS_ERROR, MEMS_SUCCESS]
-*******************************************************************************/
-status_t LIS3DH::LIS3DH_GetTempRaw(i8_t* buff) {
-  u8_t valueL;
-  u8_t valueH;
-  
-  if( !LIS3DH_ReadReg(LIS3DH_OUT_3_L, &valueL) )
-    return MEMS_ERROR;
-  
-  if( !LIS3DH_ReadReg(LIS3DH_OUT_3_H, &valueH) )
-    return MEMS_ERROR;
-  
-  *buff = (i8_t)( valueH );
-  
-  return MEMS_SUCCESS;  
-}
-
-/*******************************************************************************
-* Function Name  : LIS3DH_GetWHO_AM_I
-* Description    : Read identification code by WHO_AM_I register
-* Input          : Char to empty by Device identification Value
-* Output         : None
-* Return         : Status [value of FSS]
-*******************************************************************************/
-status_t LIS3DH::LIS3DH_GetWHO_AM_I(u8_t* val){
-  
-  if( !LIS3DH_ReadReg(LIS3DH_WHO_AM_I, val) )
-    return MEMS_ERROR;
-  
-  return MEMS_SUCCESS;
-}
-
-/*******************************************************************************
-* Function Name     : LIS3DH_ReadReg
-* Description       : Generic Reading function. It must be fullfilled with either
-*           : I2C or SPI reading functions                  
-* Input         : Register Address
-* Output        : Data REad
-* Return        : None
-*******************************************************************************/
-u8_t LIS3DH::LIS3DH_ReadReg(u8_t Reg, u8_t* Data) {
-  
-  //To be completed with either I2c or SPI reading function
-  //i.e. *Data = SPI_Mems_Read_Reg( Reg );  
-    
-    _ss = 0;
-    _spi.write(0x80 | Reg);
-    signed char raw = _spi.write(0x00); 
-    _ss = 1;
-    
-    *Data=raw;
-    
-  return 1;
-}
-
-/*******************************************************************************
-* Function Name     : LIS3DH_WriteReg
-* Description       : Generic Writing function. It must be fullfilled with either
-*           : I2C or SPI writing function
-* Input         : Register Address, Data to be written
-* Output        : None
-* Return        : None
-*******************************************************************************/
-u8_t LIS3DH::LIS3DH_WriteReg(u8_t WriteAddr, u8_t Data) {
-  
-  //To be completed with either I2c or SPI writing function
-  //i.e. SPI_Mems_Write_Reg(WriteAddr, Data);  
-    
-    _ss = 0;
-    _spi.write(0x00 | WriteAddr);
-    _spi.write (Data);
-    _ss = 1;  
-    
-  return 1;
-}
-
-LIS3DH::~LIS3DH(){};
-    
\ No newline at end of file
diff -r bd7fd35251ab -r b221ba23b37f LIS3DH.h
--- a/LIS3DH.h	Mon Jan 25 13:27:15 2016 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,516 +0,0 @@
-#ifndef LIS3DH_H
-#define LIS3DH_H
-
-#include "mbed.h"
-
-namespace mbed {
-
-#ifndef __ARCHDEP__TYPES
-#define __ARCHDEP__TYPES
-
-typedef unsigned char u8_t;
-typedef unsigned short int u16_t;
-typedef short int i16_t;
-typedef signed char i8_t;
-
-#endif /*__ARCHDEP__TYPES*/
-
-typedef u8_t LIS3DH_IntPinConf_t;
-typedef u8_t LIS3DH_Axis_t;
-typedef u8_t LIS3DH_Int1Conf_t;
-
-
-//define structure
-#ifndef __SHARED__TYPES
-#define __SHARED__TYPES
-
-typedef enum {
-  MEMS_SUCCESS              =       0x01,
-  MEMS_ERROR                =       0x00    
-} status_t;
-
-typedef enum {
-  MEMS_ENABLE               =       0x01,
-  MEMS_DISABLE              =       0x00    
-} State_t;
-
-typedef __packed struct {
-  i16_t AXIS_X;
-  i16_t AXIS_Y;
-  i16_t AXIS_Z;
-} AxesRaw_t;
-
-#endif /*__SHARED__TYPES*/
-
-typedef enum {  
-  LIS3DH_ODR_1Hz                =       0x01,       
-  LIS3DH_ODR_10Hz                      =        0x02,
-  LIS3DH_ODR_25Hz               =       0x03,
-  LIS3DH_ODR_50Hz               =       0x04,
-  LIS3DH_ODR_100Hz              =       0x05,   
-  LIS3DH_ODR_200Hz              =       0x06,
-  LIS3DH_ODR_400Hz              =       0x07,
-  LIS3DH_ODR_1620Hz_LP              =       0x08,
-  LIS3DH_ODR_1344Hz_NP_5367HZ_LP       =        0x09    
-} LIS3DH_ODR_t;
-
-typedef enum {
-  LIS3DH_POWER_DOWN                    =        0x00,
-  LIS3DH_LOW_POWER          =       0x01,
-  LIS3DH_NORMAL         =       0x02
-} LIS3DH_Mode_t;
-
-typedef enum {
-  LIS3DH_HPM_NORMAL_MODE_RES           =               0x00,
-  LIS3DH_HPM_REF_SIGNAL                =               0x01,
-  LIS3DH_HPM_NORMAL_MODE               =               0x02,
-  LIS3DH_HPM_AUTORESET_INT             =               0x03
-} LIS3DH_HPFMode_t;
-
-typedef enum {
-  LIS3DH_HPFCF_0                       =               0x00,
-  LIS3DH_HPFCF_1                       =               0x01,
-  LIS3DH_HPFCF_2                       =        0x02,
-  LIS3DH_HPFCF_3                       =               0x03
-} LIS3DH_HPFCutOffFreq_t;
-
-typedef struct {
-  u16_t AUX_1;
-  u16_t AUX_2;
-  u16_t AUX_3;
-} LIS3DH_Aux123Raw_t;
-
-typedef enum {
-  LIS3DH_FULLSCALE_2                   =               0x00,
-  LIS3DH_FULLSCALE_4                   =               0x01,
-  LIS3DH_FULLSCALE_8                   =               0x02,
-  LIS3DH_FULLSCALE_16                  =               0x03
-} LIS3DH_Fullscale_t;
-
-typedef enum {
-  LIS3DH_BLE_LSB            =       0x00,
-  LIS3DH_BLE_MSB            =       0x01
-} LIS3DH_Endianess_t;
-
-typedef enum {
-  LIS3DH_SELF_TEST_DISABLE             =               0x00,
-  LIS3DH_SELF_TEST_0                   =               0x01,
-  LIS3DH_SELF_TEST_1                   =               0x02
-} LIS3DH_SelfTest_t;
-
-typedef enum {
-  LIS3DH_FIFO_BYPASS_MODE              =               0x00,
-  LIS3DH_FIFO_MODE                     =               0x01,
-  LIS3DH_FIFO_STREAM_MODE              =               0x02,
-  LIS3DH_FIFO_TRIGGER_MODE             =               0x03,
-  LIS3DH_FIFO_DISABLE                  =               0x04
-} LIS3DH_FifoMode_t;
-
-typedef enum {
-  LIS3DH_TRIG_INT1                     =        0x00,
-  LIS3DH_TRIG_INT2          =       0x01
-} LIS3DH_TrigInt_t;
-
-typedef enum {
-  LIS3DH_SPI_4_WIRE                    =               0x00,
-  LIS3DH_SPI_3_WIRE                    =               0x01
-} LIS3DH_SPIMode_t;
-
-typedef enum {
-  LIS3DH_X_ENABLE                      =               0x01,
-  LIS3DH_X_DISABLE                     =               0x00,
-  LIS3DH_Y_ENABLE                      =               0x02,
-  LIS3DH_Y_DISABLE                     =               0x00,
-  LIS3DH_Z_ENABLE                      =               0x04,
-  LIS3DH_Z_DISABLE                     =               0x00    
-} LIS3DH_AXISenable_t;
-
-typedef enum {
-  LIS3DH_INT1_6D_4D_DISABLE            =               0x00,
-  LIS3DH_INT1_6D_ENABLE                =               0x01,
-  LIS3DH_INT1_4D_ENABLE                =               0x02 
-} LIS3DH_INT_6D_4D_t;
-
-typedef enum {
-  LIS3DH_UP_SX                         =               0x44,
-  LIS3DH_UP_DX                         =               0x42,
-  LIS3DH_DW_SX                         =               0x41,
-  LIS3DH_DW_DX                         =               0x48,
-  LIS3DH_TOP                           =               0x60,
-  LIS3DH_BOTTOM                        =               0x50
-} LIS3DH_POSITION_6D_t;
-
-typedef enum {
-  LIS3DH_INT_MODE_OR                   =               0x00,
-  LIS3DH_INT_MODE_6D_MOVEMENT          =               0x01,
-  LIS3DH_INT_MODE_AND                  =               0x02,
-  LIS3DH_INT_MODE_6D_POSITION          =               0x03  
-} LIS3DH_Int1Mode_t;
-
-
-//interrupt click response
-//  b7 = don't care   b6 = IA  b5 = DClick  b4 = Sclick  b3 = Sign  
-//  b2 = z      b1 = y     b0 = x
-typedef enum {
-LIS3DH_DCLICK_Z_P                      =               0x24,
-LIS3DH_DCLICK_Z_N                      =               0x2C,
-LIS3DH_SCLICK_Z_P                      =               0x14,
-LIS3DH_SCLICK_Z_N                      =               0x1C,
-LIS3DH_DCLICK_Y_P                      =               0x22,
-LIS3DH_DCLICK_Y_N                      =               0x2A,
-LIS3DH_SCLICK_Y_P                      =               0x12,
-LIS3DH_SCLICK_Y_N           =       0x1A,
-LIS3DH_DCLICK_X_P                      =               0x21,
-LIS3DH_DCLICK_X_N                      =               0x29,
-LIS3DH_SCLICK_X_P                      =               0x11,
-LIS3DH_SCLICK_X_N                      =               0x19,
-LIS3DH_NO_CLICK                        =               0x00
-} LIS3DH_Click_Response; 
-
-//TODO: start from here and manage the shared macros etc before this
-
-/* Exported constants --------------------------------------------------------*/
-
-#ifndef __SHARED__CONSTANTS
-#define __SHARED__CONSTANTS
-
-#define MEMS_SET                                        0x01
-#define MEMS_RESET                                      0x00
-
-#endif /*__SHARED__CONSTANTS*/
-
-
-//Register Definition
-#define LIS3DH_WHO_AM_I             0x0F  // device identification register (00110011 default value=0x33)
-
-// CONTROL REGISTER 1
-#define LIS3DH_CTRL_REG1                0x20
-#define LIS3DH_ODR_BIT                      BIT(4)
-#define LIS3DH_LPEN                 BIT(3)
-#define LIS3DH_ZEN                  BIT(2)
-#define LIS3DH_YEN                  BIT(1)
-#define LIS3DH_XEN                  BIT(0)
-
-//CONTROL REGISTER 2
-#define LIS3DH_CTRL_REG2                0x21
-#define LIS3DH_HPM                  BIT(6)
-#define LIS3DH_HPCF                 BIT(4)
-#define LIS3DH_FDS                  BIT(3)
-#define LIS3DH_HPCLICK                  BIT(2)
-#define LIS3DH_HPIS2                    BIT(1)
-#define LIS3DH_HPIS1                    BIT(0)
-
-//CONTROL REGISTER 3
-#define LIS3DH_CTRL_REG3                0x22
-#define LIS3DH_I1_CLICK             BIT(7)
-#define LIS3DH_I1_AOI1                  BIT(6)
-#define LIS3DH_I1_AOI2                      BIT(5)
-#define LIS3DH_I1_DRDY1             BIT(4)
-#define LIS3DH_I1_DRDY2             BIT(3)
-#define LIS3DH_I1_WTM                   BIT(2)
-#define LIS3DH_I1_ORUN                  BIT(1)
-
-//CONTROL REGISTER 6
-#define LIS3DH_CTRL_REG6                0x25
-#define LIS3DH_I2_CLICK             BIT(7)
-#define LIS3DH_I2_INT1                  BIT(6)
-#define LIS3DH_I2_BOOT                  BIT(4)
-#define LIS3DH_H_LACTIVE                BIT(1)
-
-//TEMPERATURE CONFIG REGISTER
-#define LIS3DH_TEMP_CFG_REG             0x1F
-#define LIS3DH_ADC_PD                       BIT(7)
-#define LIS3DH_TEMP_EN                  BIT(6)
-
-//CONTROL REGISTER 4
-#define LIS3DH_CTRL_REG4                0x23
-#define LIS3DH_BDU                  BIT(7)
-#define LIS3DH_BLE                  BIT(6)
-#define LIS3DH_FS                   BIT(4)
-#define LIS3DH_HR                   BIT(3)
-#define LIS3DH_ST                       BIT(1)
-#define LIS3DH_SIM                  BIT(0)
-
-//CONTROL REGISTER 5
-#define LIS3DH_CTRL_REG5                0x24
-#define LIS3DH_BOOT                                    BIT(7)
-#define LIS3DH_FIFO_EN                                 BIT(6)
-#define LIS3DH_LIR_INT1                                BIT(3)
-#define LIS3DH_D4D_INT1                                BIT(2)
-
-//REFERENCE/DATA_CAPTURE
-#define LIS3DH_REFERENCE_REG                        0x26
-#define LIS3DH_REF                          BIT(0)
-
-//STATUS_REG_AXIES
-#define LIS3DH_STATUS_REG               0x27
-#define LIS3DH_ZYXOR                                   BIT(7)
-#define LIS3DH_ZOR                                     BIT(6)
-#define LIS3DH_YOR                                     BIT(5)
-#define LIS3DH_XOR                                     BIT(4)
-#define LIS3DH_ZYXDA                                   BIT(3)
-#define LIS3DH_ZDA                                     BIT(2)
-#define LIS3DH_YDA                                     BIT(1)
-#define LIS3DH_XDA                                     BIT(0)
-
-//STATUS_REG_AUX
-#define LIS3DH_STATUS_AUX               0x07
-
-//INTERRUPT 1 CONFIGURATION
-#define LIS3DH_INT1_CFG             0x30
-#define LIS3DH_ANDOR                                   BIT(7)
-#define LIS3DH_INT_6D                                  BIT(6)
-#define LIS3DH_ZHIE                                    BIT(5)
-#define LIS3DH_ZLIE                                    BIT(4)
-#define LIS3DH_YHIE                                    BIT(3)
-#define LIS3DH_YLIE                                    BIT(2)
-#define LIS3DH_XHIE                                    BIT(1)
-#define LIS3DH_XLIE                                    BIT(0)
-
-//FIFO CONTROL REGISTER
-#define LIS3DH_FIFO_CTRL_REG                           0x2E
-#define LIS3DH_FM                                      BIT(6)
-#define LIS3DH_TR                                      BIT(5)
-#define LIS3DH_FTH                                     BIT(0)
-
-//CONTROL REG3 bit mask
-#define LIS3DH_CLICK_ON_PIN_INT1_ENABLE                0x80
-#define LIS3DH_CLICK_ON_PIN_INT1_DISABLE               0x00
-#define LIS3DH_I1_INT1_ON_PIN_INT1_ENABLE              0x40
-#define LIS3DH_I1_INT1_ON_PIN_INT1_DISABLE             0x00
-#define LIS3DH_I1_INT2_ON_PIN_INT1_ENABLE              0x20
-#define LIS3DH_I1_INT2_ON_PIN_INT1_DISABLE             0x00
-#define LIS3DH_I1_DRDY1_ON_INT1_ENABLE                 0x10
-#define LIS3DH_I1_DRDY1_ON_INT1_DISABLE                0x00
-#define LIS3DH_I1_DRDY2_ON_INT1_ENABLE                 0x08
-#define LIS3DH_I1_DRDY2_ON_INT1_DISABLE                0x00
-#define LIS3DH_WTM_ON_INT1_ENABLE                      0x04
-#define LIS3DH_WTM_ON_INT1_DISABLE                     0x00
-#define LIS3DH_INT1_OVERRUN_ENABLE                     0x02
-#define LIS3DH_INT1_OVERRUN_DISABLE                    0x00
-
-//CONTROL REG6 bit mask
-#define LIS3DH_CLICK_ON_PIN_INT2_ENABLE                0x80
-#define LIS3DH_CLICK_ON_PIN_INT2_DISABLE               0x00
-#define LIS3DH_I2_INT1_ON_PIN_INT2_ENABLE              0x40
-#define LIS3DH_I2_INT1_ON_PIN_INT2_DISABLE             0x00
-#define LIS3DH_I2_INT2_ON_PIN_INT2_ENABLE              0x20
-#define LIS3DH_I2_INT2_ON_PIN_INT2_DISABLE             0x00
-#define LIS3DH_I2_BOOT_ON_INT2_ENABLE                  0x10
-#define LIS3DH_I2_BOOT_ON_INT2_DISABLE                 0x00
-#define LIS3DH_INT_ACTIVE_HIGH                         0x00
-#define LIS3DH_INT_ACTIVE_LOW                          0x02
-
-//INT1_CFG bit mask
-#define LIS3DH_INT1_AND                                0x80
-#define LIS3DH_INT1_OR                                 0x00
-#define LIS3DH_INT1_ZHIE_ENABLE                        0x20
-#define LIS3DH_INT1_ZHIE_DISABLE                       0x00
-#define LIS3DH_INT1_ZLIE_ENABLE                        0x10
-#define LIS3DH_INT1_ZLIE_DISABLE                       0x00
-#define LIS3DH_INT1_YHIE_ENABLE                        0x08
-#define LIS3DH_INT1_YHIE_DISABLE                       0x00
-#define LIS3DH_INT1_YLIE_ENABLE                        0x04
-#define LIS3DH_INT1_YLIE_DISABLE                       0x00
-#define LIS3DH_INT1_XHIE_ENABLE                        0x02
-#define LIS3DH_INT1_XHIE_DISABLE                       0x00
-#define LIS3DH_INT1_XLIE_ENABLE                        0x01
-#define LIS3DH_INT1_XLIE_DISABLE                       0x00
-
-//INT1_SRC bit mask
-#define LIS3DH_INT1_SRC_IA                             0x40
-#define LIS3DH_INT1_SRC_ZH                             0x20
-#define LIS3DH_INT1_SRC_ZL                             0x10
-#define LIS3DH_INT1_SRC_YH                             0x08
-#define LIS3DH_INT1_SRC_YL                             0x04
-#define LIS3DH_INT1_SRC_XH                             0x02
-#define LIS3DH_INT1_SRC_XL                             0x01
-
-//INT1 REGISTERS
-#define LIS3DH_INT1_THS                                0x32
-#define LIS3DH_INT1_DURATION                           0x33
-
-//INTERRUPT 1 SOURCE REGISTER
-#define LIS3DH_INT1_SRC             0x31
-
-//FIFO Source Register bit Mask
-#define LIS3DH_FIFO_SRC_WTM                            0x80
-#define LIS3DH_FIFO_SRC_OVRUN                          0x40
-#define LIS3DH_FIFO_SRC_EMPTY                          0x20
-  
-//INTERRUPT CLICK REGISTER
-#define LIS3DH_CLICK_CFG                0x38
-//INTERRUPT CLICK CONFIGURATION bit mask
-#define LIS3DH_ZD_ENABLE                               0x20
-#define LIS3DH_ZD_DISABLE                              0x00
-#define LIS3DH_ZS_ENABLE                               0x10
-#define LIS3DH_ZS_DISABLE                              0x00
-#define LIS3DH_YD_ENABLE                               0x08
-#define LIS3DH_YD_DISABLE                              0x00
-#define LIS3DH_YS_ENABLE                               0x04
-#define LIS3DH_YS_DISABLE                              0x00
-#define LIS3DH_XD_ENABLE                               0x02
-#define LIS3DH_XD_DISABLE                              0x00
-#define LIS3DH_XS_ENABLE                               0x01
-#define LIS3DH_XS_DISABLE                              0x00
-
-//INTERRUPT CLICK SOURCE REGISTER
-#define LIS3DH_CLICK_SRC                               0x39
-//INTERRUPT CLICK SOURCE REGISTER bit mask
-#define LIS3DH_IA                                      0x40
-#define LIS3DH_DCLICK                                  0x20
-#define LIS3DH_SCLICK                                  0x10
-#define LIS3DH_CLICK_SIGN                              0x08
-#define LIS3DH_CLICK_Z                                 0x04
-#define LIS3DH_CLICK_Y                                 0x02
-#define LIS3DH_CLICK_X                                 0x01
-
-//Click-click Register
-#define LIS3DH_CLICK_THS                               0x3A
-#define LIS3DH_TIME_LIMIT                              0x3B
-#define LIS3DH_TIME_LATENCY                            0x3C
-#define LIS3DH_TIME_WINDOW                             0x3D
-
-//OUTPUT REGISTER
-#define LIS3DH_OUT_X_L                  0x28
-#define LIS3DH_OUT_X_H                  0x29
-#define LIS3DH_OUT_Y_L                  0x2A
-#define LIS3DH_OUT_Y_H                  0x2B
-#define LIS3DH_OUT_Z_L                  0x2C
-#define LIS3DH_OUT_Z_H                  0x2D
-
-//AUX REGISTER
-#define LIS3DH_OUT_1_L                  0x08
-#define LIS3DH_OUT_1_H                  0x09
-#define LIS3DH_OUT_2_L                  0x0A
-#define LIS3DH_OUT_2_H                  0x0B
-#define LIS3DH_OUT_3_L                  0x0C
-#define LIS3DH_OUT_3_H                  0x0D
-
-//STATUS REGISTER bit mask
-#define LIS3DH_STATUS_REG_ZYXOR                        0x80    // 1 :   new data set has over written the previous one
-                            // 0    :   no overrun has occurred (default)   
-#define LIS3DH_STATUS_REG_ZOR                          0x40    // 0 :   no overrun has occurred (default)
-                            // 1    :   new Z-axis data has over written the previous one
-#define LIS3DH_STATUS_REG_YOR                          0x20    // 0 :   no overrun has occurred (default)
-                            // 1    :   new Y-axis data has over written the previous one
-#define LIS3DH_STATUS_REG_XOR                          0x10    // 0 :   no overrun has occurred (default)
-                            // 1    :   new X-axis data has over written the previous one
-#define LIS3DH_STATUS_REG_ZYXDA                        0x08    // 0 :   a new set of data is not yet avvious one
-                                                        // 1    :   a new set of data is available 
-#define LIS3DH_STATUS_REG_ZDA                          0x04    // 0 :   a new data for the Z-Axis is not availvious one
-                                                        // 1    :   a new data for the Z-Axis is available
-#define LIS3DH_STATUS_REG_YDA                          0x02    // 0 :   a new data for the Y-Axis is not available
-                                                        // 1    :   a new data for the Y-Axis is available
-#define LIS3DH_STATUS_REG_XDA                          0x01    // 0 :   a new data for the X-Axis is not available
-
-#define LIS3DH_DATAREADY_BIT                           LIS3DH_STATUS_REG_ZYXDA
-
-
-//STATUS AUX REGISTER bit mask
-#define LIS3DH_STATUS_AUX_321OR                         0x80
-#define LIS3DH_STATUS_AUX_3OR                           0x40
-#define LIS3DH_STATUS_AUX_2OR                           0x20
-#define LIS3DH_STATUS_AUX_1OR                           0x10
-#define LIS3DH_STATUS_AUX_321DA                         0x08
-#define LIS3DH_STATUS_AUX_3DA                           0x04
-#define LIS3DH_STATUS_AUX_2DA                           0x02
-#define LIS3DH_STATUS_AUX_1DA                           0x01
-
-#define LIS3DH_MEMS_I2C_ADDRESS                 0x33
-
-//FIFO REGISTERS
-#define LIS3DH_FIFO_CTRL_REG                    0x2E
-#define LIS3DH_FIFO_SRC_REG                 0x2F
-
-
-/* Exported macro ------------------------------------------------------------*/
-
-#ifndef __SHARED__MACROS
-
-#define __SHARED__MACROS
-#define ValBit(VAR,Place)         (VAR & (1<<Place))
-#define BIT(x) ( (x) )
-
-#endif /*__SHARED__MACROS*/
-
-class LIS3DH
-{
-public:  
-    LIS3DH(PinName mosi, PinName miso, PinName ss, PinName sck);
-    ~LIS3DH();
-    
-    //own functions 
-    u8_t InitLIS3DH(LIS3DH_Mode_t Mode, LIS3DH_ODR_t Odr, LIS3DH_Fullscale_t Grange);
-    u8_t SetLIS3DHActivityDetection(uint8_t Th, LIS3DH_Int1Mode_t Mode, uint8_t OnOff);
-
-    //Sensor Configuration Functions
-    status_t LIS3DH_SetODR(LIS3DH_ODR_t ov);
-    status_t LIS3DH_SetMode(LIS3DH_Mode_t md);
-    status_t LIS3DH_SetAxis(LIS3DH_Axis_t axis);
-    status_t LIS3DH_SetFullScale(LIS3DH_Fullscale_t fs);
-    status_t LIS3DH_SetBDU(State_t bdu);
-  status_t LIS3DH_SetBLE(LIS3DH_Endianess_t ble);
-  status_t LIS3DH_SetSelfTest(LIS3DH_SelfTest_t st);
-    status_t LIS3DH_SetTemperature(State_t state);
-    status_t LIS3DH_SetADCAux(State_t state);
-
-  //Filtering Functions
-  status_t LIS3DH_HPFClickEnable(State_t hpfe);
-  status_t LIS3DH_HPFAOI1Enable(State_t hpfe);
-  status_t LIS3DH_HPFAOI2Enable(State_t hpfe);
-  status_t LIS3DH_SetHPFMode(LIS3DH_HPFMode_t hpf);
-  status_t LIS3DH_SetHPFCutOFF(LIS3DH_HPFCutOffFreq_t hpf);
-  status_t LIS3DH_SetFilterDataSel(State_t state);
-
-    //Interrupt Functions
-    status_t LIS3DH_SetInt1Pin(LIS3DH_IntPinConf_t pinConf);
-    status_t LIS3DH_SetInt2Pin(LIS3DH_IntPinConf_t pinConf);
-  status_t LIS3DH_Int1LatchEnable(State_t latch);
-    status_t LIS3DH_ResetInt1Latch(void);
-    status_t LIS3DH_SetIntConfiguration(LIS3DH_Int1Conf_t ic);
-    status_t LIS3DH_SetInt1Threshold(u8_t ths);
-  status_t LIS3DH_SetInt1Duration(LIS3DH_Int1Conf_t id);
-    status_t LIS3DH_SetIntMode(LIS3DH_Int1Mode_t ic);
-  status_t LIS3DH_SetClickCFG(u8_t status);
-    status_t LIS3DH_SetClickTHS(u8_t ths);
-    status_t LIS3DH_SetClickLIMIT(u8_t t_limit);
-    status_t LIS3DH_SetClickLATENCY(u8_t t_latency);
-    status_t LIS3DH_SetClickWINDOW(u8_t t_window);
-  status_t LIS3DH_SetInt6D4DConfiguration(LIS3DH_INT_6D_4D_t ic);
-  status_t LIS3DH_GetInt1Src(u8_t* val);
-  status_t LIS3DH_GetInt1SrcBit(u8_t statusBIT, u8_t* val);
-
-  //FIFO Functions
-  status_t LIS3DH_FIFOModeEnable(LIS3DH_FifoMode_t fm);
-  status_t LIS3DH_SetWaterMark(u8_t wtm);
-  status_t LIS3DH_SetTriggerInt(LIS3DH_TrigInt_t tr);
-  status_t LIS3DH_GetFifoSourceReg(u8_t* val);
-  status_t LIS3DH_GetFifoSourceBit(u8_t statusBIT, u8_t* val);
-  status_t LIS3DH_GetFifoSourceFSS(u8_t* val);
-
-    //Other Reading Functions   
-  status_t LIS3DH_GetStatusReg(u8_t* val);
-  status_t LIS3DH_GetStatusBit(u8_t statusBIT, u8_t* val);
-  status_t LIS3DH_GetStatusAUXBit(u8_t statusBIT, u8_t* val);
-  status_t LIS3DH_GetStatusAUX(u8_t* val);
-
-    status_t LIS3DH_GetAccAxesRaw(AxesRaw_t* buff);
-  status_t LIS3DH_GetAuxRaw(LIS3DH_Aux123Raw_t* buff);
-  status_t LIS3DH_GetClickResponse(u8_t* val);
-    status_t LIS3DH_GetTempRaw(i8_t* val);
-    status_t LIS3DH_GetWHO_AM_I(u8_t* val);
-  status_t LIS3DH_Get6DPosition(u8_t* val);
-  
-private:
-    u8_t LIS3DH_ReadReg(u8_t Reg, u8_t* Data);
-    u8_t LIS3DH_WriteReg(u8_t WriteAddr, u8_t Data);
-        
-    
-protected:
-    SPI  _spi;
-    DigitalOut _ss;
-  
-};
-} //Namespace
-#endif
diff -r bd7fd35251ab -r b221ba23b37f Si7021.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Si7021.cpp	Mon Jan 25 14:36:57 2016 +0000
@@ -0,0 +1,103 @@
+#include "Si7021.h"
+
+SI7021_I2C::SI7021_I2C(PinName sda, PinName scl) : i2c_(sda, scl) 
+{    
+    //400kHz, allowing us to use the fastest data rates.
+    i2c_.frequency(400000);   
+}
+
+uint8_t SI7021_I2C::readBytes(uint8_t *values, int8_t length, bool waitConversion)
+{
+    uint8_t Status=0;
+
+    if(!i2c_.write(SI7021_ADDR, (const char*)values, 1,0))
+        Status=1;
+    
+    //Wait the measurement time
+    if(waitConversion)
+        wait_ms(23);
+    
+    if(!i2c_.read(SI7021_ADDR, (char*)values, length,0))
+        Status=1;
+    return(Status);
+}
+
+
+float SI7021_I2C::Measure_Temp(void)
+{
+    float Temperature;
+    uint16_t ConvValue;
+    uint8_t *Ptr;
+    uint8_t Data[2];
+    
+    Data[0]=SI7021_MEASURE_TEMPERATURE_HOLD_MASTER;
+    if(readBytes(Data,2, 1))
+    {
+        Ptr=(uint8_t*)&ConvValue;
+        Ptr[0]=Data[1];
+        Ptr[1]=Data[0];
+        
+        Temperature=(((float)ConvValue)/65536)*175-46.85;
+    }
+    else
+    {
+        Temperature=1234;
+    }
+    
+    return(Temperature);
+}
+
+float SI7021_I2C::get_HumidityTemp(void)
+{
+    float Temperature;
+    uint16_t ConvValue;
+    uint8_t *Ptr;
+    uint8_t Data[2];
+    
+    Data[0]=SI7021_READ_TEMPERATURE;
+    if(readBytes(Data,2, 0))
+    {
+        Ptr=(uint8_t*)&ConvValue;
+        Ptr[0]=Data[1];
+        Ptr[1]=Data[0];
+        
+        Temperature=(((float)ConvValue)/65536)*175-46.85;
+    }
+    else
+    {
+        Temperature=1234;
+    }
+    
+    return(Temperature);
+}
+
+void SI7021_I2C::Measure_Humidity_Temp(float *humidity, float *temperature)
+{
+    float Humidity;
+    uint16_t ConvValueHum;
+    uint8_t *Ptr;
+    uint8_t Data[2];
+    
+    Data[0]=SI7021_MEASURE_RH_NO_HOLD_MASSTER;
+    
+    if(readBytes(Data,2, 1))
+    {
+    
+        Ptr=(uint8_t*)&ConvValueHum;
+        Ptr[0]=Data[1];
+        Ptr[1]=Data[0];
+        
+        Humidity=(((float)ConvValueHum)/65536)*125-6;
+        
+        if(Humidity<0)
+            Humidity=0;
+        if(Humidity>100)
+            Humidity=100;           
+    }
+    else
+        Humidity=1234;  
+
+    *humidity = Humidity;
+    *temperature = get_HumidityTemp();
+    
+}
diff -r bd7fd35251ab -r b221ba23b37f Si7021.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Si7021.h	Mon Jan 25 14:36:57 2016 +0000
@@ -0,0 +1,37 @@
+#ifndef SI7021_H
+#define SI7021_H
+
+#include "mbed.h"
+
+#define SI7021_ADDR 0x80
+#define SI7021_CONTROL_BYTE 0x3A    //Reset settings (default values ok, no need to write)
+#define SI7021_MEASURE_RH_HOLD_MASTER 0xE5
+#define SI7021_MEASURE_RH_NO_HOLD_MASSTER 0xF5
+#define SI7021_MEASURE_TEMPERATURE_HOLD_MASTER 0xE3
+#define SI7021_MEASURE_TEMPERATURE_NO_HOLD_MASTER 0xF3
+#define SI7021_READ_TEMPERATURE 0xE0
+#define SI7021_RESET 0xFE
+#define SI7021_WRITE_USER_REG1 0xE6
+#define SI7021_READ_USER_REG1 0xE7
+#define SI7021_READ_EID1_1 0xFA
+#define SI7021_READ_EID1_2 0x0F
+#define SI7021_READ_EID2_1 0xFC
+#define SI7021_READ_EID2_2 0xC9
+#define SI7021_READ_FW_REVISION_1 0x84
+#define SI7021_READ_FW_REVISION_2 0xB8
+
+class SI7021_I2C {
+
+public:
+    SI7021_I2C(PinName sda, PinName scl);
+
+    float Measure_Temp(void);
+    void Measure_Humidity_Temp(float *humidity, float *temperature);
+
+private:
+    float get_HumidityTemp(void);
+    uint8_t readBytes(uint8_t *values, int8_t length, bool waitConversion); 
+    I2C i2c_;
+};
+
+#endif
diff -r bd7fd35251ab -r b221ba23b37f main.cpp
--- a/main.cpp	Mon Jan 25 13:27:15 2016 +0000
+++ b/main.cpp	Mon Jan 25 14:36:57 2016 +0000
@@ -1,8 +1,6 @@
 /** 
-*   LIS3DH & BLE broadcast example for VTT Node V3 & mbed
-*   broadcasts accelerometer xyz values. 
-*   Also generates LIS3DH interrupt on position change and lights up leds based on that interrupt.
-*   As a bonus, read temperature values from SOC and transmit those as well.
+*   Temperature/humidity/pressure broadcast example for mbed / VTT Node V3   
+*   o   Using BMP180 & Si7021 and onboard temperature sensor
 *   Juho Eskeli, VTT
 */
 
@@ -18,9 +16,11 @@
 #endif
 
 #include "AT45.h"
-#include "LIS3DH.h"
 #include "TMP_nrf51.h"
 
+#include "BMP180.h"
+#include "Si7021.h"
+
 //interrupt /gpio configuration
 #include "nrf_gpio.h"
 #include "nrf_gpiote.h"
@@ -35,8 +35,10 @@
 #define MISO SPI_PSELMISO0
 #define CS SPI_PSELSS0
 #define SCLK SPI_PSELSCK0
-static LIS3DH lis(MOSI, MISO, CS, SCLK);    
-static TMP_nrf51  tempSensor;                         
+
+static TMP_nrf51  tempSensor;   
+BMP180 bmp180(I2C_SDA0, I2C_SCL0);
+SI7021_I2C si7021(I2C_SDA0, I2C_SCL0);                
                                                                                             
 DigitalOut myled1(LED1);
 DigitalOut myled2(LED2);
@@ -45,79 +47,23 @@
 DigitalOut AT_CS(p5); //Dataflash CS
 DigitalOut AT_RS(p6); //Dataflash reset
 
-/** @brief Function for initializing the GPIO Tasks/Events peripheral.
-*/
-static void gpiote_init(void)
-{
-    // Configure accelerometer interrupt pin
-    nrf_gpio_cfg_input(3, NRF_GPIO_PIN_PULLDOWN);
-        //nrf_gpio_cfg_input(4, NRF_GPIO_PIN_PULLDOWN);
-    
-    // Configure GPIOTE channel 0 to generate event when MOTION_INTERRUPT_PIN_NUMBER goes from Low to High
-    nrf_gpiote_event_config(0, 3, NRF_GPIOTE_POLARITY_LOTOHI);   //accelerometer int1
-        //nrf_gpiote_event_config(1, 4, NRF_GPIOTE_POLARITY_LOTOHI);   //accelerometer int2
-
-    // Enable interrupt for NRF_GPIOTE->EVENTS_IN[0] event
-    NRF_GPIOTE->INTENSET  = GPIOTE_INTENSET_IN0_Msk;
-    //NRF_GPIOTE->INTENSET |= GPIOTE_INTENSET_IN1_Msk;
-}
-
-extern "C"
-void GPIOTE_IRQHandler(void)
-{
-    // Event causing the interrupt must be cleared
-    NRF_GPIOTE->EVENTS_IN[0]  = 0;
-    //NRF_GPIOTE->EVENTS_IN[1]  = 0;
-    lis.LIS3DH_ResetInt1Latch();
-    
-    myled1 = !myled1;
-    myled2 = !myled2;
-}
-
-void disconnect_input_buffers()
-{
-    for(uint8_t i = 0; i < 3; i++)
-    {
-                    NRF_GPIO->PIN_CNF[i] = (GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos)
-                                        | (GPIO_PIN_CNF_DRIVE_S0S1 << GPIO_PIN_CNF_DRIVE_Pos)
-                                        | (GPIO_PIN_CNF_PULL_Disabled << GPIO_PIN_CNF_PULL_Pos)
-                                        | (GPIO_PIN_CNF_INPUT_Disconnect << GPIO_PIN_CNF_INPUT_Pos)
-                                        | (GPIO_PIN_CNF_DIR_Output << GPIO_PIN_CNF_DIR_Pos);
-    }   
-    //Omit accelerometer interrupt pins (3&4)
-    for(uint8_t i = 5; i < 21; i++)
-    {
-                    NRF_GPIO->PIN_CNF[i] = (GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos)
-                                        | (GPIO_PIN_CNF_DRIVE_S0S1 << GPIO_PIN_CNF_DRIVE_Pos)
-                                        | (GPIO_PIN_CNF_PULL_Disabled << GPIO_PIN_CNF_PULL_Pos)
-                                        | (GPIO_PIN_CNF_INPUT_Disconnect << GPIO_PIN_CNF_INPUT_Pos)
-                                        | (GPIO_PIN_CNF_DIR_Output << GPIO_PIN_CNF_DIR_Pos);
-    }   
-    //Omit I2C pins (21 & 22)
-    for(uint8_t i = 23; i < 31; i++)
-    {
-                    NRF_GPIO->PIN_CNF[i] = (GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos)
-                                        | (GPIO_PIN_CNF_DRIVE_S0S1 << GPIO_PIN_CNF_DRIVE_Pos)
-                                        | (GPIO_PIN_CNF_PULL_Disabled << GPIO_PIN_CNF_PULL_Pos)
-                                        | (GPIO_PIN_CNF_INPUT_Disconnect << GPIO_PIN_CNF_INPUT_Pos)
-                                        | (GPIO_PIN_CNF_DIR_Output << GPIO_PIN_CNF_DIR_Pos);
-    }
-}
-
 __packed struct ApplicationData_t {
     uint16_t                    applicationSpecificId; /* An ID used to identify temperature value in the manufacture specific AD data field */
-    TMP_nrf51::tmpSensorValue_t tmpSensorValue;      /* User defined application data */
-    int8_t                      accel_temp;    
-    AxesRaw_t                   accel_raw;        
+    TMP_nrf51::tmpSensorValue_t tmpSensorValue;      /* User defined application data */           
+    int16_t                     bmp180_temp;
+    uint32_t                    bmp180_press;
+    float                       si7021_temperature;
+    float                       si7021_humidity;
 };
 
 void setupApplicationData(ApplicationData_t &appData)
 {
     static const uint16_t APP_SPECIFIC_ID_TEST = 0xFEFE;
     appData.applicationSpecificId = APP_SPECIFIC_ID_TEST;
-    appData.tmpSensorValue        = tempSensor.get();
-    lis.LIS3DH_GetAccAxesRaw(&appData.accel_raw);
-    lis.LIS3DH_GetTempRaw(&appData.accel_temp);    
+    appData.tmpSensorValue        = tempSensor.get();          
+    appData.bmp180_temp           = bmp180.BMP180GetTemperature();
+    appData.bmp180_press          = bmp180.BMP180GetPressure();
+    si7021.Measure_Humidity_Temp((float*)&(appData.si7021_humidity), (float*)&(appData.si7021_temperature));
 }
  
 void disconnectionCallback(const Gap::DisconnectionCallbackParams_t *params)
@@ -142,6 +88,23 @@
     AT_RS = 1;
 }
 
+bool init_bmp180(void) 
+{    
+    // Read the WHO_AM_I register of the BMP-180, this is a good test of communication
+    uint8_t c = bmp180.readByte(BMP180_ADDRESS, BMP180_WHO_AM_I);   
+    if(c == 0x55) {
+        //BMP-180 should be 0x55
+        //BMP-180 online...
+        bmp180.BMP180Calibration();
+        //BMP-180 calibration complete        
+        return true;
+    }
+    else 
+    {                
+        return false;
+    }
+}
+
 int main() 
 {    
     //LEDS off
@@ -156,25 +119,9 @@
     spi.frequency(8000000); 
     //setup AT45 dataflash to powersaving mode
     AT45* flash = new AT45(spi, p5);    
-    flash->ultra_deep_power_down(true); 
-    
-    //Accelerometer interrupt pin configuration
-    gpiote_init();  
-    
-    //Disconnect input buffers to save power
-    disconnect_input_buffers();
+    flash->ultra_deep_power_down(true);     
     
-    //Initialize LIS3DH driver
-    lis.InitLIS3DH(LIS3DH_NORMAL, LIS3DH_ODR_100Hz, LIS3DH_FULLSCALE_2);    //Init Acc-sensor
-    //enable threshold to generate interrupt
-    lis.SetLIS3DHActivityDetection(3, LIS3DH_INT_MODE_6D_POSITION, 1);  
-    
-    // Enable GPIOTE interrupt in Nested Vector Interrupt Controller.
-    NVIC_ClearPendingIRQ(GPIOTE_IRQn);
-    NRF_GPIOTE->INTENSET = GPIOTE_INTENSET_PORT_Set << GPIOTE_INTENSET_PORT_Pos;
-    NVIC_SetPriority(GPIOTE_IRQn, 1);
-    NVIC_EnableIRQ(GPIOTE_IRQn);
-    //sd_nvic_EnableIRQ(GPIOTE_IRQn);    
+    init_bmp180();
     
     //Initialize BLE stuff
     ble.init();