Răsfoiți Sursa

Initial Version

add Grove-3Aixi Digital Accelerometer-H3LIS331DL
lawliet zou 11 ani în urmă
comite
d959dc26e1
8 a modificat fișierele cu 2009 adăugiri și 0 ștergeri
  1. 22 0
      .gitattributes
  2. 215 0
      .gitignore
  3. 1289 0
      H3LIS331DL.cpp
  4. 315 0
      H3LIS331DL.h
  5. 21 0
      License.txt
  6. 36 0
      README.md
  7. 69 0
      examples/H3LIS331DL_AdjVal/H3LIS331DL_AdjVal.ino
  8. 42 0
      examples/H3LIS331DL_Demo/H3LIS331DL_Demo.ino

+ 22 - 0
.gitattributes

@@ -0,0 +1,22 @@
+# Auto detect text files and perform LF normalization
+* text=auto
+
+# Custom for Visual Studio
+*.cs     diff=csharp
+*.sln    merge=union
+*.csproj merge=union
+*.vbproj merge=union
+*.fsproj merge=union
+*.dbproj merge=union
+
+# Standard to msysgit
+*.doc	 diff=astextplain
+*.DOC	 diff=astextplain
+*.docx diff=astextplain
+*.DOCX diff=astextplain
+*.dot  diff=astextplain
+*.DOT  diff=astextplain
+*.pdf  diff=astextplain
+*.PDF	 diff=astextplain
+*.rtf	 diff=astextplain
+*.RTF	 diff=astextplain

+ 215 - 0
.gitignore

@@ -0,0 +1,215 @@
+#################
+## Eclipse
+#################
+
+*.pydevproject
+.project
+.metadata
+bin/
+tmp/
+*.tmp
+*.bak
+*.swp
+*~.nib
+local.properties
+.classpath
+.settings/
+.loadpath
+
+# External tool builders
+.externalToolBuilders/
+
+# Locally stored "Eclipse launch configurations"
+*.launch
+
+# CDT-specific
+.cproject
+
+# PDT-specific
+.buildpath
+
+
+#################
+## Visual Studio
+#################
+
+## Ignore Visual Studio temporary files, build results, and
+## files generated by popular Visual Studio add-ons.
+
+# User-specific files
+*.suo
+*.user
+*.sln.docstates
+
+# Build results
+
+[Dd]ebug/
+[Rr]elease/
+x64/
+build/
+[Bb]in/
+[Oo]bj/
+
+# MSTest test Results
+[Tt]est[Rr]esult*/
+[Bb]uild[Ll]og.*
+
+*_i.c
+*_p.c
+*.ilk
+*.meta
+*.obj
+*.pch
+*.pdb
+*.pgc
+*.pgd
+*.rsp
+*.sbr
+*.tlb
+*.tli
+*.tlh
+*.tmp
+*.tmp_proj
+*.log
+*.vspscc
+*.vssscc
+.builds
+*.pidb
+*.log
+*.scc
+
+# Visual C++ cache files
+ipch/
+*.aps
+*.ncb
+*.opensdf
+*.sdf
+*.cachefile
+
+# Visual Studio profiler
+*.psess
+*.vsp
+*.vspx
+
+# Guidance Automation Toolkit
+*.gpState
+
+# ReSharper is a .NET coding add-in
+_ReSharper*/
+*.[Rr]e[Ss]harper
+
+# TeamCity is a build add-in
+_TeamCity*
+
+# DotCover is a Code Coverage Tool
+*.dotCover
+
+# NCrunch
+*.ncrunch*
+.*crunch*.local.xml
+
+# Installshield output folder
+[Ee]xpress/
+
+# DocProject is a documentation generator add-in
+DocProject/buildhelp/
+DocProject/Help/*.HxT
+DocProject/Help/*.HxC
+DocProject/Help/*.hhc
+DocProject/Help/*.hhk
+DocProject/Help/*.hhp
+DocProject/Help/Html2
+DocProject/Help/html
+
+# Click-Once directory
+publish/
+
+# Publish Web Output
+*.Publish.xml
+*.pubxml
+
+# NuGet Packages Directory
+## TODO: If you have NuGet Package Restore enabled, uncomment the next line
+#packages/
+
+# Windows Azure Build Output
+csx
+*.build.csdef
+
+# Windows Store app package directory
+AppPackages/
+
+# Others
+sql/
+*.Cache
+ClientBin/
+[Ss]tyle[Cc]op.*
+~$*
+*~
+*.dbmdl
+*.[Pp]ublish.xml
+*.pfx
+*.publishsettings
+
+# RIA/Silverlight projects
+Generated_Code/
+
+# Backup & report files from converting an old project file to a newer
+# Visual Studio version. Backup files are not needed, because we have git ;-)
+_UpgradeReport_Files/
+Backup*/
+UpgradeLog*.XML
+UpgradeLog*.htm
+
+# SQL Server files
+App_Data/*.mdf
+App_Data/*.ldf
+
+#############
+## Windows detritus
+#############
+
+# Windows image file caches
+Thumbs.db
+ehthumbs.db
+
+# Folder config file
+Desktop.ini
+
+# Recycle Bin used on file shares
+$RECYCLE.BIN/
+
+# Mac crap
+.DS_Store
+
+
+#############
+## Python
+#############
+
+*.py[co]
+
+# Packages
+*.egg
+*.egg-info
+dist/
+build/
+eggs/
+parts/
+var/
+sdist/
+develop-eggs/
+.installed.cfg
+
+# Installer logs
+pip-log.txt
+
+# Unit test / coverage reports
+.coverage
+.tox
+
+#Translations
+*.mo
+
+#Mr Developer
+.mr.developer.cfg

+ 1289 - 0
H3LIS331DL.cpp

@@ -0,0 +1,1289 @@
+#include "H3LIS331DL.h"
+#include <Wire.h>
+
+void H3LIS331DL::init(H3LIS331DL_ODR_t  odr,H3LIS331DL_Mode_t mode,H3LIS331DL_Fullscale_t fullScale){
+
+	Wire.begin();
+	//set output data rate
+	setODR(odr);
+    //set PowerMode 
+    setMode( mode);
+    //set Fullscale
+	setFullScale( fullScale);
+    //set axis Enable
+    setAxis( H3LIS331DL_X_ENABLE | H3LIS331DL_Y_ENABLE |  H3LIS331DL_Z_ENABLE);
+}
+
+void H3LIS331DL::importPara(int16_t val_x, int16_t val_y, int16_t val_z)
+{
+	_adjVal[0] = val_x;
+	_adjVal[1] = val_y;
+	_adjVal[2] = val_z;
+}
+void H3LIS331DL::readXYZ(int16_t* x, int16_t* y, int16_t* z)
+{
+    //get Acceleration Raw data  
+    AxesRaw_t data;
+    status_t response = getAccAxesRaw(&data);
+    if(MEMS_SUCCESS == response){
+		*x = (data.AXIS_X - _adjVal[0]);
+        *y = (data.AXIS_Y - _adjVal[1]);
+        *z = (data.AXIS_Z - _adjVal[2]);
+    }
+}
+
+void H3LIS331DL::getAcceleration(double* xyz)
+{
+	AxesRaw_t data;
+	double gains = 0.003;
+	getAccAxesRaw(&data);
+	
+	xyz[0] = (data.AXIS_X - _adjVal[0]) * gains;
+	xyz[1] = (data.AXIS_Y - _adjVal[1]) * gains;
+	xyz[2] = (data.AXIS_Z - _adjVal[2]) * gains;
+}
+
+
+/*******************************************************************************
+* Function Name  : getWHO_AM_I
+* Description    : Read identification code from H3LIS331DL::WHO_AM_I register
+* Input          : char to be filled with the Device identification Value
+* Output         : None
+* Return         : Status [value of FSS]
+*******************************************************************************/
+status_t H3LIS331DL::getWHO_AM_I(byte* val){
+  
+    if( !readReg(H3LIS331DL_MEMS_I2C_ADDRESS, H3LIS331DL_WHO_AM_I, val) )
+        return MEMS_ERROR;
+  
+    return MEMS_SUCCESS;
+}
+
+
+/*******************************************************************************
+* Function Name  : setODR
+* Description    : Sets H3LIS331DL Accelerometer Output Data Rate 
+* Input          : Output Data Rate
+* Output         : None
+* Return         : Status [MEMS_ERROR, MEMS_SUCCESS]
+*******************************************************************************/
+status_t H3LIS331DL::setODR(H3LIS331DL_ODR_t dr){
+    byte value;
+  
+    if( !readReg(H3LIS331DL_MEMS_I2C_ADDRESS, H3LIS331DL_CTRL_REG1, &value) )
+        return MEMS_ERROR;
+  
+    value &= 0xE7;
+    value |= dr<<H3LIS331DL_DR;
+  
+    if( !writeReg(H3LIS331DL_MEMS_I2C_ADDRESS, H3LIS331DL_CTRL_REG1, value) )
+        return MEMS_ERROR;
+  
+    return MEMS_SUCCESS;
+}
+
+
+/*******************************************************************************
+* Function Name  : setMode
+* Description    : Sets H3LIS331DLH Accelerometer Operating Mode
+* Input          : Modality (H3LIS331DL_LOW_POWER, H3LIS331DL_NORMAL, H3LIS331DL_POWER_DOWN...)
+* Output         : None
+* Return         : Status [MEMS_ERROR, MEMS_SUCCESS]
+*******************************************************************************/
+status_t H3LIS331DL::setMode(H3LIS331DL_Mode_t pm) {
+    byte value;
+  
+    if( !readReg(H3LIS331DL_MEMS_I2C_ADDRESS, H3LIS331DL_CTRL_REG1, &value) )
+        return MEMS_ERROR;
+  
+    value &= 0x1F;
+    value |= (pm<<H3LIS331DL_PM);   
+  
+    if( !writeReg(H3LIS331DL_MEMS_I2C_ADDRESS, H3LIS331DL_CTRL_REG1, value) )
+        return MEMS_ERROR;
+  
+    return MEMS_SUCCESS;
+}
+
+/*******************************************************************************
+* Function Name  : setAxis
+* Description    : Enable/Disable LIS331DLH Axis
+* Input          : H3LIS331DL_X_ENABLE/H3LIS331DL_X_DISABLE | H3LIS331DL_Y_ENABLE/H3LIS331DL_Y_DISABLE
+                   | H3LIS331DL_Z_ENABLE/H3LIS331DL_Z_DISABLE
+* Output         : None
+* Note           : You MUST use all input variable in the argument, as example
+* Return         : Status [MEMS_ERROR, MEMS_SUCCESS]
+*******************************************************************************/
+status_t H3LIS331DL::setAxis(H3LIS331DL_Axis_t axis) {
+  byte value;
+  
+  if( !readReg(H3LIS331DL_MEMS_I2C_ADDRESS, H3LIS331DL_CTRL_REG1, &value) )
+    return MEMS_ERROR;
+  
+  value &= 0xF8;
+  value |= (0x07 & axis);
+  
+  if( !writeReg(H3LIS331DL_MEMS_I2C_ADDRESS, H3LIS331DL_CTRL_REG1, value) )
+    return MEMS_ERROR;   
+  
+  return MEMS_SUCCESS;
+}
+
+
+/*******************************************************************************
+* Function Name  : setFullScale
+* Description    : Sets the LIS331DLH FullScale
+* Input          : H3LIS331DL_FULLSCALE_2/H3LIS331DL_FULLSCALE_4/H3LIS331DL_FULLSCALE_8
+* Output         : None
+* Return         : Status [MEMS_ERROR, MEMS_SUCCESS]
+*******************************************************************************/
+status_t H3LIS331DL::setFullScale(H3LIS331DL_Fullscale_t fs) {
+  byte value;
+  
+  if( !readReg(H3LIS331DL_MEMS_I2C_ADDRESS, H3LIS331DL_CTRL_REG4, &value) )
+    return MEMS_ERROR;
+  
+  value &= 0xCF;	
+  value |= (fs<<H3LIS331DL_FS);
+  
+  if( !writeReg(H3LIS331DL_MEMS_I2C_ADDRESS, H3LIS331DL_CTRL_REG4, value) )
+    return MEMS_ERROR;
+  
+  return MEMS_SUCCESS;
+}
+
+
+/*******************************************************************************
+* Function Name  : setBDU
+* Description    : Enable/Disable Block Data Update Functionality
+* Input          : MEMS_ENABLE/MEMS_DISABLE
+* Output         : None
+* Return         : Status [MEMS_ERROR, MEMS_SUCCESS]
+*******************************************************************************/
+status_t H3LIS331DL::setBDU(State_t bdu) {
+  byte value;
+  
+  if( !readReg(H3LIS331DL_MEMS_I2C_ADDRESS, H3LIS331DL_CTRL_REG4, &value) )
+    return MEMS_ERROR;
+  
+  value &= 0x7F;
+  value |= (bdu<<H3LIS331DL_BDU);
+  
+  if( !writeReg(H3LIS331DL_MEMS_I2C_ADDRESS, H3LIS331DL_CTRL_REG4, value) )
+    return MEMS_ERROR;
+  
+  return MEMS_SUCCESS;
+}
+
+
+/*******************************************************************************
+* Function Name  : setBLE
+* Description    : Set Endianess (MSB/LSB)
+* Input          : H3LIS331DL_BLE_LSB / H3LIS331DL_BLE_MSB
+* Output         : None
+* Return         : Status [MEMS_ERROR, MEMS_SUCCESS]
+*******************************************************************************/
+status_t H3LIS331DL::setBLE(H3LIS331DL_Endianess_t ble) {
+  byte value;
+  
+  if( !readReg(H3LIS331DL_MEMS_I2C_ADDRESS, H3LIS331DL_CTRL_REG4, &value) )
+    return MEMS_ERROR;
+  
+  value &= 0xBF;	
+  value |= (ble<<H3LIS331DL_BLE);
+  
+  if( !writeReg(H3LIS331DL_MEMS_I2C_ADDRESS, H3LIS331DL_CTRL_REG4, value) )
+    return MEMS_ERROR;
+  
+  return MEMS_SUCCESS;
+}
+
+
+/*******************************************************************************
+* Function Name  : setFDS
+* Description    : Set Filter Data Selection
+* Input          : MEMS_ENABLE/MEMS_DISABLE
+* Output         : None
+* Return         : Status [MEMS_ERROR, MEMS_SUCCESS]
+*******************************************************************************/
+status_t H3LIS331DL::setFDS(State_t fds) {
+  byte value;
+  
+  if( !readReg(H3LIS331DL_MEMS_I2C_ADDRESS, H3LIS331DL_CTRL_REG2, &value) )
+    return MEMS_ERROR;
+  
+  value &= 0xEF;	
+  value |= (fds<<H3LIS331DL_FDS);
+  
+  if( !writeReg(H3LIS331DL_MEMS_I2C_ADDRESS, H3LIS331DL_CTRL_REG2, value) )
+    return MEMS_ERROR;
+  
+  return MEMS_SUCCESS;
+}
+
+
+/*******************************************************************************
+* Function Name  : setBOOT
+* Description    : Rebot memory content
+* Input          : MEMS_ENABLE/MEMS_DISABLE
+* Output         : None
+* Return         : Status [MEMS_ERROR, MEMS_SUCCESS]
+*******************************************************************************/
+status_t H3LIS331DL::setBOOT(State_t boot) {
+  byte value;
+  
+  if( !readReg(H3LIS331DL_MEMS_I2C_ADDRESS, H3LIS331DL_CTRL_REG2, &value) )
+    return MEMS_ERROR;
+  
+  value &= 0x7F;	
+  value |= (boot<<H3LIS331DL_BOOT);
+  
+  if( !writeReg(H3LIS331DL_MEMS_I2C_ADDRESS, H3LIS331DL_CTRL_REG2, value) )
+    return MEMS_ERROR;
+  
+  return MEMS_SUCCESS;
+}
+
+
+/*******************************************************************************
+* Function Name  : setSelfTest
+* Description    : Set Self Test Modality
+* Input          : MEMS_DISABLE/MEMS_ENABLE
+* Output         : None
+* Return         : Status [MEMS_ERROR, MEMS_SUCCESS]
+*******************************************************************************/
+status_t H3LIS331DL::setSelfTest(State_t st) {
+  byte value;
+  
+  if( !readReg(H3LIS331DL_MEMS_I2C_ADDRESS, H3LIS331DL_CTRL_REG4, &value) )
+    return MEMS_ERROR;
+  
+  value &= 0xFD;
+  value |= (st<<H3LIS331DL_ST);
+  
+  if( !writeReg(H3LIS331DL_MEMS_I2C_ADDRESS, H3LIS331DL_CTRL_REG4, value) )
+    return MEMS_ERROR;
+  
+  return MEMS_SUCCESS;
+}
+
+
+/*******************************************************************************
+* Function Name  : setSelfTestSign
+* Description    : Set Self Test Sign (Disable = st_plus, Enable = st_minus)
+* Input          : MEMS_DISABLE/MEMS_ENABLE
+* Output         : None
+* Return         : Status [MEMS_ERROR, MEMS_SUCCESS]
+*******************************************************************************/
+status_t H3LIS331DL::setSelfTestSign(State_t st_sign) {
+  byte value;
+  
+  if( !readReg(H3LIS331DL_MEMS_I2C_ADDRESS, H3LIS331DL_CTRL_REG4, &value) )
+    return MEMS_ERROR;
+  
+  value &= 0xF7;
+  value |= (st_sign<<H3LIS331DL_ST_SIGN);
+  
+  if( !writeReg(H3LIS331DL_MEMS_I2C_ADDRESS, H3LIS331DL_CTRL_REG4, value) )
+    return MEMS_ERROR;
+  
+  return MEMS_SUCCESS;
+}
+
+
+/*******************************************************************************
+* Function Name  : setIntHighLow
+* Description    : Set Interrupt active state (Disable = active high, Enable = active low)
+* Input          : MEMS_DISABLE/MEMS_ENABLE
+* Output         : None
+* Return         : Status [MEMS_ERROR, MEMS_SUCCESS]
+*******************************************************************************/
+status_t H3LIS331DL::setIntHighLow(State_t ihl) {
+  byte value;
+  
+  if( !readReg(H3LIS331DL_MEMS_I2C_ADDRESS, H3LIS331DL_CTRL_REG3, &value) )
+    return MEMS_ERROR;
+  
+  value &= 0x7F;
+  value |= (ihl<<H3LIS331DL_IHL);
+  
+  if( !writeReg(H3LIS331DL_MEMS_I2C_ADDRESS, H3LIS331DL_CTRL_REG3, value) )
+    return MEMS_ERROR;
+  
+  return MEMS_SUCCESS;
+}
+
+
+/*******************************************************************************
+* Function Name  : setIntPPOD
+* Description    : Set Interrupt Push-Pull/OpenDrain Pad (Disable = Push-Pull, Enable = OpenDrain)
+* Input          : MEMS_DISABLE/MEMS_ENABLE
+* Output         : None
+* Return         : Status [MEMS_ERROR, MEMS_SUCCESS]
+*******************************************************************************/
+status_t H3LIS331DL::setIntPPOD(State_t pp_od) {
+  byte value;
+  
+  if( !readReg(H3LIS331DL_MEMS_I2C_ADDRESS, H3LIS331DL_CTRL_REG3, &value) )
+    return MEMS_ERROR;
+  
+  value &= 0xBF;
+  value |= (pp_od<<H3LIS331DL_PP_OD);
+  
+  if( !writeReg(H3LIS331DL_MEMS_I2C_ADDRESS, H3LIS331DL_CTRL_REG3, value) )
+    return MEMS_ERROR;
+  
+  return MEMS_SUCCESS;
+}
+
+
+/*******************************************************************************
+* Function Name  : setInt1DataSign
+* Description    : Set Data signal Interrupt 1 pad
+* Input          : Modality by H3LIS331DL_INT_Conf_t Typedef 
+                  (H3LIS331DL_INT_SOURCE, H3LIS331DL_INT_1OR2_SOURCE, H3LIS331DL_DATA_READY, H3LIS331DL_BOOT_RUNNING)
+* Output         : None
+* Return         : Status [MEMS_ERROR, MEMS_SUCCESS]
+*******************************************************************************/
+status_t H3LIS331DL::setInt1DataSign(H3LIS331DL_INT_Conf_t i_cfg) {
+  byte value;
+  
+  if( !readReg(H3LIS331DL_MEMS_I2C_ADDRESS, H3LIS331DL_CTRL_REG3, &value) )
+    return MEMS_ERROR;
+  
+  value &= 0xFC;
+  value |= (i_cfg<<H3LIS331DL_I1_CFG);
+  
+  if( !writeReg(H3LIS331DL_MEMS_I2C_ADDRESS, H3LIS331DL_CTRL_REG3, value) )
+    return MEMS_ERROR;
+  
+  return MEMS_SUCCESS;
+}
+
+
+/*******************************************************************************
+* Function Name  : setInt2DataSign
+* Description    : Set Data signal Interrupt 2 pad
+* Input          : Modality by H3LIS331DL_INT_Conf_t Typedef 
+                  (H3LIS331DL_INT_SOURCE, H3LIS331DL_INT_1OR2_SOURCE, H3LIS331DL_DATA_READY, H3LIS331DL_BOOT_RUNNING)
+* Output         : None
+* Return         : Status [MEMS_ERROR, MEMS_SUCCESS]
+*******************************************************************************/
+status_t H3LIS331DL::setInt2DataSign(H3LIS331DL_INT_Conf_t i_cfg) {
+  byte value;
+  
+  if( !readReg(H3LIS331DL_MEMS_I2C_ADDRESS, H3LIS331DL_CTRL_REG3, &value) )
+    return MEMS_ERROR;
+  
+  value &= 0xE7;
+  value |= (i_cfg<<H3LIS331DL_I2_CFG);
+  
+  if( !writeReg(H3LIS331DL_MEMS_I2C_ADDRESS, H3LIS331DL_CTRL_REG3, value) )
+    return MEMS_ERROR;
+  
+  return MEMS_SUCCESS;
+}
+
+
+/*******************************************************************************
+* Function Name  : setSPI34Wire
+* Description    : Set SPI mode 
+* Input          : Modality by H3LIS331DL_SPIMode_t Typedef (H3LIS331DL_SPI_4_WIRE, H3LIS331DL_SPI_3_WIRE)
+* Output         : None
+* Return         : Status [MEMS_ERROR, MEMS_SUCCESS]
+*******************************************************************************/
+status_t H3LIS331DL::setSPI34Wire(H3LIS331DL_SPIMode_t sim) {
+  byte value;
+  
+  if( !readReg(H3LIS331DL_MEMS_I2C_ADDRESS, H3LIS331DL_CTRL_REG4, &value) )
+    return MEMS_ERROR;
+  
+  value &= 0xFE;
+  value |= (sim<<H3LIS331DL_SIM);
+  
+  if( !writeReg(H3LIS331DL_MEMS_I2C_ADDRESS, H3LIS331DL_CTRL_REG4, value) )
+    return MEMS_ERROR;
+  
+  return MEMS_SUCCESS;
+}
+
+
+/*******************************************************************************
+* Function Name  : turnONEnable
+* Description    : TurnON Mode selection for sleep to wake function
+* Input          : H3LIS331DL_SLEEP_TO_WAKE_DIS/H3LIS331DL_SLEEP_TO_WAKE_ENA
+* Output         : None
+* Return         : Status [MEMS_ERROR, MEMS_SUCCESS]
+*******************************************************************************/
+status_t H3LIS331DL::turnONEnable(H3LIS331DL_Sleep_To_Wake_Conf_t stw) {
+  byte value;
+  
+  if( !readReg(H3LIS331DL_MEMS_I2C_ADDRESS, H3LIS331DL_CTRL_REG5, &value) )
+    return MEMS_ERROR;
+  
+  value &= 0x00;
+  value |= (stw<<H3LIS331DL_TURN_ON);
+  
+  if( !writeReg(H3LIS331DL_MEMS_I2C_ADDRESS, H3LIS331DL_CTRL_REG5, value) )
+    return MEMS_ERROR;
+  
+  return MEMS_SUCCESS;
+}
+
+#if 0
+/*******************************************************************************
+* Function Name  : HPFilterReset
+* Description    : Reading register for reset the content of internal HP filter
+* Input          : None
+* Output         : None
+* Return         : Status [MEMS_ERROR, MEMS_SUCCESS]
+*******************************************************************************/
+status_t H3LIS331DL::HPFilterReset(void) {
+  byte value;
+  
+  if( !readReg(H3LIS331DL_MEMS_I2C_ADDRESS, H3LIS331DL_HP_FILTER_RESET, &value) )
+    return MEMS_ERROR;
+  
+  return MEMS_SUCCESS;
+}
+#endif
+
+/*******************************************************************************
+* Function Name  : setReference
+* Description    : Sets Reference register acceleration value as a reference for HP filter
+* Input          : Value of reference acceleration value (0-255)
+* Output         : None
+* Return         : Status [MEMS_ERROR, MEMS_SUCCESS]
+*******************************************************************************/
+status_t H3LIS331DL::setReference(int8_t ref) {
+  
+  if( !writeReg(H3LIS331DL_MEMS_I2C_ADDRESS, H3LIS331DL_REFERENCE_REG, ref) )
+    return MEMS_ERROR;
+  
+  return MEMS_SUCCESS;
+}
+
+
+/*******************************************************************************
+* Function Name  : setHPFMode
+* Description    : Set High Pass Filter Modality
+* Input          : H3LIS331DL_HPM_NORMAL_MODE_RES/H3LIS331DL_HPM_REF_SIGNAL/H3LIS331DL_HPM_NORMAL_MODE
+* Output         : None
+* Return         : Status [MEMS_ERROR, MEMS_SUCCESS]
+*******************************************************************************/
+status_t H3LIS331DL::setHPFMode(H3LIS331DL_HPFMode_t hpm) {
+  byte value;
+  
+  if( !readReg(H3LIS331DL_MEMS_I2C_ADDRESS, H3LIS331DL_CTRL_REG2, &value) )
+    return MEMS_ERROR;
+  
+  value &= 0x9F;
+  value |= (hpm<<H3LIS331DL_HPM);
+  
+  if( !writeReg(H3LIS331DL_MEMS_I2C_ADDRESS, H3LIS331DL_CTRL_REG2, value) )
+    return MEMS_ERROR;
+  
+  return MEMS_SUCCESS;
+}
+
+
+/*******************************************************************************
+* Function Name  : setHPFCutOFF
+* Description    : Set High Pass CUT OFF Freq
+* Input          : H3LIS331DL_HPFCF [0,3]
+* Output         : None
+* Return         : Status [MEMS_ERROR, MEMS_SUCCESS]
+*******************************************************************************/
+status_t H3LIS331DL::setHPFCutOFF(H3LIS331DL_HPFCutOffFreq_t hpf) {
+  byte value;
+  
+  if( !readReg(H3LIS331DL_MEMS_I2C_ADDRESS, H3LIS331DL_CTRL_REG2, &value) )
+    return MEMS_ERROR;
+  
+  value &= 0xFC;
+  value |= (hpf<<H3LIS331DL_HPCF);
+  
+  if( !writeReg(H3LIS331DL_MEMS_I2C_ADDRESS, H3LIS331DL_CTRL_REG2, value) )
+    return MEMS_ERROR;
+  
+  return MEMS_SUCCESS;
+  
+}
+
+
+/*******************************************************************************
+* Function Name  : setInt2HPEnable
+* Description    : Set Interrupt2 hp filter enable/disable
+* Input          : MEMS_ENABLE/MEMS_DISABLE
+* example        : H3LIS331DL_SetInt2HPEnable(MEMS_ENABLE)
+* Output         : None
+* Return         : Status [MEMS_ERROR, MEMS_SUCCESS]
+*******************************************************************************/
+status_t H3LIS331DL::setInt2HPEnable(State_t stat) {
+  byte value;
+  
+  if( !readReg(H3LIS331DL_MEMS_I2C_ADDRESS, H3LIS331DL_CTRL_REG2, &value) )
+    return MEMS_ERROR;
+  
+  value &= 0xF7;
+  value |= stat<<H3LIS331DL_HPEN2 ;
+  
+  if( !writeReg(H3LIS331DL_MEMS_I2C_ADDRESS, H3LIS331DL_CTRL_REG2, value) )
+    return MEMS_ERROR;
+  
+  return MEMS_SUCCESS;
+}     
+
+
+/*******************************************************************************
+* Function Name  : setInt1HPEnable
+* Description    : Set Interrupt1 hp filter enable/disable
+* Input          : MEMS_ENABLE/MEMS_DISABLE
+* example        : H3LIS331DL_SetInt1HPEnable(MEMS_ENABLE)
+* Output         : None
+* Return         : Status [MEMS_ERROR, MEMS_SUCCESS]
+*******************************************************************************/
+status_t H3LIS331DL::setInt1HPEnable(State_t stat) {
+  byte value;
+  
+  if( !readReg(H3LIS331DL_MEMS_I2C_ADDRESS, H3LIS331DL_CTRL_REG2, &value) )
+    return MEMS_ERROR;
+  
+  value &= 0xFB;
+  value |= stat<<H3LIS331DL_HPEN1 ;
+  
+  if( !writeReg(H3LIS331DL_MEMS_I2C_ADDRESS, H3LIS331DL_CTRL_REG2, value) )
+    return MEMS_ERROR;
+  
+  return MEMS_SUCCESS;
+}  
+
+
+/*******************************************************************************
+* Function Name  : int1LatchEnable
+* Description    : Enable Interrupt 1 Latching function
+* Input          : ENABLE/DISABLE
+* Output         : None
+* Return         : Status [MEMS_ERROR, MEMS_SUCCESS]
+*******************************************************************************/
+status_t H3LIS331DL::int1LatchEnable(State_t latch) {
+  byte value;
+  
+  if( !readReg(H3LIS331DL_MEMS_I2C_ADDRESS, H3LIS331DL_CTRL_REG3, &value) )
+    return MEMS_ERROR;
+  
+  value &= 0xFB;
+  value |= latch<<H3LIS331DL_LIR1;
+  
+  if( !writeReg(H3LIS331DL_MEMS_I2C_ADDRESS, H3LIS331DL_CTRL_REG3, value) )
+    return MEMS_ERROR;
+  
+  return MEMS_SUCCESS;
+}
+
+
+/*******************************************************************************
+* Function Name  : int2LatchEnable
+* Description    : Enable Interrupt 2 Latching function
+* Input          : ENABLE/DISABLE
+* Output         : None
+* Return         : Status [MEMS_ERROR, MEMS_SUCCESS]
+*******************************************************************************/
+status_t H3LIS331DL::int2LatchEnable(State_t latch) {
+  byte value;
+  
+  if( !readReg(H3LIS331DL_MEMS_I2C_ADDRESS, H3LIS331DL_CTRL_REG3, &value) )
+    return MEMS_ERROR;
+  
+  value &= 0xDF;
+  value |= latch<<H3LIS331DL_LIR2;
+  
+  if( !writeReg(H3LIS331DL_MEMS_I2C_ADDRESS, H3LIS331DL_CTRL_REG3, value) )
+    return MEMS_ERROR;
+  
+  return MEMS_SUCCESS;
+}
+
+
+/*******************************************************************************
+* Function Name  : resetInt1Latch
+* Description    : Reset Interrupt 1 Latching function
+* Input          : None
+* Output         : None
+* Return         : Status [MEMS_ERROR, MEMS_SUCCESS]
+*******************************************************************************/
+status_t H3LIS331DL::resetInt1Latch(void) {
+  byte value;
+  
+  if( !readReg(H3LIS331DL_MEMS_I2C_ADDRESS, H3LIS331DL_INT1_SRC, &value) )
+    return MEMS_ERROR;
+  
+  return MEMS_SUCCESS;
+}
+
+
+/*******************************************************************************
+* Function Name  : resetInt2Latch
+* Description    : Reset Interrupt 2 Latching function
+* Input          : None
+* Output         : None
+* Return         : Status [MEMS_ERROR, MEMS_SUCCESS]
+*******************************************************************************/
+status_t H3LIS331DL::resetInt2Latch(void) {
+  byte value;
+  
+  if( !readReg(H3LIS331DL_MEMS_I2C_ADDRESS, H3LIS331DL_INT2_SRC, &value) )
+    return MEMS_ERROR;
+  
+  return MEMS_SUCCESS;
+}
+
+
+/*******************************************************************************
+* Function Name  : setInt1Configuration
+* Description    : Interrupt 1 Configuration (without 6D_INT)
+* Input          : H3LIS331DL_INT_AND/OR | H3LIS331DL_INT_ZHIE_ENABLE/DISABLE | H3LIS331DL_INT_ZLIE_ENABLE/DISABLE...
+* Output         : None
+* Note           : You MUST use ALL input variable in the argument, as in example above
+* Return         : Status [MEMS_ERROR, MEMS_SUCCESS]
+*******************************************************************************/
+status_t H3LIS331DL::setInt1Configuration(H3LIS331DL_IntConf_t ic) {
+  byte value;
+  
+  if( !readReg(H3LIS331DL_MEMS_I2C_ADDRESS, H3LIS331DL_INT1_CFG, &value) )
+    return MEMS_ERROR;
+  
+  value &= 0x40; 
+  value |= ic;
+  
+  if( !writeReg(H3LIS331DL_MEMS_I2C_ADDRESS, H3LIS331DL_INT1_CFG, value) )
+    return MEMS_ERROR;
+  
+  return MEMS_SUCCESS;
+}
+
+
+/*******************************************************************************
+* Function Name  : setInt2Configuration
+* Description    : Interrupt 2 Configuration (without 6D_INT)
+* Input          : H3LIS331DL_INT_AND/OR | H3LIS331DL_INT_ZHIE_ENABLE/DISABLE | H3LIS331DL_INT_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 H3LIS331DL::setInt2Configuration(H3LIS331DL_IntConf_t ic) {
+  byte value;
+  
+  if( !readReg(H3LIS331DL_MEMS_I2C_ADDRESS, H3LIS331DL_INT2_CFG, &value) )
+    return MEMS_ERROR;
+  
+  value &= 0x40; 
+  value |= ic;
+  
+  if( !writeReg(H3LIS331DL_MEMS_I2C_ADDRESS, H3LIS331DL_INT2_CFG, value) )
+    return MEMS_ERROR;
+  
+  return MEMS_SUCCESS;
+}
+
+
+/*******************************************************************************
+* Function Name  : setInt1Mode
+* Description    : Interrupt 1 Configuration mode (OR, 6D Movement, AND, 6D Position)
+* Input          : H3LIS331DL_INT_MODE_OR, H3LIS331DL_INT_MODE_6D_MOVEMENT, H3LIS331DL_INT_MODE_AND, H3LIS331DL_INT_MODE_6D_POSITION
+* Output         : None
+* Return         : Status [MEMS_ERROR, MEMS_SUCCESS]
+*******************************************************************************/
+status_t H3LIS331DL::setInt1Mode(H3LIS331DL_IntMode_t int_mode) {
+  byte value;
+  
+  if( !readReg(H3LIS331DL_MEMS_I2C_ADDRESS, H3LIS331DL_INT1_CFG, &value) )
+    return MEMS_ERROR;
+  
+  value &= 0x3F; 
+  value |= (int_mode<<H3LIS331DL_INT_6D);
+  
+  if( !writeReg(H3LIS331DL_MEMS_I2C_ADDRESS, H3LIS331DL_INT1_CFG, value) )
+    return MEMS_ERROR;
+  
+  return MEMS_SUCCESS;
+}
+
+
+/*******************************************************************************
+* Function Name  : setInt2Mode
+* Description    : Interrupt 2 Configuration mode (OR, 6D Movement, AND, 6D Position)
+* Input          : H3LIS331DL_INT_MODE_OR, H3LIS331DL_INT_MODE_6D_MOVEMENT, H3LIS331DL_INT_MODE_AND, H3LIS331DL_INT_MODE_6D_POSITION
+* Output         : None
+* Return         : Status [MEMS_ERROR, MEMS_SUCCESS]
+*******************************************************************************/
+status_t H3LIS331DL::setInt2Mode(H3LIS331DL_IntMode_t int_mode) {
+  byte value;
+  
+  if( !readReg(H3LIS331DL_MEMS_I2C_ADDRESS, H3LIS331DL_INT2_CFG, &value) )
+    return MEMS_ERROR;
+  
+  value &= 0x3F; 
+  value |= (int_mode<<H3LIS331DL_INT_6D);
+  
+  if( !writeReg(H3LIS331DL_MEMS_I2C_ADDRESS, H3LIS331DL_INT2_CFG, value) )
+    return MEMS_ERROR;
+  
+  return MEMS_SUCCESS;
+}
+
+
+/*******************************************************************************
+* Function Name  : get6DPositionInt1
+* Description    : 6D Interrupt 1 Position Detect
+* Input          : Byte to be filled with H3LIS331DL_POSITION_6D_t Typedef
+* Output         : None
+* Return         : Status [MEMS_ERROR, MEMS_SUCCESS]
+*******************************************************************************/
+status_t H3LIS331DL::get6DPositionInt1(byte* val){
+  byte value;
+  
+  if( !readReg(H3LIS331DL_MEMS_I2C_ADDRESS, H3LIS331DL_INT1_SRC, &value) )
+    return MEMS_ERROR;
+  
+  value &= 0x7F;
+  
+  switch (value){
+  case H3LIS331DL_UP_SX:   
+    *val = H3LIS331DL_UP_SX;    
+    break;
+  case H3LIS331DL_UP_DX:   
+    *val = H3LIS331DL_UP_DX;    
+    break;
+  case H3LIS331DL_DW_SX:   
+    *val = H3LIS331DL_DW_SX;    
+    break;
+  case H3LIS331DL_DW_DX:   
+    *val = H3LIS331DL_DW_DX;    
+    break;
+  case H3LIS331DL_TOP:     
+    *val = H3LIS331DL_TOP;      
+    break;
+  case H3LIS331DL_BOTTOM:  
+    *val = H3LIS331DL_BOTTOM;  
+    break;
+  }
+  
+  return MEMS_SUCCESS;  
+}
+
+
+/*******************************************************************************
+* Function Name  : get6DPositionInt2
+* Description    : 6D Interrupt 2 Position Detect
+* Input          : Byte to be filled with H3LIS331DL_POSITION_6D_t Typedef
+* Output         : None
+* Return         : Status [MEMS_ERROR, MEMS_SUCCESS]
+*******************************************************************************/
+status_t H3LIS331DL::get6DPositionInt2(byte* val){
+  byte value;
+  
+  if( !readReg(H3LIS331DL_MEMS_I2C_ADDRESS, H3LIS331DL_INT2_SRC, &value) )
+    return MEMS_ERROR;
+  
+  value &= 0x7F;
+  
+  switch (value){
+  case H3LIS331DL_UP_SX:   
+    *val = H3LIS331DL_UP_SX;    
+    break;
+  case H3LIS331DL_UP_DX:   
+    *val = H3LIS331DL_UP_DX;    
+    break;
+  case H3LIS331DL_DW_SX:   
+    *val = H3LIS331DL_DW_SX;    
+    break;
+  case H3LIS331DL_DW_DX:   
+    *val = H3LIS331DL_DW_DX;    
+    break;
+  case H3LIS331DL_TOP:     
+    *val = H3LIS331DL_TOP;      
+    break;
+  case H3LIS331DL_BOTTOM:  
+    *val = H3LIS331DL_BOTTOM;   
+    break;
+  }
+  
+  return MEMS_SUCCESS;  
+}
+
+
+/*******************************************************************************
+* Function Name  : setInt1Threshold
+* Description    : Sets Interrupt 1 Threshold
+* Input          : Threshold = [0,127]
+* Output         : None
+* Return         : Status [MEMS_ERROR, MEMS_SUCCESS]
+*******************************************************************************/
+status_t H3LIS331DL::setInt1Threshold(byte ths) {
+  if (ths > 127)
+    return MEMS_ERROR;
+  
+  if( !writeReg(H3LIS331DL_MEMS_I2C_ADDRESS, H3LIS331DL_INT1_THS, ths) )
+    return MEMS_ERROR;    
+  
+  return MEMS_SUCCESS;
+}
+
+
+/*******************************************************************************
+* Function Name  : setInt1Duration
+* Description    : Sets Interrupt 1 Duration
+* Input          : Duration = [0,127]
+* Output         : None
+* Return         : Status [MEMS_ERROR, MEMS_SUCCESS]
+*******************************************************************************/
+status_t H3LIS331DL::setInt1Duration(byte id) {  
+  if (id > 127)
+    return MEMS_ERROR;
+  
+  if( !writeReg(H3LIS331DL_MEMS_I2C_ADDRESS, H3LIS331DL_INT1_DURATION, id) )
+    return MEMS_ERROR;
+  
+  return MEMS_SUCCESS;
+}
+
+
+/*******************************************************************************
+* Function Name  : setInt2Threshold
+* Description    : Sets Interrupt 2 Threshold
+* Input          : Threshold = [0,127]
+* Output         : None
+* Return         : Status [MEMS_ERROR, MEMS_SUCCESS]
+*******************************************************************************/
+status_t H3LIS331DL::setInt2Threshold(byte ths) {
+  if (ths > 127)
+    return MEMS_ERROR;
+  
+  if( !writeReg(H3LIS331DL_MEMS_I2C_ADDRESS, H3LIS331DL_INT2_THS, ths) )
+    return MEMS_ERROR;    
+  
+  return MEMS_SUCCESS;
+}
+
+
+/*******************************************************************************
+* Function Name  : setInt2Duration
+* Description    : Sets Interrupt 2 Duration
+* Input          : Duration = [0,127]
+* Output         : None
+* Return         : Status [MEMS_ERROR, MEMS_SUCCESS]
+*******************************************************************************/
+status_t H3LIS331DL::setInt2Duration(byte id) {  
+  if (id > 127)
+    return MEMS_ERROR;
+  
+  if( !writeReg(H3LIS331DL_MEMS_I2C_ADDRESS, H3LIS331DL_INT2_DURATION, id) )
+    return MEMS_ERROR;
+  
+  return MEMS_SUCCESS;
+}
+
+
+/*******************************************************************************
+* Function Name  : getStatusReg
+* Description    : Read the status register
+* Input          : char to empty by Status Reg Value
+* Output         : None
+* Return         : Status [MEMS_ERROR, MEMS_SUCCESS]
+*******************************************************************************/
+status_t H3LIS331DL::getStatusReg(byte* val) {
+  
+  if( !readReg(H3LIS331DL_MEMS_I2C_ADDRESS, H3LIS331DL_STATUS_REG, val) )
+    return MEMS_ERROR;
+  
+  return MEMS_SUCCESS;  
+}
+
+/*******************************************************************************
+* Function Name  : getStatusBIT
+* Description    : Read the status register BIT
+* Input          : H3LIS331DL_STATUS_REG_ZYXOR, H3LIS331DL_STATUS_REG_ZOR, H3LIS331DL_STATUS_REG_YOR, H3LIS331DL_STATUS_REG_XOR,
+                   H3LIS331DL_STATUS_REG_ZYXDA, H3LIS331DL_STATUS_REG_ZDA, H3LIS331DL_STATUS_REG_YDA, H3LIS331DL_STATUS_REG_XDA, 
+                   H3LIS331DL_DATAREADY_BIT
+* Output         : status register BIT
+* Return         : Status [MEMS_ERROR, MEMS_SUCCESS]
+*******************************************************************************/
+status_t H3LIS331DL::getStatusBit(byte statusBIT, byte *val) {
+  byte value;  
+  
+  if( !readReg(H3LIS331DL_MEMS_I2C_ADDRESS, H3LIS331DL_STATUS_REG, &value) )
+    return MEMS_ERROR;
+  
+  switch (statusBIT){
+  case H3LIS331DL_STATUS_REG_ZYXOR:     
+    if(value &= H3LIS331DL_STATUS_REG_ZYXOR){     
+      *val = MEMS_SET;
+      return MEMS_SUCCESS;
+    }
+    else{  
+      *val = MEMS_RESET;
+      return MEMS_SUCCESS;
+    }  
+  case H3LIS331DL_STATUS_REG_ZOR:       
+    if(value &= H3LIS331DL_STATUS_REG_ZOR){     
+      *val = MEMS_SET;
+      return MEMS_SUCCESS;
+    }
+    else{  
+      *val = MEMS_RESET;
+      return MEMS_SUCCESS;
+    }  
+  case H3LIS331DL_STATUS_REG_YOR:       
+    if(value &= H3LIS331DL_STATUS_REG_YOR){     
+      *val = MEMS_SET;
+      return MEMS_SUCCESS;
+    }
+    else{  
+      *val = MEMS_RESET;
+      return MEMS_SUCCESS;
+    }                                 
+  case H3LIS331DL_STATUS_REG_XOR:       
+    if(value &= H3LIS331DL_STATUS_REG_XOR){     
+      *val = MEMS_SET;
+      return MEMS_SUCCESS;
+    }
+    else{  
+      *val = MEMS_RESET;
+      return MEMS_SUCCESS;
+    }  
+  case H3LIS331DL_STATUS_REG_ZYXDA:     
+    if(value &= H3LIS331DL_STATUS_REG_ZYXDA){     
+      *val = MEMS_SET;
+      return MEMS_SUCCESS;
+    }
+    else{  
+      *val = MEMS_RESET;
+      return MEMS_SUCCESS;
+    }   
+  case H3LIS331DL_STATUS_REG_ZDA:       
+    if(value &= H3LIS331DL_STATUS_REG_ZDA){     
+      *val = MEMS_SET;
+      return MEMS_SUCCESS;
+    }
+    else{  
+      *val = MEMS_RESET;
+      return MEMS_SUCCESS;
+    }   
+  case H3LIS331DL_STATUS_REG_YDA:       
+    if(value &= H3LIS331DL_STATUS_REG_YDA){     
+      *val = MEMS_SET;
+      return MEMS_SUCCESS;
+    }
+    else{  
+      *val = MEMS_RESET;
+      return MEMS_SUCCESS;
+    }   
+  case H3LIS331DL_STATUS_REG_XDA:       
+    if(value &= H3LIS331DL_STATUS_REG_XDA){     
+      *val = MEMS_SET;
+      return MEMS_SUCCESS;
+    }
+    else{  
+      *val = MEMS_RESET;
+      return MEMS_SUCCESS;
+    }                                      
+  }
+  
+  return MEMS_ERROR;
+}
+
+
+/*******************************************************************************
+* Function Name  : getAccAxesRaw
+* Description    : Read the Acceleration Values Output Registers
+* Input          : buffer to empty by AccAxesRaw_t Typedef
+* Output         : None
+* Return         : Status [MEMS_ERROR, MEMS_SUCCESS]
+*******************************************************************************/
+status_t H3LIS331DL::getAccAxesRaw(AxesRaw_t* buff) {
+	byte valueL = 0,valueH = 0;
+	readReg(H3LIS331DL_MEMS_I2C_ADDRESS, H3LIS331DL_OUT_X_L, &valueL);
+	readReg(H3LIS331DL_MEMS_I2C_ADDRESS, H3LIS331DL_OUT_X_H, &valueH);
+	buff->AXIS_X = (valueH<<8)|valueL;
+	readReg(H3LIS331DL_MEMS_I2C_ADDRESS, H3LIS331DL_OUT_Y_L, &valueL);
+	readReg(H3LIS331DL_MEMS_I2C_ADDRESS, H3LIS331DL_OUT_Y_H, &valueH);
+	buff->AXIS_Y = (valueH<<8)|valueL;
+	readReg(H3LIS331DL_MEMS_I2C_ADDRESS, H3LIS331DL_OUT_Z_L, &valueL);
+	readReg(H3LIS331DL_MEMS_I2C_ADDRESS, H3LIS331DL_OUT_Z_H, &valueH);
+	buff->AXIS_Z = (valueH<<8)|valueL;
+	return MEMS_SUCCESS;  
+}
+
+
+/*******************************************************************************
+* Function Name  : getInt1Src
+* Description    : Reset Interrupt 1 Latching function
+* Input          : buffer to empty by Int1 Source Value
+* Output         : None
+* Return         : Status [MEMS_ERROR, MEMS_SUCCESS]
+*******************************************************************************/
+status_t H3LIS331DL::getInt1Src(byte* val) {  
+  if( !readReg(H3LIS331DL_MEMS_I2C_ADDRESS, H3LIS331DL_INT1_SRC, val) )
+    return MEMS_ERROR;
+  
+  return MEMS_SUCCESS;
+}
+
+
+/*******************************************************************************
+* Function Name  : getInt2Src
+* Description    : Reset Interrupt 2 Latching function
+* Input          : buffer to empty by Int2 Source Value
+* Output         : None
+* Return         : Status [MEMS_ERROR, MEMS_SUCCESS]
+*******************************************************************************/
+status_t H3LIS331DL::getInt2Src(byte* val) {  
+  if( !readReg(H3LIS331DL_MEMS_I2C_ADDRESS, H3LIS331DL_INT2_SRC, val) )
+    return MEMS_ERROR;
+  
+  return MEMS_SUCCESS;
+}
+
+
+/*******************************************************************************
+* Function Name  : getInt1SrcBit
+* Description    : Reset Interrupt 1 Latching function
+* Input          : H3LIS331DL_INT1_SRC_IA, H3LIS331DL_INT1_SRC_ZH, H3LIS331DL_INT1_SRC_ZL .....
+* Output         : None
+* Return         : Status of BIT [MEMS_ERROR, MEMS_SUCCESS]
+*******************************************************************************/
+status_t H3LIS331DL::getInt1SrcBit(byte statusBIT, byte *val) {
+  byte value;  
+  
+  if( !readReg(H3LIS331DL_MEMS_I2C_ADDRESS, H3LIS331DL_INT1_SRC, &value) )
+    return MEMS_ERROR;
+  
+  if(statusBIT == H3LIS331DL_INT_SRC_IA){
+    if(value &= H3LIS331DL_INT_SRC_IA){     
+      *val = MEMS_SET;
+      return MEMS_SUCCESS;
+    }
+    else{  
+      *val = MEMS_RESET;
+      return MEMS_SUCCESS;
+    }    
+  }
+  
+  if(statusBIT == H3LIS331DL_INT_SRC_ZH){
+    if(value &= H3LIS331DL_INT_SRC_ZH){     
+      *val = MEMS_SET;
+      return MEMS_SUCCESS;
+    }
+    else{  
+      *val = MEMS_RESET;
+      return MEMS_SUCCESS;
+    }   
+  }
+  
+  if(statusBIT == H3LIS331DL_INT_SRC_ZL){
+    if(value &= H3LIS331DL_INT_SRC_ZL){     
+      *val = MEMS_SET;
+      return MEMS_SUCCESS;
+    }
+    else{  
+      *val = MEMS_RESET;
+      return MEMS_SUCCESS;
+    }   
+  }
+  
+  if(statusBIT == H3LIS331DL_INT_SRC_YH){
+    if(value &= H3LIS331DL_INT_SRC_YH){     
+      *val = MEMS_SET;
+      return MEMS_SUCCESS;
+    }
+    else{  
+      *val = MEMS_RESET;
+      return MEMS_SUCCESS;
+    }   
+  }
+  
+  if(statusBIT == H3LIS331DL_INT_SRC_YL){
+    if(value &= H3LIS331DL_INT_SRC_YL){     
+      *val = MEMS_SET;
+      return MEMS_SUCCESS;
+    }
+    else{  
+      *val = MEMS_RESET;
+      return MEMS_SUCCESS;
+    }  
+  }
+  
+  if(statusBIT == H3LIS331DL_INT_SRC_XH){
+    if(value &= H3LIS331DL_INT_SRC_XH){     
+      *val = MEMS_SET;
+      return MEMS_SUCCESS;
+    }
+    else{  
+      *val = MEMS_RESET;
+      return MEMS_SUCCESS;
+    }   
+  }
+  
+  if(statusBIT == H3LIS331DL_INT_SRC_XL){
+    if(value &= H3LIS331DL_INT_SRC_XL){     
+      *val = MEMS_SET;
+      return MEMS_SUCCESS;
+    }
+    else{  
+      *val = MEMS_RESET;
+      return MEMS_SUCCESS;
+    }    
+  } 
+  return MEMS_ERROR;
+}
+
+
+/*******************************************************************************
+* Function Name  : getInt2SrcBit
+* Description    : Reset Interrupt 2 Latching function
+* Input          : H3LIS331DL_INT_SRC_IA, H3LIS331DL_INT_SRC_ZH, H3LIS331DL_INT_SRC_ZL .....
+* Output         : None
+* Return         : Status of BIT [MEMS_ERROR, MEMS_SUCCESS]
+*******************************************************************************/
+status_t H3LIS331DL::getInt2SrcBit(byte statusBIT, byte *val) {
+  byte value;  
+  
+  if( !readReg(H3LIS331DL_MEMS_I2C_ADDRESS, H3LIS331DL_INT2_SRC, &value) )
+    return MEMS_ERROR;
+  
+  if(statusBIT == H3LIS331DL_INT_SRC_IA){
+    if(value &= H3LIS331DL_INT_SRC_IA){     
+      *val = MEMS_SET;
+      return MEMS_SUCCESS;
+    }
+    else{  
+      *val = MEMS_RESET;
+      return MEMS_SUCCESS;
+    }   
+  }
+  
+  if(statusBIT == H3LIS331DL_INT_SRC_ZH){
+    if(value &= H3LIS331DL_INT_SRC_ZH){     
+      *val = MEMS_SET;
+      return MEMS_SUCCESS;
+    }
+    else{  
+      *val = MEMS_RESET;
+      return MEMS_SUCCESS;
+    }  
+  }
+  
+  if(statusBIT == H3LIS331DL_INT_SRC_ZL){
+    if(value &= H3LIS331DL_INT_SRC_ZL){     
+      *val = MEMS_SET;
+      return MEMS_SUCCESS;
+    }
+    else{  
+      *val = MEMS_RESET;
+      return MEMS_SUCCESS;
+    }  
+  }
+  
+  if(statusBIT == H3LIS331DL_INT_SRC_YH){
+    if(value &= H3LIS331DL_INT_SRC_YH){     
+      *val = MEMS_SET;
+      return MEMS_SUCCESS;
+    }
+    else{  
+      *val = MEMS_RESET;
+      return MEMS_SUCCESS;
+    }    
+  }
+  
+  if(statusBIT == H3LIS331DL_INT_SRC_YL){
+    if(value &= H3LIS331DL_INT_SRC_YL){     
+      *val = MEMS_SET;
+      return MEMS_SUCCESS;
+    }
+    else{  
+      *val = MEMS_RESET;
+      return MEMS_SUCCESS;
+    }   
+  }
+  
+  if(statusBIT == H3LIS331DL_INT_SRC_XH){
+    if(value &= H3LIS331DL_INT_SRC_XH){     
+      *val = MEMS_SET;
+      return MEMS_SUCCESS;
+    }
+    else{  
+      *val = MEMS_RESET;
+      return MEMS_SUCCESS;
+    }  
+  }
+  
+  if(statusBIT == H3LIS331DL_INT_SRC_XL){
+    if(value &= H3LIS331DL_INT_SRC_XL){     
+      *val = MEMS_SET;
+      return MEMS_SUCCESS;
+    }
+    else{  
+      *val = MEMS_RESET;
+      return MEMS_SUCCESS;
+    }    
+  } 
+  return MEMS_ERROR;
+}
+
+/*******************************************************************************
+* Function Name		: readReg
+* Description		: Generic Reading function. It must be full filled with either
+*			        : I2C or SPI reading functions					
+* Input			    : Register Address
+* Output		    : Data Read
+* Return		    : Status [MEMS_ERROR, MEMS_SUCCESS]
+*******************************************************************************/
+uint8_t H3LIS331DL::readReg(byte deviceAddr, byte Reg, byte* Data) {
+  
+  //To be completed with either I2c or SPI reading function
+  // i.e. *Data = SPI_Mems_Read_Reg( Reg );
+  // i.e. if(!I2C_BufferRead(Data, deviceAddr, Reg, 1)) 
+  // return MEMS_ERROR;
+  // else  
+  // return MEMS_SUCCESS;
+// Reads num bytes starting from address register on device in to _buff array
+    byte num = 1;
+	Wire.beginTransmission(deviceAddr); // start transmission to device 
+	Wire.write(Reg);             // sends address to read from
+	Wire.endTransmission();         // end transmission
+	
+	Wire.beginTransmission(deviceAddr); // start transmission to device
+	Wire.requestFrom(deviceAddr,num);    // request 6 bytes from device
+	
+	if(Wire.available()){
+		*Data = Wire.read();    // receive a byte
+		Wire.endTransmission(); // end transmission
+		return MEMS_SUCCESS;		
+	}else{
+		Wire.endTransmission();
+		return MEMS_ERROR;
+	}
+}
+
+/*******************************************************************************
+* Function Name		: writeReg
+* Description		: Generic Writing function. It must be full filled with either
+*			        : I2C or SPI writing function
+* Input			    : Register Address, Data to be written
+* Output		    : None
+* Return		    : Status [MEMS_ERROR, MEMS_SUCCESS]
+*******************************************************************************/
+uint8_t H3LIS331DL::writeReg(byte deviceAddress, byte WriteAddr, byte Data) {
+  
+  //To be completed with either I2c or SPI writing function
+  // i.e. SPI_Mems_Write_Reg(Reg, Data);
+  // i.e. I2C_ByteWrite(&Data,  deviceAddress,  WriteAddr);  
+  //  return MEMS_SUCCESS;
+  // Writes val to address register on device
+	Wire.beginTransmission(deviceAddress); // start transmission to device 
+	Wire.write(WriteAddr);             // send register address
+	Wire.write(Data);                 // send value to write
+	Wire.endTransmission();         // end transmission  
+    return MEMS_SUCCESS;
+}

+ 315 - 0
H3LIS331DL.h

@@ -0,0 +1,315 @@
+#include "arduino.h"
+
+#ifndef H3LIS331DL_H
+#define H3LIS331DL_H
+
+#define MEMS_SET                        0x01
+#define MEMS_RESET                      0x00
+
+#define H3LIS331DL_MEMS_I2C_ADDRESS     0x18//0x32
+
+//Register and define
+#define H3LIS331DL_WHO_AM_I				0x0F   // device identification register
+
+// CONTROL REGISTER 1 
+#define H3LIS331DL_CTRL_REG1       	    0x20
+#define H3LIS331DL_PM				    BIT(5) //PowerMode selection: 000 - power down / 001 - normal mode / other - low power
+#define H3LIS331DL_DR				    BIT(3) //output data rate: 00 - 50hz / 01 - 100hz / 10 - 400hz / 11 - 1000hz
+#define H3LIS331DL_ZEN					BIT(2) //Z-axis enable: 0 - disable / 1 - enable
+#define H3LIS331DL_YEN					BIT(1) //Y-axis enable: 0 - disable / 1 - enable
+#define H3LIS331DL_XEN					BIT(0) //Y-axis enable: 0 - disable / 1 - enable
+
+//CONTROL REGISTER 2 
+#define H3LIS331DL_CTRL_REG2			0x21
+#define H3LIS331DL_BOOT                 BIT(7) //reboot memory content, default is 0
+#define H3LIS331DL_HPM     				BIT(5) //High-pass-filter mode selection, default is 00
+#define H3LIS331DL_FDS     				BIT(4) //Filter data selection, default is 0
+#define H3LIS331DL_HPEN2				BIT(3) //High-pass filter enabled for interrupt 2 source, default is 0
+#define H3LIS331DL_HPEN1				BIT(2) //High-pass filter enabled for interrupt 1 source, default is 0
+#define H3LIS331DL_HPCF					BIT(0) //High-pass filter cutoff frequency configuration, default is 00
+
+//CONTROL REGISTER 3 
+#define H3LIS331DL_CTRL_REG3			0x22
+#define H3LIS331DL_IHL                  BIT(7) //Interrupt active high,low. default is 0
+#define H3LIS331DL_PP_OD				BIT(6) //Push-pull/open drain selection on interrupt pad. default is 0
+#define H3LIS331DL_LIR2				    BIT(5) //Latch interrupt request on INT2_SRC register, with INT2_SRC register cleared by read INT2_SRC itself. default is 0
+#define H3LIS331DL_I2_CFG  				BIT(3) //Data signal on INT2 pad control bits, default is 00
+#define H3LIS331DL_LIR1    				BIT(2) //Latch interrupt request on the INT1_SRC register, with the INT1_SRC register cleared by reading the INT1_SRC register.
+#define H3LIS331DL_I1_CFG  				BIT(0) //Data signal on INT1 pad control bits, default is 00
+
+//CONTROL REGISTER 4
+#define H3LIS331DL_CTRL_REG4			0x23
+#define H3LIS331DL_BDU					BIT(7) //Block data update, default is 0
+#define H3LIS331DL_BLE					BIT(6) //Big/little endian data selection, default is 0
+#define H3LIS331DL_FS					BIT(4) //Full scale selection, default is 00(00:100g;01:200g;11:400g)
+#define H3LIS331DL_ST_SIGN				BIT(3) //
+#define H3LIS331DL_ST       			BIT(1) //
+#define H3LIS331DL_SIM					BIT(0) // SPI serial interface mode selection, default is 0
+
+//CONTROL REGISTER 5
+#define H3LIS331DL_CTRL_REG5       		0x24 
+#define H3LIS331DL_TURN_ON              BIT(0) // Turn-on mode selection selection for sleep to wake function. default is 00
+
+#define H3LIS331DL_HP_FILTER_RESET		0x25   // 
+
+//REFERENCE/DATA_CAPTURE
+#define H3LIS331DL_REFERENCE_REG	    0x26   //
+#define H3LIS331DL_REF		            BIT(0) //
+
+//STATUS_REG_AXIES 
+#define H3LIS331DL_STATUS_REG		    0x27   //
+
+//OUTPUT REGISTER
+#define H3LIS331DL_OUT_X_L              0x28   //x-axis acceleration data
+#define H3LIS331DL_OUT_X_H              0x29   
+#define H3LIS331DL_OUT_Y_L			    0x2A   //y-axis acceleration data
+#define H3LIS331DL_OUT_Y_H		        0x2B
+#define H3LIS331DL_OUT_Z_L			    0x2C   //z-axis acceleration data
+#define H3LIS331DL_OUT_Z_H		        0x2D
+
+
+//INTERRUPT 1 CONFIGURATION 
+#define H3LIS331DL_INT1_CFG				0x30
+
+//INTERRUPT 2 CONFIGURATION 
+#define H3LIS331DL_INT2_CFG				0x34
+#define H3LIS331DL_ANDOR                BIT(7)
+#define H3LIS331DL_INT_6D               BIT(6)
+
+//INT REGISTERS 
+#define H3LIS331DL_INT1_THS             0x32
+#define H3LIS331DL_INT1_DURATION        0x33
+#define H3LIS331DL_INT2_THS             0x36
+#define H3LIS331DL_INT2_DURATION        0x37
+
+//INTERRUPT 1 SOURCE REGISTER 
+#define H3LIS331DL_INT1_SRC             0x31
+#define H3LIS331DL_INT2_SRC			    0x35
+
+//INT_CFG  bit mask
+#define H3LIS331DL_INT_AND              0x80
+#define H3LIS331DL_INT_OR               0x00
+#define H3LIS331DL_INT_ZHIE_ENABLE      0x20
+#define H3LIS331DL_INT_ZHIE_DISABLE     0x00
+#define H3LIS331DL_INT_ZLIE_ENABLE      0x10
+#define H3LIS331DL_INT_ZLIE_DISABLE     0x00
+#define H3LIS331DL_INT_YHIE_ENABLE      0x08
+#define H3LIS331DL_INT_YHIE_DISABLE     0x00
+#define H3LIS331DL_INT_YLIE_ENABLE      0x04
+#define H3LIS331DL_INT_YLIE_DISABLE     0x00
+#define H3LIS331DL_INT_XHIE_ENABLE      0x02
+#define H3LIS331DL_INT_XHIE_DISABLE     0x00
+#define H3LIS331DL_INT_XLIE_ENABLE      0x01
+#define H3LIS331DL_INT_XLIE_DISABLE     0x00
+
+//INT_SRC  bit mask
+#define H3LIS331DL_INT_SRC_IA           0x40
+#define H3LIS331DL_INT_SRC_ZH           0x20
+#define H3LIS331DL_INT_SRC_ZL           0x10
+#define H3LIS331DL_INT_SRC_YH           0x08
+#define H3LIS331DL_INT_SRC_YL           0x04
+#define H3LIS331DL_INT_SRC_XH           0x02
+#define H3LIS331DL_INT_SRC_XL           0x01
+
+//STATUS REGISTER bit mask
+#define H3LIS331DL_STATUS_REG_ZYXOR     0x80    // 1:new data set has over written the previous one
+                                                // 0:no overrun has occurred (default)	
+#define H3LIS331DL_STATUS_REG_ZOR       0x40    // 0:no overrun has occurred (default)
+                                                // 1:new Z-axis data has over written the previous one
+#define H3LIS331DL_STATUS_REG_YOR       0x20    // 0:no overrun has occurred (default)
+                                                // 1:new Y-axis data has over written the previous one
+#define H3LIS331DL_STATUS_REG_XOR       0x10    // 0:no overrun has occurred (default)
+                                                // 1:new X-axis data has over written the previous one
+#define H3LIS331DL_STATUS_REG_ZYXDA     0x08    // 0:a new set of data is not yet avvious one
+                                                // 1:a new set of data is available 
+#define H3LIS331DL_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 H3LIS331DL_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 H3LIS331DL_STATUS_REG_XDA       0x01    // 0:a new data for the X-Axis is not available
+                                                // 1:a new data for the X-Axis is available
+#define H3LIS331DL_DATAREADY_BIT        H3LIS331DL_STATUS_REG_ZYXDA
+
+#define ValBit(VAR,Place)         (VAR & (1<<Place))
+#define BIT(x) ( (x) )
+
+typedef uint8_t H3LIS331DL_Axis_t;
+typedef uint8_t H3LIS331DL_IntConf_t;
+
+//define structure
+typedef enum {
+    MEMS_SUCCESS  = 0x01,
+    MEMS_ERROR	= 0x00	
+} status_t;
+
+typedef enum {
+    MEMS_ENABLE   = 0x01,
+    MEMS_DISABLE	= 0x00	
+} State_t;
+
+typedef struct {
+    int16_t AXIS_X;
+    int16_t AXIS_Y;
+    int16_t AXIS_Z;
+} AxesRaw_t;
+
+typedef enum {  
+    H3LIS331DL_ODR_50Hz    = 0x00,
+    H3LIS331DL_ODR_100Hz   = 0x01,	
+    H3LIS331DL_ODR_400Hz   = 0x02,
+    H3LIS331DL_ODR_1000Hz  = 0x03
+} H3LIS331DL_ODR_t;
+
+typedef enum {
+    H3LIS331DL_CONTINUOUS_MODE = 0x00,
+    H3LIS331DL_SINGLE_MODE     = 0x01,
+    H3LIS331DL_SLEEP_MODE      = 0x02
+} H3LIS331DL_Mode_M_t;
+
+typedef enum {
+    H3LIS331DL_POWER_DOWN   = 0x00,
+    H3LIS331DL_NORMAL       = 0x01,
+    H3LIS331DL_LOW_POWER_05 = 0x02,
+    H3LIS331DL_LOW_POWER_1  = 0x03,
+    H3LIS331DL_LOW_POWER_2	= 0x04,
+    H3LIS331DL_LOW_POWER_5	= 0x05,
+    H3LIS331DL_LOW_POWER_10 = 0x06,
+} H3LIS331DL_Mode_t;
+
+typedef enum {
+    H3LIS331DL_HPM_NORMAL_MODE_RES = 0x00,
+    H3LIS331DL_HPM_REF_SIGNAL      = 0x01,
+    H3LIS331DL_HPM_NORMAL_MODE     = 0x02,
+} H3LIS331DL_HPFMode_t;
+
+typedef enum {
+    H3LIS331DL_HPFCF_0 = 0x00,
+    H3LIS331DL_HPFCF_1 = 0x01,
+    H3LIS331DL_HPFCF_2 = 0x02,
+    H3LIS331DL_HPFCF_3 = 0x03,
+} H3LIS331DL_HPFCutOffFreq_t;
+
+typedef enum {
+    H3LIS331DL_INT_SOURCE      = 0x00,
+    H3LIS331DL_INT_1OR2_SOURCE = 0x01,
+    H3LIS331DL_DATA_READY      = 0x02,
+    H3LIS331DL_BOOT_RUNNING    = 0x03
+} H3LIS331DL_INT_Conf_t;
+
+typedef enum {
+    H3LIS331DL_SLEEP_TO_WAKE_DIS    = 0x00,
+    H3LIS331DL_SLEEP_TO_WAKE_ENA    = 0x03,
+} H3LIS331DL_Sleep_To_Wake_Conf_t;
+
+typedef enum {
+    H3LIS331DL_FULLSCALE_2    = 0x00,
+    H3LIS331DL_FULLSCALE_4    = 0x01,
+    H3LIS331DL_FULLSCALE_8    = 0x03,
+} H3LIS331DL_Fullscale_t;
+
+typedef enum {
+    H3LIS331DL_BLE_LSB        = 0x00,
+    H3LIS331DL_BLE_MSB        = 0x01
+} H3LIS331DL_Endianess_t;
+
+typedef enum {
+    H3LIS331DL_SPI_4_WIRE = 0x00,
+    H3LIS331DL_SPI_3_WIRE = 0x01
+} H3LIS331DL_SPIMode_t;
+
+typedef enum {
+    H3LIS331DL_X_ENABLE     = 0x01,
+    H3LIS331DL_X_DISABLE    = 0x00,
+    H3LIS331DL_Y_ENABLE     = 0x02,
+    H3LIS331DL_Y_DISABLE    = 0x00,
+    H3LIS331DL_Z_ENABLE     = 0x04,
+    H3LIS331DL_Z_DISABLE    = 0x00    
+} H3LIS331DL_AXISenable_t;
+
+typedef enum {
+    H3LIS331DL_UP_SX  = 0x44,
+    H3LIS331DL_UP_DX  = 0x42,
+    H3LIS331DL_DW_SX  = 0x41,
+    H3LIS331DL_DW_DX  = 0x48,
+    H3LIS331DL_TOP    = 0x60,
+    H3LIS331DL_BOTTOM = 0x50
+} H3LIS331DL_POSITION_6D_t;
+
+typedef enum {
+    H3LIS331DL_INT_MODE_OR            = 0x00,
+    H3LIS331DL_INT_MODE_6D_MOVEMENT   = 0x01,
+    H3LIS331DL_INT_MODE_AND           = 0x02,
+    H3LIS331DL_INT_MODE_6D_POSITION   = 0x03  
+} H3LIS331DL_IntMode_t;
+
+
+class H3LIS331DL
+{
+public:
+	H3LIS331DL(){
+		_adjVal[0] = _adjVal[1] = _adjVal[2] = 0; 
+	};
+    void init(H3LIS331DL_ODR_t  odr = H3LIS331DL_ODR_100Hz, 
+			H3LIS331DL_Mode_t mode = H3LIS331DL_NORMAL,H3LIS331DL_Fullscale_t fullScale = H3LIS331DL_FULLSCALE_2);
+	void importPara(int16_t val_x, int16_t val_y, int16_t val_z);
+    void readXYZ(int16_t* x, int16_t* y, int16_t* z);
+	void getAcceleration(double* xyz);
+    //Sensor Configuration Functions
+    status_t getWHO_AM_I(byte* val);
+    status_t setODR(H3LIS331DL_ODR_t dr);
+    status_t setMode(H3LIS331DL_Mode_t pm);
+    status_t setAxis(H3LIS331DL_Axis_t axis);
+    status_t setFullScale(H3LIS331DL_Fullscale_t fs);
+    status_t setBDU(State_t bdu);
+    status_t setBLE(H3LIS331DL_Endianess_t ble);
+    status_t setSelfTest(State_t st);
+    status_t setSelfTestSign(State_t st_sign);
+    status_t turnONEnable(H3LIS331DL_Sleep_To_Wake_Conf_t stw);
+    status_t setBOOT(State_t boot);
+    status_t setFDS(State_t fds);
+    status_t setSPI34Wire(H3LIS331DL_SPIMode_t sim);
+
+    //Filtering Functions
+    status_t setHPFMode(H3LIS331DL_HPFMode_t hpm);
+    status_t setHPFCutOFF(H3LIS331DL_HPFCutOffFreq_t hpf);
+    status_t setFilterDataSel(State_t state);
+    status_t setReference(int8_t ref);
+
+    //Interrupt Functions
+    status_t setIntHighLow(State_t hil);
+    status_t setIntPPOD(State_t pp_od);
+    status_t setInt1DataSign(H3LIS331DL_INT_Conf_t i_cfg);
+    status_t setInt2DataSign(H3LIS331DL_INT_Conf_t i_cfg);
+    status_t setInt1HPEnable(State_t stat);
+    status_t setInt2HPEnable(State_t stat);
+    status_t int1LatchEnable(State_t latch);
+    status_t int2LatchEnable(State_t latch);
+    status_t resetInt1Latch(void);
+    status_t resetInt2Latch(void);
+    status_t setInt1Configuration(H3LIS331DL_IntConf_t ic);
+    status_t setInt2Configuration(H3LIS331DL_IntConf_t ic);
+    status_t setInt1Threshold(byte ths);
+    status_t setInt2Threshold(byte ths);
+    status_t setInt1Duration(byte id);
+    status_t setInt2Duration(byte id);
+    status_t setInt1Mode(H3LIS331DL_IntMode_t int_mode);
+    status_t setInt2Mode(H3LIS331DL_IntMode_t int_mode);
+    status_t getInt1Src(byte* val);
+    status_t getInt2Src(byte* val);
+    status_t getInt1SrcBit(byte statusBIT, byte* val);
+    status_t getInt2SrcBit(byte statusBIT, byte* val); 
+
+    //Other Reading Functions
+    status_t getStatusReg(byte* val);
+    status_t getStatusBit(byte statusBIT, byte* val);
+    status_t getAccAxesRaw(AxesRaw_t* buff);
+    status_t get6DPositionInt1(byte* val);
+    status_t get6DPositionInt2(byte* val);
+    
+private:
+    uint8_t readReg(byte deviceAddr, byte Reg, byte* Data);
+    uint8_t writeReg(byte deviceAddress, byte WriteAddr, byte Data);
+	int16_t _adjVal[3];
+};
+
+#endif /*__H3LIS331DL_H */

+ 21 - 0
License.txt

@@ -0,0 +1,21 @@
+The MIT License (MIT)
+
+Copyright (c) 2013 Seeed Technology Inc.
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.

+ 36 - 0
README.md

@@ -0,0 +1,36 @@
+## Grove - 3-Axis Digital Accelerometer(±400g)
+
+This is an Arduino library to use H3LIS331DL as a 3-Axis Digital Accelerometer
+
+### Features
++ Ultra low power mode consumption down to 10 µA
++ ±100g/±200g/±400gdynamically selectable full scale
++ 16-bit data output
++ 10000g high shock survivability
+
+
+### Applications
++ Shock detection
++ Impact recognition and logging
++ Concussion detection 
+
+### Getting Started
+please follow the example sketch.(**H3LIS331DL_AdjVal** and **H3LIS331DL_Demo**) Have fun!
+
+
+----
+
+This software is written by lawliet ([wei.zou@seeedstudio.com](wei.zou@seeedstudio.com "wei.zou@seeedstudio.com")) for seeed studio<br>
+and is licensed under [The MIT License](http://opensource.org/licenses/mit-license.php). Check License.txt for more information.<br>
+
+Contributing to this software is warmly welcomed. You can do this basically by<br>
+[forking](https://help.github.com/articles/fork-a-repo), committing modifications and then [pulling requests](https://help.github.com/articles/using-pull-requests) (follow the links above<br>
+for operating guide). Adding change log and your contact into file header is encouraged.<br>
+Thanks for your contribution.
+
+Seeed Studio is an open hardware facilitation company based in Shenzhen, China. <br>
+Benefiting from local manufacture power and convenient global logistic system, <br>
+we integrate resources to serve new era of innovation. Seeed also works with <br>
+global distributors and partners to push open hardware movement.<br>
+
+[![Analytics](https://ga-beacon.appspot.com/UA-46589105-3/NFC_Tag_M24LR6E)](https://github.com/igrigorik/ga-beacon)

+ 69 - 0
examples/H3LIS331DL_AdjVal/H3LIS331DL_AdjVal.ino

@@ -0,0 +1,69 @@
+/* this sketch is used for adjusting raw data of H3LIS331DL to make it more precise
+ * auth : lawliet(lawliet.zou@gmail.com)
+ * version : 0.1
+ */
+
+#include <H3LIS331DL.h>
+#include <Wire.h>
+
+H3LIS331DL h3lis;
+
+char* tag[] = {"Z+","Z-","Y+","Y-","X+","X-"};
+int16_t dataBuf[6][3] = {0};
+
+void setup(){
+  Serial.begin(9600);
+  h3lis.init();
+  getAdjParameter();
+}
+
+void loop(){
+  //nothing to do
+}
+
+void getAdjParameter()
+{
+    AxesRaw_t data;
+    int32_t sum[3] = {0};
+  	
+    Serial.println("Start ...");
+    delay(3000);
+    for(int timer = 0; timer < 6; timer++){
+      Serial.print("please turn ");
+      Serial.print(tag[timer]);
+      Serial.println(" up");
+      delay(3000);
+      for(int i = 0; i < 5; i++){
+        Serial.print("start will be in ");
+        Serial.print(5-i);
+        Serial.println(" seconds");
+        delay(1000);
+      }
+      Serial.println("calculating ... ");
+      for(int i = 0 ; i < 100; i++){
+        status_t response = h3lis.getAccAxesRaw(&data);
+        if(MEMS_SUCCESS == response){
+          sum[0] += data.AXIS_X;
+    	  sum[1] += data.AXIS_Y;
+    	  sum[2] += data.AXIS_Z;
+        }
+        delay(20);
+     }
+     dataBuf[timer][0] = sum[0]/100;
+     dataBuf[timer][1] = sum[1]/100;
+     dataBuf[timer][2] = sum[2]/100;
+     sum[0] = sum[1] = sum[2] = 0;
+     Serial.println("calculate success");
+     delay(1000);
+   }
+   int16_t axis_x = (dataBuf[0][2] + dataBuf[1][2])*0.3 + (dataBuf[2][2]+dataBuf[3][2]+dataBuf[4][2]+dataBuf[5][2])/10;
+   Serial.print("adjust value of X axis is ");
+   Serial.println(axis_x);
+   int16_t axis_y = (dataBuf[2][1] + dataBuf[3][1])*0.3 + (dataBuf[0][1]+dataBuf[1][1]+dataBuf[4][1]+dataBuf[5][1])/10;
+   Serial.print("adjust value of X axis is ");
+   Serial.println(axis_y);
+   int16_t axis_z = (dataBuf[4][0] + dataBuf[5][0])*0.3 + (dataBuf[0][0]+dataBuf[1][0]+dataBuf[2][0]+dataBuf[3][0])/10;   
+   Serial.print("adjust value of X axis is ");
+   Serial.println(axis_z);
+   Serial.println("note: these data can be used in H3LISDL_Demo sketch");
+}

+ 42 - 0
examples/H3LIS331DL_Demo/H3LIS331DL_Demo.ino

@@ -0,0 +1,42 @@
+/* get accelerate data of H3LIS331DL
+ * Auth : lawliet(lawliet.zou@gmail.com)
+ * version : 0.1
+ */
+
+#include <H3LIS331DL.h>
+#include <Wire.h>
+
+//please get these value by running H3LIS331DL_AdjVal Sketch.
+#define VAL_X_AXIS  100
+#define VAL_Y_AXIS  180
+#define VAL_Z_AXIS  140
+
+H3LIS331DL h3lis;
+
+void setup(){
+  Serial.begin(9600);
+  h3lis.init();
+  h3lis.importPara(VAL_X_AXIS,VAL_Y_AXIS,VAL_Z_AXIS);
+}
+
+void loop(){
+  int16_t x,y,z;
+  h3lis.readXYZ(&x,&y,&z);
+  Serial.print("x, y, z = ");
+  Serial.print(x);
+  Serial.print("\t");
+  Serial.print(y);
+  Serial.print("\t");
+  Serial.println(z);
+
+  double xyz[3];
+  h3lis.getAcceleration(xyz);
+  Serial.print("accelerate of x, y, z = ");
+  Serial.print(xyz[0]);
+  Serial.print("\t");
+  Serial.print(xyz[1]);
+  Serial.print("\t");
+  Serial.println(xyz[2]);  
+  
+  delay(1000);
+}