Example #1
0
/**
 * @brief Initialize the LPS25HB sensor
 * @param handle the device handle
 * @retval COMPONENT_OK in case of success
 * @retval COMPONENT_ERROR in case of failure
 */
static DrvStatusTypeDef LPS25HB_Init( DrvContextTypeDef *handle )
{

  if ( LPS25HB_Check_WhoAmI( handle ) == COMPONENT_ERROR )
  {
    return COMPONENT_ERROR;
  }
  
  /* Power down the device */
  if ( LPS25HB_DeActivate( (void *)handle ) == LPS25HB_ERROR )
  {
    return COMPONENT_ERROR;
  }
  
  if ( LPS25HB_Set_ODR( handle, ODR_LOW ) == COMPONENT_ERROR )
  {
    return COMPONENT_ERROR;
  }
  
  /* Enable interrupt circuit */
  if ( LPS25HB_Set_InterruptCircuitEnable( (void *)handle, LPS25HB_ENABLE ) == LPS25HB_ERROR )
  {
    return COMPONENT_ERROR;
  }
  
  /* Set block data update mode */
  if ( LPS25HB_Set_Bdu( (void *)handle, LPS25HB_BDU_NO_UPDATE ) == LPS25HB_ERROR )
  {
    return COMPONENT_ERROR;
  }
  
  /* Set SPI mode */
  if ( LPS25HB_Set_SpiInterface( (void *)handle, LPS25HB_SPI_3_WIRE ) == LPS25HB_ERROR )
  {
    return COMPONENT_ERROR;
  }
  
  /* Set internal averaging sample counts for pressure and temperature */
  if ( LPS25HB_Set_Avg( (void *)handle, LPS25HB_AVGP_32, LPS25HB_AVGT_16 ) == LPS25HB_ERROR )
  {
    return COMPONENT_ERROR;
  }
  
  return COMPONENT_OK;
}
/**
* @brief   Set Generic Configuration
* @param  *handle Device handle.
* @param  LPS25HB Configuration structure
* @retval  Status [LPS25HB_ERROR, LPS25HB_OK]
*/
LPS25HB_Error_et LPS25HB_Set_GenericConfig(void *handle, LPS25HB_ConfigTypeDef_st* pxLPS25HBInit)
{
  /* Step 1. Init REF_P register*/
  /* The REF_P is the Reference Pressure. Its reset tmp is 0x00*/
  /* The REF_P will be set to the defualt RPDS (0x39h) tmp  if Reset_AZ is enabled.*/
  /* The REF_P will be set the actual pressure output if AutoZero is enabled*/
  
  if((pxLPS25HBInit->Reset_AZ) == LPS25HB_ENABLE)
  {
    if(LPS25HB_ResetAZ(handle))
      return LPS25HB_ERROR;
  }
  else if((pxLPS25HBInit->AutoZero) == LPS25HB_ENABLE)
  {
    if(LPS25HB_Set_AutoZeroFunction(handle, LPS25HB_SET))
      return LPS25HB_ERROR;
  }
  
  /* Step 2. Init the Pressure and Temperature Resolution*/
  if(LPS25HB_Set_Avg(handle, pxLPS25HBInit->PressResolution, pxLPS25HBInit->TempResolution))
    return LPS25HB_ERROR;
    
  /* Step 3. Init the Output Data Rate*/
  if(LPS25HB_Set_Odr(handle, pxLPS25HBInit->OutputDataRate))
    return LPS25HB_ERROR;
    
  /*Step 4. BDU bit is used to inhibit the output registers update between the reading of upper and
  lower register parts. In default mode (BDU = ‘0’), the lower and upper register parts are
  updated continuously. If it is not sure to read faster than output data rate, it is recommended
  to set BDU bit to ‘1’. In this way, after the reading of the lower (upper) register part, the
  content of that output registers is not updated until the upper (lower) part is read too.
  This feature avoids reading LSB and MSB related to different samples.*/
  
  if(LPS25HB_Set_Bdu(handle, pxLPS25HBInit->BDU))
    return LPS25HB_ERROR;
    
  /*Step 5. SIM bit selects the SPI serial interface mode.*/
  /* This feature has effect only if SPI interface is used*/
  
  if(LPS25HB_Set_SpiInterface(handle, pxLPS25HBInit->Sim))
    return LPS25HB_ERROR;
    
  return LPS25HB_OK;
}