Environmental Shield API
BSP/Components/hts221/hts221.c@0:9e645e6ed2ce, 2014-08-19 (annotated)
- Committer:
- Deepti
- Date:
- Tue Aug 19 07:13:15 2014 +0000
- Revision:
- 0:9e645e6ed2ce
Environment Shield API
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Deepti | 0:9e645e6ed2ce | 1 | /** |
Deepti | 0:9e645e6ed2ce | 2 | ****************************************************************************** |
Deepti | 0:9e645e6ed2ce | 3 | * @file hts221.c |
Deepti | 0:9e645e6ed2ce | 4 | * @author AST Robotics Team |
Deepti | 0:9e645e6ed2ce | 5 | * @version V0.0.1 |
Deepti | 0:9e645e6ed2ce | 6 | * @date 08-April-2014 |
Deepti | 0:9e645e6ed2ce | 7 | * @brief This file provides a set of functions needed to manage the hts221. |
Deepti | 0:9e645e6ed2ce | 8 | ****************************************************************************** |
Deepti | 0:9e645e6ed2ce | 9 | * @attention |
Deepti | 0:9e645e6ed2ce | 10 | * |
Deepti | 0:9e645e6ed2ce | 11 | * <h2><center>© 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 "hts221.h" |
Deepti | 0:9e645e6ed2ce | 39 | #include <math.h> |
Deepti | 0:9e645e6ed2ce | 40 | |
Deepti | 0:9e645e6ed2ce | 41 | /** @addtogroup BSP |
Deepti | 0:9e645e6ed2ce | 42 | * @{ |
Deepti | 0:9e645e6ed2ce | 43 | */ |
Deepti | 0:9e645e6ed2ce | 44 | |
Deepti | 0:9e645e6ed2ce | 45 | /** @addtogroup STM32F439_SENSITRON |
Deepti | 0:9e645e6ed2ce | 46 | * @{ |
Deepti | 0:9e645e6ed2ce | 47 | */ |
Deepti | 0:9e645e6ed2ce | 48 | |
Deepti | 0:9e645e6ed2ce | 49 | /** @addtogroup HTS221 |
Deepti | 0:9e645e6ed2ce | 50 | * @{ |
Deepti | 0:9e645e6ed2ce | 51 | */ |
Deepti | 0:9e645e6ed2ce | 52 | |
Deepti | 0:9e645e6ed2ce | 53 | |
Deepti | 0:9e645e6ed2ce | 54 | /** @defgroup HTS221_Private_TypesDefinitions |
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 | |
Deepti | 0:9e645e6ed2ce | 62 | /** @defgroup HTS221_Private_Defines |
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 | |
Deepti | 0:9e645e6ed2ce | 70 | /** @defgroup HTS221_Private_Macros |
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 | |
Deepti | 0:9e645e6ed2ce | 78 | /** @defgroup HTS221_Private_Variables |
Deepti | 0:9e645e6ed2ce | 79 | * @{ |
Deepti | 0:9e645e6ed2ce | 80 | */ |
Deepti | 0:9e645e6ed2ce | 81 | |
Deepti | 0:9e645e6ed2ce | 82 | HUM_TEMP_DrvTypeDef Hts221Drv = |
Deepti | 0:9e645e6ed2ce | 83 | { |
Deepti | 0:9e645e6ed2ce | 84 | HTS221_Init, |
Deepti | 0:9e645e6ed2ce | 85 | HTS221_Power_OFF, |
Deepti | 0:9e645e6ed2ce | 86 | HTS221_ReadID, |
Deepti | 0:9e645e6ed2ce | 87 | HTS221_RebootCmd, |
Deepti | 0:9e645e6ed2ce | 88 | HTS221_INT1InterruptConfig, |
Deepti | 0:9e645e6ed2ce | 89 | HTS221_EnableIT, |
Deepti | 0:9e645e6ed2ce | 90 | HTS221_DisableIT, |
Deepti | 0:9e645e6ed2ce | 91 | HTS221_GetHumidity, |
Deepti | 0:9e645e6ed2ce | 92 | HTS221_GetTemperature |
Deepti | 0:9e645e6ed2ce | 93 | }; |
Deepti | 0:9e645e6ed2ce | 94 | |
Deepti | 0:9e645e6ed2ce | 95 | |
Deepti | 0:9e645e6ed2ce | 96 | /* Temperature in degree for calibration */ |
Deepti | 0:9e645e6ed2ce | 97 | float T0_degC, T1_degC; |
Deepti | 0:9e645e6ed2ce | 98 | |
Deepti | 0:9e645e6ed2ce | 99 | /* Output temperature value for calibration */ |
Deepti | 0:9e645e6ed2ce | 100 | int16_t T0_out, T1_out; |
Deepti | 0:9e645e6ed2ce | 101 | |
Deepti | 0:9e645e6ed2ce | 102 | |
Deepti | 0:9e645e6ed2ce | 103 | /* Humidity for calibration */ |
Deepti | 0:9e645e6ed2ce | 104 | float H0_rh, H1_rh; |
Deepti | 0:9e645e6ed2ce | 105 | |
Deepti | 0:9e645e6ed2ce | 106 | /* Output Humidity value for calibration */ |
Deepti | 0:9e645e6ed2ce | 107 | int16_t H0_T0_out, H1_T0_out; |
Deepti | 0:9e645e6ed2ce | 108 | |
Deepti | 0:9e645e6ed2ce | 109 | |
Deepti | 0:9e645e6ed2ce | 110 | /** |
Deepti | 0:9e645e6ed2ce | 111 | * @} |
Deepti | 0:9e645e6ed2ce | 112 | */ |
Deepti | 0:9e645e6ed2ce | 113 | |
Deepti | 0:9e645e6ed2ce | 114 | /** @defgroup HTS221_Private_FunctionPrototypes |
Deepti | 0:9e645e6ed2ce | 115 | * @{ |
Deepti | 0:9e645e6ed2ce | 116 | */ |
Deepti | 0:9e645e6ed2ce | 117 | static void HTS221_Power_On(void); |
Deepti | 0:9e645e6ed2ce | 118 | |
Deepti | 0:9e645e6ed2ce | 119 | static void HTS221_Calibration(void); |
Deepti | 0:9e645e6ed2ce | 120 | /** |
Deepti | 0:9e645e6ed2ce | 121 | * @} |
Deepti | 0:9e645e6ed2ce | 122 | */ |
Deepti | 0:9e645e6ed2ce | 123 | |
Deepti | 0:9e645e6ed2ce | 124 | /** @defgroup HTS221_Private_Functions |
Deepti | 0:9e645e6ed2ce | 125 | * @{ |
Deepti | 0:9e645e6ed2ce | 126 | */ |
Deepti | 0:9e645e6ed2ce | 127 | |
Deepti | 0:9e645e6ed2ce | 128 | |
Deepti | 0:9e645e6ed2ce | 129 | |
Deepti | 0:9e645e6ed2ce | 130 | /** |
Deepti | 0:9e645e6ed2ce | 131 | * @brief HTS221 Calibration procedure. |
Deepti | 0:9e645e6ed2ce | 132 | * @param None |
Deepti | 0:9e645e6ed2ce | 133 | * @retval None |
Deepti | 0:9e645e6ed2ce | 134 | */ |
Deepti | 0:9e645e6ed2ce | 135 | static void HTS221_Calibration(void) |
Deepti | 0:9e645e6ed2ce | 136 | { |
Deepti | 0:9e645e6ed2ce | 137 | /* Temperature Calibration */ |
Deepti | 0:9e645e6ed2ce | 138 | /* Temperature in degree for calibration ( "/8" to obtain float) */ |
Deepti | 0:9e645e6ed2ce | 139 | uint16_t T0_degC_x8_L, T0_degC_x8_H, T1_degC_x8_L, T1_degC_x8_H; |
Deepti | 0:9e645e6ed2ce | 140 | uint8_t H0_rh_x2, H1_rh_x2; |
Deepti | 0:9e645e6ed2ce | 141 | uint8_t tempReg[2] = {0,0}; |
Deepti | 0:9e645e6ed2ce | 142 | |
Deepti | 0:9e645e6ed2ce | 143 | HUM_TEMP_IO_Read(tempReg, HTS221_ADDRESS, HTS221_T0_degC_X8_ADDR, 1); |
Deepti | 0:9e645e6ed2ce | 144 | T0_degC_x8_L = (uint16_t)tempReg[0]; |
Deepti | 0:9e645e6ed2ce | 145 | |
Deepti | 0:9e645e6ed2ce | 146 | HUM_TEMP_IO_Read(tempReg, HTS221_ADDRESS, HTS221_T1_T0_MSB_X8_ADDR, 1); |
Deepti | 0:9e645e6ed2ce | 147 | T0_degC_x8_H = (uint16_t) (tempReg[0] & 0x03); |
Deepti | 0:9e645e6ed2ce | 148 | |
Deepti | 0:9e645e6ed2ce | 149 | T0_degC = ((float)((T0_degC_x8_H<<8) | (T0_degC_x8_L)))/8; |
Deepti | 0:9e645e6ed2ce | 150 | |
Deepti | 0:9e645e6ed2ce | 151 | HUM_TEMP_IO_Read(tempReg, HTS221_ADDRESS, HTS221_T1_degC_X8_ADDR, 1); |
Deepti | 0:9e645e6ed2ce | 152 | T1_degC_x8_L = (uint16_t)tempReg[0]; |
Deepti | 0:9e645e6ed2ce | 153 | |
Deepti | 0:9e645e6ed2ce | 154 | HUM_TEMP_IO_Read(tempReg, HTS221_ADDRESS, HTS221_T1_T0_MSB_X8_ADDR, 1); |
Deepti | 0:9e645e6ed2ce | 155 | T1_degC_x8_H = (uint16_t) (tempReg[0] & 0x0C); |
Deepti | 0:9e645e6ed2ce | 156 | T1_degC_x8_H = T1_degC_x8_H >> 2; |
Deepti | 0:9e645e6ed2ce | 157 | |
Deepti | 0:9e645e6ed2ce | 158 | T1_degC = ((float)((T1_degC_x8_H<<8) | (T1_degC_x8_L)))/8; |
Deepti | 0:9e645e6ed2ce | 159 | |
Deepti | 0:9e645e6ed2ce | 160 | HUM_TEMP_IO_Read(tempReg, HTS221_ADDRESS, HTS221_T0_OUT_L_ADDR + 0x80, 2); |
Deepti | 0:9e645e6ed2ce | 161 | T0_out = ((((int16_t)tempReg[1]) << 8)+(int16_t)tempReg[0]); |
Deepti | 0:9e645e6ed2ce | 162 | |
Deepti | 0:9e645e6ed2ce | 163 | HUM_TEMP_IO_Read(tempReg, HTS221_ADDRESS, HTS221_T1_OUT_L_ADDR + 0x80, 2); |
Deepti | 0:9e645e6ed2ce | 164 | T1_out = ((((int16_t)tempReg[1]) << 8)+(int16_t)tempReg[0]); |
Deepti | 0:9e645e6ed2ce | 165 | |
Deepti | 0:9e645e6ed2ce | 166 | /* Humidity Calibration */ |
Deepti | 0:9e645e6ed2ce | 167 | /* Humidity in degree for calibration ( "/2" to obtain float) */ |
Deepti | 0:9e645e6ed2ce | 168 | |
Deepti | 0:9e645e6ed2ce | 169 | HUM_TEMP_IO_Read(&H0_rh_x2, HTS221_ADDRESS, HTS221_H0_RH_X2_ADDR, 1); |
Deepti | 0:9e645e6ed2ce | 170 | |
Deepti | 0:9e645e6ed2ce | 171 | HUM_TEMP_IO_Read(&H1_rh_x2, HTS221_ADDRESS, HTS221_H1_RH_X2_ADDR, 1); |
Deepti | 0:9e645e6ed2ce | 172 | |
Deepti | 0:9e645e6ed2ce | 173 | HUM_TEMP_IO_Read(&tempReg[0], HTS221_ADDRESS, HTS221_H0_T0_OUT_L_ADDR + 0x80, 2); |
Deepti | 0:9e645e6ed2ce | 174 | H0_T0_out = ((((int16_t)tempReg[1]) << 8)+(int16_t)tempReg[0]); |
Deepti | 0:9e645e6ed2ce | 175 | |
Deepti | 0:9e645e6ed2ce | 176 | HUM_TEMP_IO_Read(&tempReg[0], HTS221_ADDRESS, HTS221_H1_T0_OUT_L_ADDR + 0x80, 2); |
Deepti | 0:9e645e6ed2ce | 177 | H1_T0_out = ((((int16_t)tempReg[1]) << 8)+(int16_t)tempReg[0]); |
Deepti | 0:9e645e6ed2ce | 178 | |
Deepti | 0:9e645e6ed2ce | 179 | H0_rh = ((float)H0_rh_x2)/2; |
Deepti | 0:9e645e6ed2ce | 180 | H1_rh = ((float)H1_rh_x2)/2; |
Deepti | 0:9e645e6ed2ce | 181 | } |
Deepti | 0:9e645e6ed2ce | 182 | |
Deepti | 0:9e645e6ed2ce | 183 | |
Deepti | 0:9e645e6ed2ce | 184 | /** |
Deepti | 0:9e645e6ed2ce | 185 | * @brief Set HTS221 Initialization. |
Deepti | 0:9e645e6ed2ce | 186 | * @param InitStruct: it contains the configuration setting for the HTS221. |
Deepti | 0:9e645e6ed2ce | 187 | * @retval None |
Deepti | 0:9e645e6ed2ce | 188 | */ |
Deepti | 0:9e645e6ed2ce | 189 | void HTS221_Init(HUM_TEMP_InitTypeDef *HTS221_Init) |
Deepti | 0:9e645e6ed2ce | 190 | { |
Deepti | 0:9e645e6ed2ce | 191 | uint8_t tmp = 0x00; |
Deepti | 0:9e645e6ed2ce | 192 | |
Deepti | 0:9e645e6ed2ce | 193 | /* Configure the low level interface ---------------------------------------*/ |
Deepti | 0:9e645e6ed2ce | 194 | HUM_TEMP_IO_Init(); |
Deepti | 0:9e645e6ed2ce | 195 | |
Deepti | 0:9e645e6ed2ce | 196 | HTS221_Power_On(); |
Deepti | 0:9e645e6ed2ce | 197 | |
Deepti | 0:9e645e6ed2ce | 198 | HTS221_Calibration(); |
Deepti | 0:9e645e6ed2ce | 199 | |
Deepti | 0:9e645e6ed2ce | 200 | HUM_TEMP_IO_Read(&tmp, HTS221_ADDRESS, HTS221_CTRL_REG1_ADDR, 1); |
Deepti | 0:9e645e6ed2ce | 201 | |
Deepti | 0:9e645e6ed2ce | 202 | /* Output Data Rate selection */ |
Deepti | 0:9e645e6ed2ce | 203 | tmp &= ~(HTS221_ODR_MASK); |
Deepti | 0:9e645e6ed2ce | 204 | tmp |= HTS221_Init->OutputDataRate; |
Deepti | 0:9e645e6ed2ce | 205 | |
Deepti | 0:9e645e6ed2ce | 206 | HUM_TEMP_IO_Write(&tmp, HTS221_ADDRESS, HTS221_CTRL_REG1_ADDR, 1); |
Deepti | 0:9e645e6ed2ce | 207 | } |
Deepti | 0:9e645e6ed2ce | 208 | |
Deepti | 0:9e645e6ed2ce | 209 | /** |
Deepti | 0:9e645e6ed2ce | 210 | * @brief Read ID address of HTS221 |
Deepti | 0:9e645e6ed2ce | 211 | * @param Device ID address |
Deepti | 0:9e645e6ed2ce | 212 | * @retval ID name |
Deepti | 0:9e645e6ed2ce | 213 | */ |
Deepti | 0:9e645e6ed2ce | 214 | uint8_t HTS221_ReadID(void) |
Deepti | 0:9e645e6ed2ce | 215 | { |
Deepti | 0:9e645e6ed2ce | 216 | uint8_t tmp; |
Deepti | 0:9e645e6ed2ce | 217 | |
Deepti | 0:9e645e6ed2ce | 218 | /* Read WHO I AM register */ |
Deepti | 0:9e645e6ed2ce | 219 | HUM_TEMP_IO_Read(&tmp, HTS221_ADDRESS, HTS221_WHO_AM_I_ADDR, 1); |
Deepti | 0:9e645e6ed2ce | 220 | |
Deepti | 0:9e645e6ed2ce | 221 | /* Return the ID */ |
Deepti | 0:9e645e6ed2ce | 222 | return (uint8_t)tmp; |
Deepti | 0:9e645e6ed2ce | 223 | } |
Deepti | 0:9e645e6ed2ce | 224 | |
Deepti | 0:9e645e6ed2ce | 225 | /** |
Deepti | 0:9e645e6ed2ce | 226 | * @brief Reboot memory content of HTS221 |
Deepti | 0:9e645e6ed2ce | 227 | * @param None |
Deepti | 0:9e645e6ed2ce | 228 | * @retval None |
Deepti | 0:9e645e6ed2ce | 229 | */ |
Deepti | 0:9e645e6ed2ce | 230 | void HTS221_RebootCmd(void) |
Deepti | 0:9e645e6ed2ce | 231 | { |
Deepti | 0:9e645e6ed2ce | 232 | uint8_t tmpreg; |
Deepti | 0:9e645e6ed2ce | 233 | |
Deepti | 0:9e645e6ed2ce | 234 | /* Read CTRL_REG2 register */ |
Deepti | 0:9e645e6ed2ce | 235 | HUM_TEMP_IO_Read(&tmpreg, HTS221_ADDRESS, HTS221_CTRL_REG2_ADDR, 1); |
Deepti | 0:9e645e6ed2ce | 236 | |
Deepti | 0:9e645e6ed2ce | 237 | /* Enable or Disable the reboot memory */ |
Deepti | 0:9e645e6ed2ce | 238 | tmpreg |= HTS221_BOOT_REBOOTMEMORY; |
Deepti | 0:9e645e6ed2ce | 239 | |
Deepti | 0:9e645e6ed2ce | 240 | /* Write value to MEMS CTRL_REG2 regsister */ |
Deepti | 0:9e645e6ed2ce | 241 | HUM_TEMP_IO_Write(&tmpreg, HTS221_ADDRESS, HTS221_CTRL_REG2_ADDR, 1); |
Deepti | 0:9e645e6ed2ce | 242 | } |
Deepti | 0:9e645e6ed2ce | 243 | |
Deepti | 0:9e645e6ed2ce | 244 | /** |
Deepti | 0:9e645e6ed2ce | 245 | * @brief Set HTS221 Interrupt INT1 configuration |
Deepti | 0:9e645e6ed2ce | 246 | * @param HTS221_InterruptConfig_TypeDef: pointer to a HTS221_InterruptConfig_TypeDef |
Deepti | 0:9e645e6ed2ce | 247 | * structure that contains the configuration setting for the HTS221 Interrupt. |
Deepti | 0:9e645e6ed2ce | 248 | * @retval None |
Deepti | 0:9e645e6ed2ce | 249 | */ |
Deepti | 0:9e645e6ed2ce | 250 | void HTS221_INT1InterruptConfig(uint16_t Int1Config) |
Deepti | 0:9e645e6ed2ce | 251 | { |
Deepti | 0:9e645e6ed2ce | 252 | |
Deepti | 0:9e645e6ed2ce | 253 | } |
Deepti | 0:9e645e6ed2ce | 254 | |
Deepti | 0:9e645e6ed2ce | 255 | /** |
Deepti | 0:9e645e6ed2ce | 256 | * @brief Enable INT1 |
Deepti | 0:9e645e6ed2ce | 257 | * @retval None |
Deepti | 0:9e645e6ed2ce | 258 | */ |
Deepti | 0:9e645e6ed2ce | 259 | void HTS221_EnableIT(uint8_t IntPin) |
Deepti | 0:9e645e6ed2ce | 260 | { |
Deepti | 0:9e645e6ed2ce | 261 | |
Deepti | 0:9e645e6ed2ce | 262 | } |
Deepti | 0:9e645e6ed2ce | 263 | |
Deepti | 0:9e645e6ed2ce | 264 | /** |
Deepti | 0:9e645e6ed2ce | 265 | * @brief Disable INT1 |
Deepti | 0:9e645e6ed2ce | 266 | * @retval None |
Deepti | 0:9e645e6ed2ce | 267 | */ |
Deepti | 0:9e645e6ed2ce | 268 | void HTS221_DisableIT(uint8_t IntPin) |
Deepti | 0:9e645e6ed2ce | 269 | { |
Deepti | 0:9e645e6ed2ce | 270 | |
Deepti | 0:9e645e6ed2ce | 271 | } |
Deepti | 0:9e645e6ed2ce | 272 | |
Deepti | 0:9e645e6ed2ce | 273 | |
Deepti | 0:9e645e6ed2ce | 274 | /** |
Deepti | 0:9e645e6ed2ce | 275 | * @brief Read HTS221 output register, and calculate the humidity. |
Deepti | 0:9e645e6ed2ce | 276 | * @param pfData : Data out pointer |
Deepti | 0:9e645e6ed2ce | 277 | * @retval None |
Deepti | 0:9e645e6ed2ce | 278 | */ |
Deepti | 0:9e645e6ed2ce | 279 | void HTS221_GetHumidity(float* pfData) |
Deepti | 0:9e645e6ed2ce | 280 | { |
Deepti | 0:9e645e6ed2ce | 281 | int16_t H_T_out, humidity_t; |
Deepti | 0:9e645e6ed2ce | 282 | uint8_t tempReg[2] = {0,0}; |
Deepti | 0:9e645e6ed2ce | 283 | uint8_t tmp = 0x00; |
Deepti | 0:9e645e6ed2ce | 284 | float H_rh; |
Deepti | 0:9e645e6ed2ce | 285 | |
Deepti | 0:9e645e6ed2ce | 286 | HUM_TEMP_IO_Read(&tmp, HTS221_ADDRESS, HTS221_CTRL_REG1_ADDR, 1); |
Deepti | 0:9e645e6ed2ce | 287 | |
Deepti | 0:9e645e6ed2ce | 288 | /* Output Data Rate selection */ |
Deepti | 0:9e645e6ed2ce | 289 | tmp &= (HTS221_ODR_MASK); |
Deepti | 0:9e645e6ed2ce | 290 | |
Deepti | 0:9e645e6ed2ce | 291 | if(tmp == 0x00){ |
Deepti | 0:9e645e6ed2ce | 292 | |
Deepti | 0:9e645e6ed2ce | 293 | HUM_TEMP_IO_Read(&tmp, HTS221_ADDRESS, HTS221_CTRL_REG2_ADDR, 1); |
Deepti | 0:9e645e6ed2ce | 294 | |
Deepti | 0:9e645e6ed2ce | 295 | /* Serial Interface Mode selection */ |
Deepti | 0:9e645e6ed2ce | 296 | tmp &= ~(HTS221_ONE_SHOT_MASK); |
Deepti | 0:9e645e6ed2ce | 297 | tmp |= HTS221_ONE_SHOT_START; |
Deepti | 0:9e645e6ed2ce | 298 | |
Deepti | 0:9e645e6ed2ce | 299 | HUM_TEMP_IO_Write(&tmp, HTS221_ADDRESS, HTS221_CTRL_REG2_ADDR, 1); |
Deepti | 0:9e645e6ed2ce | 300 | |
Deepti | 0:9e645e6ed2ce | 301 | do{ |
Deepti | 0:9e645e6ed2ce | 302 | |
Deepti | 0:9e645e6ed2ce | 303 | HUM_TEMP_IO_Read(&tmp, HTS221_ADDRESS, HTS221_STATUS_REG_ADDR, 1); |
Deepti | 0:9e645e6ed2ce | 304 | |
Deepti | 0:9e645e6ed2ce | 305 | }while(!(tmp&&0x02)); |
Deepti | 0:9e645e6ed2ce | 306 | |
Deepti | 0:9e645e6ed2ce | 307 | } |
Deepti | 0:9e645e6ed2ce | 308 | |
Deepti | 0:9e645e6ed2ce | 309 | |
Deepti | 0:9e645e6ed2ce | 310 | HUM_TEMP_IO_Read(&tempReg[0], HTS221_ADDRESS, HTS221_HUMIDITY_OUT_L_ADDR + 0x80, 2); |
Deepti | 0:9e645e6ed2ce | 311 | H_T_out = ((((int16_t)tempReg[1]) << 8)+(int16_t)tempReg[0]); |
Deepti | 0:9e645e6ed2ce | 312 | |
Deepti | 0:9e645e6ed2ce | 313 | H_rh = ((float)(H_T_out - H0_T0_out))/(H1_T0_out - H0_T0_out) * (H1_rh - H0_rh) + H0_rh; |
Deepti | 0:9e645e6ed2ce | 314 | |
Deepti | 0:9e645e6ed2ce | 315 | humidity_t = (uint16_t)(H_rh * pow(10,HUM_DECIMAL_DIGITS)); |
Deepti | 0:9e645e6ed2ce | 316 | |
Deepti | 0:9e645e6ed2ce | 317 | *pfData = ((float)humidity_t)/pow(10,HUM_DECIMAL_DIGITS); |
Deepti | 0:9e645e6ed2ce | 318 | } |
Deepti | 0:9e645e6ed2ce | 319 | |
Deepti | 0:9e645e6ed2ce | 320 | /** |
Deepti | 0:9e645e6ed2ce | 321 | * @brief Read HTS221 output register, and calculate the temperature. |
Deepti | 0:9e645e6ed2ce | 322 | * @param pfData : Data out pointer |
Deepti | 0:9e645e6ed2ce | 323 | * @retval None |
Deepti | 0:9e645e6ed2ce | 324 | */ |
Deepti | 0:9e645e6ed2ce | 325 | void HTS221_GetTemperature(float* pfData) |
Deepti | 0:9e645e6ed2ce | 326 | { |
Deepti | 0:9e645e6ed2ce | 327 | int16_t T_out, temperature_t; |
Deepti | 0:9e645e6ed2ce | 328 | uint8_t tempReg[2] = {0,0}; |
Deepti | 0:9e645e6ed2ce | 329 | uint8_t tmp = 0x00; |
Deepti | 0:9e645e6ed2ce | 330 | float T_degC; |
Deepti | 0:9e645e6ed2ce | 331 | |
Deepti | 0:9e645e6ed2ce | 332 | HUM_TEMP_IO_Read(&tmp, HTS221_ADDRESS, HTS221_CTRL_REG1_ADDR, 1); |
Deepti | 0:9e645e6ed2ce | 333 | |
Deepti | 0:9e645e6ed2ce | 334 | /* Output Data Rate selection */ |
Deepti | 0:9e645e6ed2ce | 335 | tmp &= (HTS221_ODR_MASK); |
Deepti | 0:9e645e6ed2ce | 336 | |
Deepti | 0:9e645e6ed2ce | 337 | if(tmp == 0x00){ |
Deepti | 0:9e645e6ed2ce | 338 | |
Deepti | 0:9e645e6ed2ce | 339 | HUM_TEMP_IO_Read(&tmp, HTS221_ADDRESS, HTS221_CTRL_REG2_ADDR, 1); |
Deepti | 0:9e645e6ed2ce | 340 | |
Deepti | 0:9e645e6ed2ce | 341 | /* Serial Interface Mode selection */ |
Deepti | 0:9e645e6ed2ce | 342 | tmp &= ~(HTS221_ONE_SHOT_MASK); |
Deepti | 0:9e645e6ed2ce | 343 | tmp |= HTS221_ONE_SHOT_START; |
Deepti | 0:9e645e6ed2ce | 344 | |
Deepti | 0:9e645e6ed2ce | 345 | HUM_TEMP_IO_Write(&tmp, HTS221_ADDRESS, HTS221_CTRL_REG2_ADDR, 1); |
Deepti | 0:9e645e6ed2ce | 346 | |
Deepti | 0:9e645e6ed2ce | 347 | do{ |
Deepti | 0:9e645e6ed2ce | 348 | |
Deepti | 0:9e645e6ed2ce | 349 | HUM_TEMP_IO_Read(&tmp, HTS221_ADDRESS, HTS221_STATUS_REG_ADDR, 1); |
Deepti | 0:9e645e6ed2ce | 350 | |
Deepti | 0:9e645e6ed2ce | 351 | }while(!(tmp&&0x01)); |
Deepti | 0:9e645e6ed2ce | 352 | |
Deepti | 0:9e645e6ed2ce | 353 | } |
Deepti | 0:9e645e6ed2ce | 354 | |
Deepti | 0:9e645e6ed2ce | 355 | HUM_TEMP_IO_Read(&tempReg[0], HTS221_ADDRESS, HTS221_TEMP_OUT_L_ADDR + 0x80, 2); |
Deepti | 0:9e645e6ed2ce | 356 | T_out = ((((int16_t)tempReg[1]) << 8)+(int16_t)tempReg[0]); |
Deepti | 0:9e645e6ed2ce | 357 | |
Deepti | 0:9e645e6ed2ce | 358 | T_degC = ((float)(T_out - T0_out))/(T1_out - T0_out) * (T1_degC - T0_degC) + T0_degC; |
Deepti | 0:9e645e6ed2ce | 359 | |
Deepti | 0:9e645e6ed2ce | 360 | temperature_t = (int16_t)(T_degC * pow(10,TEMP_DECIMAL_DIGITS)); |
Deepti | 0:9e645e6ed2ce | 361 | |
Deepti | 0:9e645e6ed2ce | 362 | *pfData = ((float)temperature_t)/pow(10,TEMP_DECIMAL_DIGITS); |
Deepti | 0:9e645e6ed2ce | 363 | } |
Deepti | 0:9e645e6ed2ce | 364 | |
Deepti | 0:9e645e6ed2ce | 365 | |
Deepti | 0:9e645e6ed2ce | 366 | /** |
Deepti | 0:9e645e6ed2ce | 367 | * @brief Exit the shutdown mode for HTS221. |
Deepti | 0:9e645e6ed2ce | 368 | * @retval None |
Deepti | 0:9e645e6ed2ce | 369 | */ |
Deepti | 0:9e645e6ed2ce | 370 | static void HTS221_Power_On() |
Deepti | 0:9e645e6ed2ce | 371 | { |
Deepti | 0:9e645e6ed2ce | 372 | uint8_t tmpReg; |
Deepti | 0:9e645e6ed2ce | 373 | |
Deepti | 0:9e645e6ed2ce | 374 | /* Read the register content */ |
Deepti | 0:9e645e6ed2ce | 375 | HUM_TEMP_IO_Read(&tmpReg, HTS221_ADDRESS, HTS221_CTRL_REG1_ADDR, 1); |
Deepti | 0:9e645e6ed2ce | 376 | |
Deepti | 0:9e645e6ed2ce | 377 | /* Set the power down bit */ |
Deepti | 0:9e645e6ed2ce | 378 | tmpReg |= HTS221_MODE_ACTIVE; |
Deepti | 0:9e645e6ed2ce | 379 | |
Deepti | 0:9e645e6ed2ce | 380 | /* Write register */ |
Deepti | 0:9e645e6ed2ce | 381 | HUM_TEMP_IO_Write(&tmpReg, HTS221_ADDRESS, HTS221_CTRL_REG1_ADDR, 1); |
Deepti | 0:9e645e6ed2ce | 382 | } |
Deepti | 0:9e645e6ed2ce | 383 | |
Deepti | 0:9e645e6ed2ce | 384 | /** |
Deepti | 0:9e645e6ed2ce | 385 | * @brief Enter the shutdown mode for HTS221. |
Deepti | 0:9e645e6ed2ce | 386 | * @retval None |
Deepti | 0:9e645e6ed2ce | 387 | */ |
Deepti | 0:9e645e6ed2ce | 388 | void HTS221_Power_OFF() |
Deepti | 0:9e645e6ed2ce | 389 | { |
Deepti | 0:9e645e6ed2ce | 390 | uint8_t tmpReg; |
Deepti | 0:9e645e6ed2ce | 391 | |
Deepti | 0:9e645e6ed2ce | 392 | /* Read the register content */ |
Deepti | 0:9e645e6ed2ce | 393 | HUM_TEMP_IO_Read(&tmpReg, HTS221_ADDRESS, HTS221_CTRL_REG1_ADDR, 1); |
Deepti | 0:9e645e6ed2ce | 394 | |
Deepti | 0:9e645e6ed2ce | 395 | /* Reset the power down bit */ |
Deepti | 0:9e645e6ed2ce | 396 | tmpReg &= ~(HTS221_MODE_ACTIVE); |
Deepti | 0:9e645e6ed2ce | 397 | |
Deepti | 0:9e645e6ed2ce | 398 | /* Write register */ |
Deepti | 0:9e645e6ed2ce | 399 | HUM_TEMP_IO_Write(&tmpReg, HTS221_ADDRESS, HTS221_CTRL_REG1_ADDR, 1); |
Deepti | 0:9e645e6ed2ce | 400 | } |
Deepti | 0:9e645e6ed2ce | 401 | |
Deepti | 0:9e645e6ed2ce | 402 | /** |
Deepti | 0:9e645e6ed2ce | 403 | * @} |
Deepti | 0:9e645e6ed2ce | 404 | */ |
Deepti | 0:9e645e6ed2ce | 405 | |
Deepti | 0:9e645e6ed2ce | 406 | /** |
Deepti | 0:9e645e6ed2ce | 407 | * @} |
Deepti | 0:9e645e6ed2ce | 408 | */ |
Deepti | 0:9e645e6ed2ce | 409 | |
Deepti | 0:9e645e6ed2ce | 410 | /** |
Deepti | 0:9e645e6ed2ce | 411 | * @} |
Deepti | 0:9e645e6ed2ce | 412 | */ |
Deepti | 0:9e645e6ed2ce | 413 | |
Deepti | 0:9e645e6ed2ce | 414 | /** |
Deepti | 0:9e645e6ed2ce | 415 | * @} |
Deepti | 0:9e645e6ed2ce | 416 | */ |
Deepti | 0:9e645e6ed2ce | 417 | |
Deepti | 0:9e645e6ed2ce | 418 | |
Deepti | 0:9e645e6ed2ce | 419 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
Deepti | 0:9e645e6ed2ce | 420 |