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