Environmental Shield API

Committer:
Deepti
Date:
Tue Aug 19 07:13:15 2014 +0000
Revision:
0:9e645e6ed2ce
Environment Shield API

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Deepti 0:9e645e6ed2ce 1 /**
Deepti 0:9e645e6ed2ce 2 ******************************************************************************
Deepti 0:9e645e6ed2ce 3 * @file LPS25H.c
Deepti 0:9e645e6ed2ce 4 * @author AST Robotics Team
Deepti 0:9e645e6ed2ce 5 * @version V0.0.1
Deepti 0:9e645e6ed2ce 6 * @date 03-April-2014
Deepti 0:9e645e6ed2ce 7 * @brief This file provides a set of functions needed to manage the lps25h.
Deepti 0:9e645e6ed2ce 8 ******************************************************************************
Deepti 0:9e645e6ed2ce 9 * @attention
Deepti 0:9e645e6ed2ce 10 *
Deepti 0:9e645e6ed2ce 11 * <h2><center>&copy; COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
Deepti 0:9e645e6ed2ce 12 *
Deepti 0:9e645e6ed2ce 13 * Redistribution and use in source and binary forms, with or without modification,
Deepti 0:9e645e6ed2ce 14 * are permitted provided that the following conditions are met:
Deepti 0:9e645e6ed2ce 15 * 1. Redistributions of source code must retain the above copyright notice,
Deepti 0:9e645e6ed2ce 16 * this list of conditions and the following disclaimer.
Deepti 0:9e645e6ed2ce 17 * 2. Redistributions in binary form must reproduce the above copyright notice,
Deepti 0:9e645e6ed2ce 18 * this list of conditions and the following disclaimer in the documentation
Deepti 0:9e645e6ed2ce 19 * and/or other materials provided with the distribution.
Deepti 0:9e645e6ed2ce 20 * 3. Neither the name of STMicroelectronics nor the names of its contributors
Deepti 0:9e645e6ed2ce 21 * may be used to endorse or promote products derived from this software
Deepti 0:9e645e6ed2ce 22 * without specific prior written permission.
Deepti 0:9e645e6ed2ce 23 *
Deepti 0:9e645e6ed2ce 24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
Deepti 0:9e645e6ed2ce 25 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
Deepti 0:9e645e6ed2ce 26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
Deepti 0:9e645e6ed2ce 27 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
Deepti 0:9e645e6ed2ce 28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
Deepti 0:9e645e6ed2ce 29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
Deepti 0:9e645e6ed2ce 30 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
Deepti 0:9e645e6ed2ce 31 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
Deepti 0:9e645e6ed2ce 32 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
Deepti 0:9e645e6ed2ce 33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Deepti 0:9e645e6ed2ce 34 *
Deepti 0:9e645e6ed2ce 35 ******************************************************************************
Deepti 0:9e645e6ed2ce 36 */
Deepti 0:9e645e6ed2ce 37 /* Includes ------------------------------------------------------------------*/
Deepti 0:9e645e6ed2ce 38 #include "lps25h.h"
Deepti 0:9e645e6ed2ce 39
Deepti 0:9e645e6ed2ce 40 /** @addtogroup BSP
Deepti 0:9e645e6ed2ce 41 * @{
Deepti 0:9e645e6ed2ce 42 */
Deepti 0:9e645e6ed2ce 43
Deepti 0:9e645e6ed2ce 44 /** @addtogroup STM32F439_SENSITRON
Deepti 0:9e645e6ed2ce 45 * @{
Deepti 0:9e645e6ed2ce 46 */
Deepti 0:9e645e6ed2ce 47
Deepti 0:9e645e6ed2ce 48 /** @addtogroup LPS25H
Deepti 0:9e645e6ed2ce 49 * @{
Deepti 0:9e645e6ed2ce 50 */
Deepti 0:9e645e6ed2ce 51
Deepti 0:9e645e6ed2ce 52
Deepti 0:9e645e6ed2ce 53 /** @defgroup LPS25H_Private_TypesDefinitions
Deepti 0:9e645e6ed2ce 54 * @{
Deepti 0:9e645e6ed2ce 55 */
Deepti 0:9e645e6ed2ce 56
Deepti 0:9e645e6ed2ce 57 /**
Deepti 0:9e645e6ed2ce 58 * @}
Deepti 0:9e645e6ed2ce 59 */
Deepti 0:9e645e6ed2ce 60
Deepti 0:9e645e6ed2ce 61 /** @defgroup LPS25H_Private_Defines
Deepti 0:9e645e6ed2ce 62 * @{
Deepti 0:9e645e6ed2ce 63 */
Deepti 0:9e645e6ed2ce 64
Deepti 0:9e645e6ed2ce 65 /**
Deepti 0:9e645e6ed2ce 66 * @}
Deepti 0:9e645e6ed2ce 67 */
Deepti 0:9e645e6ed2ce 68
Deepti 0:9e645e6ed2ce 69 /** @defgroup LPS25H_Private_Macros
Deepti 0:9e645e6ed2ce 70 * @{
Deepti 0:9e645e6ed2ce 71 */
Deepti 0:9e645e6ed2ce 72
Deepti 0:9e645e6ed2ce 73 /**
Deepti 0:9e645e6ed2ce 74 * @}
Deepti 0:9e645e6ed2ce 75 */
Deepti 0:9e645e6ed2ce 76
Deepti 0:9e645e6ed2ce 77 /** @defgroup LPS25H_Private_Variables
Deepti 0:9e645e6ed2ce 78 * @{
Deepti 0:9e645e6ed2ce 79 */
Deepti 0:9e645e6ed2ce 80
Deepti 0:9e645e6ed2ce 81 PRESSURE_DrvTypeDef LPS25HDrv =
Deepti 0:9e645e6ed2ce 82 {
Deepti 0:9e645e6ed2ce 83 LPS25H_Init,
Deepti 0:9e645e6ed2ce 84 LPS25H_PowerOff,
Deepti 0:9e645e6ed2ce 85 LPS25H_ReadID,
Deepti 0:9e645e6ed2ce 86 LPS25H_RebootCmd,
Deepti 0:9e645e6ed2ce 87 0,//LPS25H_INT1InterruptConfig,
Deepti 0:9e645e6ed2ce 88 0,//LPS25H_EnableIT,
Deepti 0:9e645e6ed2ce 89 0,//LPS25H_DisableIT,
Deepti 0:9e645e6ed2ce 90 0,
Deepti 0:9e645e6ed2ce 91 0,
Deepti 0:9e645e6ed2ce 92 LPS25H_GetPressure,
Deepti 0:9e645e6ed2ce 93 LPS25H_GetTemperature,
Deepti 0:9e645e6ed2ce 94 LPS25H_SlaveAddrRemap
Deepti 0:9e645e6ed2ce 95 };
Deepti 0:9e645e6ed2ce 96
Deepti 0:9e645e6ed2ce 97 uint8_t LPS25H_SlaveAddress = LPS25H_ADDRESS_LOW;
Deepti 0:9e645e6ed2ce 98
Deepti 0:9e645e6ed2ce 99 /**
Deepti 0:9e645e6ed2ce 100 * @}
Deepti 0:9e645e6ed2ce 101 */
Deepti 0:9e645e6ed2ce 102
Deepti 0:9e645e6ed2ce 103 /** @defgroup LPS25H_Private_FunctionPrototypes
Deepti 0:9e645e6ed2ce 104 * @{
Deepti 0:9e645e6ed2ce 105 */
Deepti 0:9e645e6ed2ce 106
Deepti 0:9e645e6ed2ce 107 /**
Deepti 0:9e645e6ed2ce 108 * @brief Exit the shutdown mode for LPS25H.
Deepti 0:9e645e6ed2ce 109 * @param None
Deepti 0:9e645e6ed2ce 110 * @retval None
Deepti 0:9e645e6ed2ce 111 */
Deepti 0:9e645e6ed2ce 112 void LPS25H_PowerOn(void);
Deepti 0:9e645e6ed2ce 113
Deepti 0:9e645e6ed2ce 114 void LPS25H_I2C_ReadRawPressure(uint32_t *raw_press);
Deepti 0:9e645e6ed2ce 115
Deepti 0:9e645e6ed2ce 116 void LPS25H_I2C_ReadRawTemperature(int16_t *raw_data);
Deepti 0:9e645e6ed2ce 117
Deepti 0:9e645e6ed2ce 118
Deepti 0:9e645e6ed2ce 119 /**
Deepti 0:9e645e6ed2ce 120 * @}
Deepti 0:9e645e6ed2ce 121 */
Deepti 0:9e645e6ed2ce 122
Deepti 0:9e645e6ed2ce 123 /** @defgroup LPS25H_Private_Functions
Deepti 0:9e645e6ed2ce 124 * @{
Deepti 0:9e645e6ed2ce 125 */
Deepti 0:9e645e6ed2ce 126
Deepti 0:9e645e6ed2ce 127
Deepti 0:9e645e6ed2ce 128 /**
Deepti 0:9e645e6ed2ce 129 * @brief Set LPS25H Initialization.
Deepti 0:9e645e6ed2ce 130 * @param InitStruct: it contains the configuration setting for the LPS25H.
Deepti 0:9e645e6ed2ce 131 * @retval Error Code (PressureError_Enum)
Deepti 0:9e645e6ed2ce 132 */
Deepti 0:9e645e6ed2ce 133 void LPS25H_Init(PRESSURE_InitTypeDef *LPS25H_Init)
Deepti 0:9e645e6ed2ce 134 {
Deepti 0:9e645e6ed2ce 135 uint8_t tmp1 = 0x00;
Deepti 0:9e645e6ed2ce 136
Deepti 0:9e645e6ed2ce 137 /* Configure the low level interface ---------------------------------------*/
Deepti 0:9e645e6ed2ce 138 PRESSURE_IO_Init();
Deepti 0:9e645e6ed2ce 139
Deepti 0:9e645e6ed2ce 140 LPS25H_PowerOn();
Deepti 0:9e645e6ed2ce 141
Deepti 0:9e645e6ed2ce 142 PRESSURE_IO_Read(&tmp1, LPS25H_SlaveAddress, LPS25H_CTRL_REG1_ADDR, 1);
Deepti 0:9e645e6ed2ce 143
Deepti 0:9e645e6ed2ce 144 /* Output Data Rate selection */
Deepti 0:9e645e6ed2ce 145 tmp1 &= ~(LPS25H_ODR_MASK);
Deepti 0:9e645e6ed2ce 146 tmp1 |= LPS25H_Init->OutputDataRate;
Deepti 0:9e645e6ed2ce 147
Deepti 0:9e645e6ed2ce 148 /* Interrupt circuit selection */
Deepti 0:9e645e6ed2ce 149 tmp1 &= ~(LPS25H_DIFF_EN_MASK);
Deepti 0:9e645e6ed2ce 150 tmp1 |= LPS25H_Init->DiffEnable;
Deepti 0:9e645e6ed2ce 151
Deepti 0:9e645e6ed2ce 152 /* Block Data Update selection */
Deepti 0:9e645e6ed2ce 153 tmp1 &= ~(LPS25H_BDU_MASK);
Deepti 0:9e645e6ed2ce 154 tmp1 |= LPS25H_Init->BlockDataUpdate;
Deepti 0:9e645e6ed2ce 155
Deepti 0:9e645e6ed2ce 156 /* Serial Interface Mode selection */
Deepti 0:9e645e6ed2ce 157 tmp1 &= ~(LPS25H_SPI_SIM_MASK);
Deepti 0:9e645e6ed2ce 158 tmp1 |= LPS25H_Init->SPIMode;
Deepti 0:9e645e6ed2ce 159
Deepti 0:9e645e6ed2ce 160 PRESSURE_IO_Write(&tmp1, LPS25H_SlaveAddress, LPS25H_CTRL_REG1_ADDR, 1);
Deepti 0:9e645e6ed2ce 161
Deepti 0:9e645e6ed2ce 162 PRESSURE_IO_Read(&tmp1, LPS25H_SlaveAddress, LPS25H_RES_CONF_ADDR, 1);
Deepti 0:9e645e6ed2ce 163
Deepti 0:9e645e6ed2ce 164 /* Serial Interface Mode selection */
Deepti 0:9e645e6ed2ce 165 tmp1 &= ~(LPS25H_P_RES_MASK);
Deepti 0:9e645e6ed2ce 166 tmp1 |= LPS25H_Init->PressureResolution;
Deepti 0:9e645e6ed2ce 167
Deepti 0:9e645e6ed2ce 168 /* Serial Interface Mode selection */
Deepti 0:9e645e6ed2ce 169 tmp1 &= ~(LPS25H_T_RES_MASK);
Deepti 0:9e645e6ed2ce 170 tmp1 |= LPS25H_Init->TemperatureResolution;
Deepti 0:9e645e6ed2ce 171
Deepti 0:9e645e6ed2ce 172 PRESSURE_IO_Write(&tmp1, LPS25H_SlaveAddress, LPS25H_RES_CONF_ADDR, 1);
Deepti 0:9e645e6ed2ce 173 }
Deepti 0:9e645e6ed2ce 174
Deepti 0:9e645e6ed2ce 175 /**
Deepti 0:9e645e6ed2ce 176 * @brief Read ID address of LPS25H
Deepti 0:9e645e6ed2ce 177 * @param Device ID address
Deepti 0:9e645e6ed2ce 178 * @retval ID name
Deepti 0:9e645e6ed2ce 179 */
Deepti 0:9e645e6ed2ce 180 uint8_t LPS25H_ReadID(void)
Deepti 0:9e645e6ed2ce 181 {
Deepti 0:9e645e6ed2ce 182 uint8_t tmp;
Deepti 0:9e645e6ed2ce 183
Deepti 0:9e645e6ed2ce 184 /* Read WHO I AM register */
Deepti 0:9e645e6ed2ce 185 PRESSURE_IO_Read(&tmp, LPS25H_SlaveAddress, LPS25H_WHO_AM_I_ADDR, 1);
Deepti 0:9e645e6ed2ce 186
Deepti 0:9e645e6ed2ce 187 /* Return the ID */
Deepti 0:9e645e6ed2ce 188 return (uint8_t)tmp;
Deepti 0:9e645e6ed2ce 189 }
Deepti 0:9e645e6ed2ce 190
Deepti 0:9e645e6ed2ce 191 /**
Deepti 0:9e645e6ed2ce 192 * @brief Reboot memory content of LPS25H
Deepti 0:9e645e6ed2ce 193 * @param None
Deepti 0:9e645e6ed2ce 194 * @retval None
Deepti 0:9e645e6ed2ce 195 */
Deepti 0:9e645e6ed2ce 196 void LPS25H_RebootCmd(void)
Deepti 0:9e645e6ed2ce 197 {
Deepti 0:9e645e6ed2ce 198 uint8_t tmpreg;
Deepti 0:9e645e6ed2ce 199
Deepti 0:9e645e6ed2ce 200 /* Read CTRL_REG5 register */
Deepti 0:9e645e6ed2ce 201 PRESSURE_IO_Read(&tmpreg, LPS25H_SlaveAddress, LPS25H_CTRL_REG2_ADDR, 1);
Deepti 0:9e645e6ed2ce 202
Deepti 0:9e645e6ed2ce 203 /* Enable or Disable the reboot memory */
Deepti 0:9e645e6ed2ce 204 tmpreg |= LPS25H_RESET_MEMORY;
Deepti 0:9e645e6ed2ce 205
Deepti 0:9e645e6ed2ce 206 /* Write value to MEMS CTRL_REG5 regsister */
Deepti 0:9e645e6ed2ce 207 PRESSURE_IO_Write(&tmpreg, LPS25H_SlaveAddress, LPS25H_CTRL_REG2_ADDR, 1);
Deepti 0:9e645e6ed2ce 208 }
Deepti 0:9e645e6ed2ce 209
Deepti 0:9e645e6ed2ce 210 /**
Deepti 0:9e645e6ed2ce 211 * @brief Set LPS25H Interrupt INT1 configuration
Deepti 0:9e645e6ed2ce 212 * @param LPS25H_InterruptConfig_TypeDef: pointer to a LPS25H_InterruptConfig_TypeDef
Deepti 0:9e645e6ed2ce 213 * structure that contains the configuration setting for the LPS25H Interrupt.
Deepti 0:9e645e6ed2ce 214 * @retval None
Deepti 0:9e645e6ed2ce 215 */
Deepti 0:9e645e6ed2ce 216 void LPS25H_INT1InterruptConfig(uint16_t Int1Config)
Deepti 0:9e645e6ed2ce 217 {
Deepti 0:9e645e6ed2ce 218
Deepti 0:9e645e6ed2ce 219 }
Deepti 0:9e645e6ed2ce 220
Deepti 0:9e645e6ed2ce 221 /**
Deepti 0:9e645e6ed2ce 222 * @brief Enable INT1
Deepti 0:9e645e6ed2ce 223 * @retval None
Deepti 0:9e645e6ed2ce 224 */
Deepti 0:9e645e6ed2ce 225 void LPS25H_EnableIT()
Deepti 0:9e645e6ed2ce 226 {
Deepti 0:9e645e6ed2ce 227
Deepti 0:9e645e6ed2ce 228 }
Deepti 0:9e645e6ed2ce 229
Deepti 0:9e645e6ed2ce 230 /**
Deepti 0:9e645e6ed2ce 231 * @brief Disable INT1
Deepti 0:9e645e6ed2ce 232 * @retval None
Deepti 0:9e645e6ed2ce 233 */
Deepti 0:9e645e6ed2ce 234 void LPS25H_DisableIT()
Deepti 0:9e645e6ed2ce 235 {
Deepti 0:9e645e6ed2ce 236
Deepti 0:9e645e6ed2ce 237 }
Deepti 0:9e645e6ed2ce 238
Deepti 0:9e645e6ed2ce 239
Deepti 0:9e645e6ed2ce 240 /**
Deepti 0:9e645e6ed2ce 241 * @brief Read LPS25H output register, and calculate the raw pressure.
Deepti 0:9e645e6ed2ce 242 * @param uint32_t: raw_press. Pressure raw value.
Deepti 0:9e645e6ed2ce 243 * @retval LPS25H_ERROR or LPS25H_OK.
Deepti 0:9e645e6ed2ce 244 */
Deepti 0:9e645e6ed2ce 245 void LPS25H_I2C_ReadRawPressure(uint32_t *raw_press)
Deepti 0:9e645e6ed2ce 246 {
Deepti 0:9e645e6ed2ce 247 uint8_t buffer[3], i;
Deepti 0:9e645e6ed2ce 248 uint32_t tempVal=0;
Deepti 0:9e645e6ed2ce 249
Deepti 0:9e645e6ed2ce 250 /* Read the register content */
Deepti 0:9e645e6ed2ce 251
Deepti 0:9e645e6ed2ce 252 PRESSURE_IO_Read(buffer, LPS25H_SlaveAddress, LPS25H_PRESS_POUT_XL_ADDR+0x80, 3);
Deepti 0:9e645e6ed2ce 253 // LPS25H_I2C_Read(LPS25H_PRESS_POUT_XL_ADDR+0x80, 3, buffer);
Deepti 0:9e645e6ed2ce 254
Deepti 0:9e645e6ed2ce 255 /* Build the raw data */
Deepti 0:9e645e6ed2ce 256 for (i = 0 ; i < 3 ; i++)
Deepti 0:9e645e6ed2ce 257 tempVal |= (((uint32_t) buffer[i]) << (8 * i));
Deepti 0:9e645e6ed2ce 258
Deepti 0:9e645e6ed2ce 259 /* convert the 2's complement 24 bit to 2's complement 32 bit */
Deepti 0:9e645e6ed2ce 260 if (tempVal & 0x00800000)
Deepti 0:9e645e6ed2ce 261 tempVal |= 0xFF000000;
Deepti 0:9e645e6ed2ce 262
Deepti 0:9e645e6ed2ce 263 /* return the built value */
Deepti 0:9e645e6ed2ce 264 *raw_press = ((uint32_t) tempVal);
Deepti 0:9e645e6ed2ce 265 }
Deepti 0:9e645e6ed2ce 266
Deepti 0:9e645e6ed2ce 267 /**
Deepti 0:9e645e6ed2ce 268 * @brief Read LPS25H output register, and calculate the pressure in mbar.
Deepti 0:9e645e6ed2ce 269 * @param float *pressure. Pressure value in mbar.
Deepti 0:9e645e6ed2ce 270 * @retval LPS25H_ERROR or LPS25H_OK.
Deepti 0:9e645e6ed2ce 271 */
Deepti 0:9e645e6ed2ce 272 void LPS25H_GetPressure(float* pfData)
Deepti 0:9e645e6ed2ce 273 {
Deepti 0:9e645e6ed2ce 274 uint32_t raw_press = 0;
Deepti 0:9e645e6ed2ce 275
Deepti 0:9e645e6ed2ce 276 LPS25H_I2C_ReadRawPressure(&raw_press);
Deepti 0:9e645e6ed2ce 277
Deepti 0:9e645e6ed2ce 278 /* return the built value */
Deepti 0:9e645e6ed2ce 279 //tempInt = raw_press / 4096;
Deepti 0:9e645e6ed2ce 280
Deepti 0:9e645e6ed2ce 281 *pfData = (float)raw_press /4096.0f;
Deepti 0:9e645e6ed2ce 282 }
Deepti 0:9e645e6ed2ce 283
Deepti 0:9e645e6ed2ce 284 /**
Deepti 0:9e645e6ed2ce 285 * @brief Read LPS25H output register, and calculate the raw temperature.
Deepti 0:9e645e6ed2ce 286 * @param int16_t *raw_data: temperature raw value.
Deepti 0:9e645e6ed2ce 287 * @retval LPS25H_ERROR or LPS25H_OK.
Deepti 0:9e645e6ed2ce 288 */
Deepti 0:9e645e6ed2ce 289 void LPS25H_I2C_ReadRawTemperature(int16_t *raw_data)
Deepti 0:9e645e6ed2ce 290 {
Deepti 0:9e645e6ed2ce 291 uint8_t buffer[2];
Deepti 0:9e645e6ed2ce 292 uint16_t tempVal=0;
Deepti 0:9e645e6ed2ce 293
Deepti 0:9e645e6ed2ce 294 /* Read the register content */
Deepti 0:9e645e6ed2ce 295 PRESSURE_IO_Read(buffer, LPS25H_SlaveAddress, LPS25H_TEMP_OUT_L_ADDR+0x80, 2);
Deepti 0:9e645e6ed2ce 296 // LPS25H_I2C_Read(LPS25H_TEMP_OUT_L_ADDR+0x80, 2, buffer);
Deepti 0:9e645e6ed2ce 297
Deepti 0:9e645e6ed2ce 298 /* Build the raw value */
Deepti 0:9e645e6ed2ce 299 tempVal = (((uint16_t)buffer[1]) << 8)+(uint16_t)buffer[0];
Deepti 0:9e645e6ed2ce 300
Deepti 0:9e645e6ed2ce 301 /* Return it */
Deepti 0:9e645e6ed2ce 302 *raw_data = ((int16_t)tempVal);
Deepti 0:9e645e6ed2ce 303 }
Deepti 0:9e645e6ed2ce 304
Deepti 0:9e645e6ed2ce 305 /**
Deepti 0:9e645e6ed2ce 306 * @brief Read LPS25H output register, and calculate the temperature.
Deepti 0:9e645e6ed2ce 307 * @param float *temperature : temperature value..
Deepti 0:9e645e6ed2ce 308 * @retval LPS25H_ERROR or LPS25H_OK.
Deepti 0:9e645e6ed2ce 309 */
Deepti 0:9e645e6ed2ce 310 void LPS25H_GetTemperature(float* pfData)
Deepti 0:9e645e6ed2ce 311 {
Deepti 0:9e645e6ed2ce 312 int16_t raw_data;
Deepti 0:9e645e6ed2ce 313
Deepti 0:9e645e6ed2ce 314 LPS25H_I2C_ReadRawTemperature(&raw_data);
Deepti 0:9e645e6ed2ce 315
Deepti 0:9e645e6ed2ce 316 //*data_out = (int16_t)((((float)raw_data/480.0) + 42.5)*100);
Deepti 0:9e645e6ed2ce 317 *pfData = (int16_t)((((float)raw_data/480.0) + 42.5));
Deepti 0:9e645e6ed2ce 318 }
Deepti 0:9e645e6ed2ce 319 /**
Deepti 0:9e645e6ed2ce 320 * @brief Exit the shutdown mode for LPS25H.
Deepti 0:9e645e6ed2ce 321 * @param None
Deepti 0:9e645e6ed2ce 322 * @retval LPS25H_ERROR or LPS25H_OK
Deepti 0:9e645e6ed2ce 323 */
Deepti 0:9e645e6ed2ce 324 void LPS25H_PowerOn(void)
Deepti 0:9e645e6ed2ce 325 {
Deepti 0:9e645e6ed2ce 326 uint8_t tmpreg;
Deepti 0:9e645e6ed2ce 327
Deepti 0:9e645e6ed2ce 328 /* Read the register content */
Deepti 0:9e645e6ed2ce 329 // LPS25H_I2C_Read(LPS25H_CTRL_REG1_ADDR,1,&tmpReg);
Deepti 0:9e645e6ed2ce 330 PRESSURE_IO_Read(&tmpreg, LPS25H_SlaveAddress, LPS25H_CTRL_REG1_ADDR, 1);
Deepti 0:9e645e6ed2ce 331
Deepti 0:9e645e6ed2ce 332 /* Set the power down bit */
Deepti 0:9e645e6ed2ce 333 tmpreg |= LPS25H_MODE_ACTIVE;
Deepti 0:9e645e6ed2ce 334
Deepti 0:9e645e6ed2ce 335 /* Write register */
Deepti 0:9e645e6ed2ce 336 // PRESSURE_IO_Write(LPS25H_CTRL_REG1_ADDR,1,&tmpReg);
Deepti 0:9e645e6ed2ce 337 PRESSURE_IO_Write(&tmpreg, LPS25H_SlaveAddress, LPS25H_CTRL_REG1_ADDR, 1);
Deepti 0:9e645e6ed2ce 338
Deepti 0:9e645e6ed2ce 339 }
Deepti 0:9e645e6ed2ce 340
Deepti 0:9e645e6ed2ce 341
Deepti 0:9e645e6ed2ce 342 /**
Deepti 0:9e645e6ed2ce 343 * @brief Enter the shutdown mode for LPS25H.
Deepti 0:9e645e6ed2ce 344 * @param None
Deepti 0:9e645e6ed2ce 345 * @retval LPS25H_ERROR or LPS25H_OK
Deepti 0:9e645e6ed2ce 346 */
Deepti 0:9e645e6ed2ce 347 void LPS25H_PowerOff(void)
Deepti 0:9e645e6ed2ce 348 {
Deepti 0:9e645e6ed2ce 349 uint8_t tmpreg;
Deepti 0:9e645e6ed2ce 350
Deepti 0:9e645e6ed2ce 351 /* Read the register content */
Deepti 0:9e645e6ed2ce 352 // PRESSURE_IO_Read( LPS25H_CTRL_REG1_ADDR,1,&tmpReg);
Deepti 0:9e645e6ed2ce 353 PRESSURE_IO_Read(&tmpreg, LPS25H_SlaveAddress, LPS25H_CTRL_REG1_ADDR, 1);
Deepti 0:9e645e6ed2ce 354
Deepti 0:9e645e6ed2ce 355 /* Reset the power down bit */
Deepti 0:9e645e6ed2ce 356 tmpreg &= ~(LPS25H_MODE_ACTIVE);
Deepti 0:9e645e6ed2ce 357
Deepti 0:9e645e6ed2ce 358 /* Write register */
Deepti 0:9e645e6ed2ce 359 // PRESSURE_IO_Write( LPS25H_CTRL_REG1_ADDR,1,&tmpReg);
Deepti 0:9e645e6ed2ce 360 PRESSURE_IO_Write(&tmpreg, LPS25H_SlaveAddress, LPS25H_CTRL_REG1_ADDR, 1);
Deepti 0:9e645e6ed2ce 361 }
Deepti 0:9e645e6ed2ce 362
Deepti 0:9e645e6ed2ce 363
Deepti 0:9e645e6ed2ce 364 /**
Deepti 0:9e645e6ed2ce 365 * @brief Set the slave address according to SA0 bit.
Deepti 0:9e645e6ed2ce 366 * @param SA0_Bit_Status: LPS25H_SA0_LOW or LPS25H_SA0_HIGH
Deepti 0:9e645e6ed2ce 367 * @retval None
Deepti 0:9e645e6ed2ce 368 */
Deepti 0:9e645e6ed2ce 369 void LPS25H_SlaveAddrRemap(uint8_t SA0_Bit_Status)
Deepti 0:9e645e6ed2ce 370 {
Deepti 0:9e645e6ed2ce 371 LPS25H_SlaveAddress = (SA0_Bit_Status==LPS25H_SA0_LOW?LPS25H_ADDRESS_LOW:LPS25H_ADDRESS_HIGH);
Deepti 0:9e645e6ed2ce 372 }
Deepti 0:9e645e6ed2ce 373
Deepti 0:9e645e6ed2ce 374 /**
Deepti 0:9e645e6ed2ce 375 * @}
Deepti 0:9e645e6ed2ce 376 */
Deepti 0:9e645e6ed2ce 377
Deepti 0:9e645e6ed2ce 378 /**
Deepti 0:9e645e6ed2ce 379 * @}
Deepti 0:9e645e6ed2ce 380 */
Deepti 0:9e645e6ed2ce 381
Deepti 0:9e645e6ed2ce 382 /**
Deepti 0:9e645e6ed2ce 383 * @}
Deepti 0:9e645e6ed2ce 384 */
Deepti 0:9e645e6ed2ce 385
Deepti 0:9e645e6ed2ce 386 /**
Deepti 0:9e645e6ed2ce 387 * @}
Deepti 0:9e645e6ed2ce 388 */
Deepti 0:9e645e6ed2ce 389
Deepti 0:9e645e6ed2ce 390
Deepti 0:9e645e6ed2ce 391 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
Deepti 0:9e645e6ed2ce 392