Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
BSP/Components/hts221/hts221.c@0:9ac219c9a7df, 2014-08-14 (annotated)
- Committer:
- Deepti
- Date:
- Thu Aug 14 11:39:55 2014 +0000
- Revision:
- 0:9ac219c9a7df
Environmental Shield API
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Deepti | 0:9ac219c9a7df | 1 | /** |
Deepti | 0:9ac219c9a7df | 2 | ****************************************************************************** |
Deepti | 0:9ac219c9a7df | 3 | * @file hts221.c |
Deepti | 0:9ac219c9a7df | 4 | * @author AST Robotics Team |
Deepti | 0:9ac219c9a7df | 5 | * @version V0.0.1 |
Deepti | 0:9ac219c9a7df | 6 | * @date 08-April-2014 |
Deepti | 0:9ac219c9a7df | 7 | * @brief This file provides a set of functions needed to manage the hts221. |
Deepti | 0:9ac219c9a7df | 8 | ****************************************************************************** |
Deepti | 0:9ac219c9a7df | 9 | * @attention |
Deepti | 0:9ac219c9a7df | 10 | * |
Deepti | 0:9ac219c9a7df | 11 | * <h2><center>© COPYRIGHT(c) 2014 STMicroelectronics</center></h2> |
Deepti | 0:9ac219c9a7df | 12 | * |
Deepti | 0:9ac219c9a7df | 13 | * Redistribution and use in source and binary forms, with or without modification, |
Deepti | 0:9ac219c9a7df | 14 | * are permitted provided that the following conditions are met: |
Deepti | 0:9ac219c9a7df | 15 | * 1. Redistributions of source code must retain the above copyright notice, |
Deepti | 0:9ac219c9a7df | 16 | * this list of conditions and the following disclaimer. |
Deepti | 0:9ac219c9a7df | 17 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
Deepti | 0:9ac219c9a7df | 18 | * this list of conditions and the following disclaimer in the documentation |
Deepti | 0:9ac219c9a7df | 19 | * and/or other materials provided with the distribution. |
Deepti | 0:9ac219c9a7df | 20 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
Deepti | 0:9ac219c9a7df | 21 | * may be used to endorse or promote products derived from this software |
Deepti | 0:9ac219c9a7df | 22 | * without specific prior written permission. |
Deepti | 0:9ac219c9a7df | 23 | * |
Deepti | 0:9ac219c9a7df | 24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
Deepti | 0:9ac219c9a7df | 25 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
Deepti | 0:9ac219c9a7df | 26 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
Deepti | 0:9ac219c9a7df | 27 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
Deepti | 0:9ac219c9a7df | 28 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
Deepti | 0:9ac219c9a7df | 29 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
Deepti | 0:9ac219c9a7df | 30 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
Deepti | 0:9ac219c9a7df | 31 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
Deepti | 0:9ac219c9a7df | 32 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
Deepti | 0:9ac219c9a7df | 33 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
Deepti | 0:9ac219c9a7df | 34 | * |
Deepti | 0:9ac219c9a7df | 35 | ****************************************************************************** |
Deepti | 0:9ac219c9a7df | 36 | */ |
Deepti | 0:9ac219c9a7df | 37 | /* Includes ------------------------------------------------------------------*/ |
Deepti | 0:9ac219c9a7df | 38 | #include "hts221.h" |
Deepti | 0:9ac219c9a7df | 39 | #include <math.h> |
Deepti | 0:9ac219c9a7df | 40 | |
Deepti | 0:9ac219c9a7df | 41 | /** @addtogroup BSP |
Deepti | 0:9ac219c9a7df | 42 | * @{ |
Deepti | 0:9ac219c9a7df | 43 | */ |
Deepti | 0:9ac219c9a7df | 44 | |
Deepti | 0:9ac219c9a7df | 45 | /** @addtogroup STM32F439_SENSITRON |
Deepti | 0:9ac219c9a7df | 46 | * @{ |
Deepti | 0:9ac219c9a7df | 47 | */ |
Deepti | 0:9ac219c9a7df | 48 | |
Deepti | 0:9ac219c9a7df | 49 | /** @addtogroup HTS221 |
Deepti | 0:9ac219c9a7df | 50 | * @{ |
Deepti | 0:9ac219c9a7df | 51 | */ |
Deepti | 0:9ac219c9a7df | 52 | |
Deepti | 0:9ac219c9a7df | 53 | |
Deepti | 0:9ac219c9a7df | 54 | /** @defgroup HTS221_Private_TypesDefinitions |
Deepti | 0:9ac219c9a7df | 55 | * @{ |
Deepti | 0:9ac219c9a7df | 56 | */ |
Deepti | 0:9ac219c9a7df | 57 | |
Deepti | 0:9ac219c9a7df | 58 | /** |
Deepti | 0:9ac219c9a7df | 59 | * @} |
Deepti | 0:9ac219c9a7df | 60 | */ |
Deepti | 0:9ac219c9a7df | 61 | |
Deepti | 0:9ac219c9a7df | 62 | /** @defgroup HTS221_Private_Defines |
Deepti | 0:9ac219c9a7df | 63 | * @{ |
Deepti | 0:9ac219c9a7df | 64 | */ |
Deepti | 0:9ac219c9a7df | 65 | |
Deepti | 0:9ac219c9a7df | 66 | /** |
Deepti | 0:9ac219c9a7df | 67 | * @} |
Deepti | 0:9ac219c9a7df | 68 | */ |
Deepti | 0:9ac219c9a7df | 69 | |
Deepti | 0:9ac219c9a7df | 70 | /** @defgroup HTS221_Private_Macros |
Deepti | 0:9ac219c9a7df | 71 | * @{ |
Deepti | 0:9ac219c9a7df | 72 | */ |
Deepti | 0:9ac219c9a7df | 73 | |
Deepti | 0:9ac219c9a7df | 74 | /** |
Deepti | 0:9ac219c9a7df | 75 | * @} |
Deepti | 0:9ac219c9a7df | 76 | */ |
Deepti | 0:9ac219c9a7df | 77 | |
Deepti | 0:9ac219c9a7df | 78 | /** @defgroup HTS221_Private_Variables |
Deepti | 0:9ac219c9a7df | 79 | * @{ |
Deepti | 0:9ac219c9a7df | 80 | */ |
Deepti | 0:9ac219c9a7df | 81 | |
Deepti | 0:9ac219c9a7df | 82 | HUM_TEMP_DrvTypeDef Hts221Drv = |
Deepti | 0:9ac219c9a7df | 83 | { |
Deepti | 0:9ac219c9a7df | 84 | HTS221_Init, |
Deepti | 0:9ac219c9a7df | 85 | HTS221_Power_OFF, |
Deepti | 0:9ac219c9a7df | 86 | HTS221_ReadID, |
Deepti | 0:9ac219c9a7df | 87 | HTS221_RebootCmd, |
Deepti | 0:9ac219c9a7df | 88 | HTS221_INT1InterruptConfig, |
Deepti | 0:9ac219c9a7df | 89 | HTS221_EnableIT, |
Deepti | 0:9ac219c9a7df | 90 | HTS221_DisableIT, |
Deepti | 0:9ac219c9a7df | 91 | HTS221_GetHumidity, |
Deepti | 0:9ac219c9a7df | 92 | HTS221_GetTemperature |
Deepti | 0:9ac219c9a7df | 93 | }; |
Deepti | 0:9ac219c9a7df | 94 | |
Deepti | 0:9ac219c9a7df | 95 | |
Deepti | 0:9ac219c9a7df | 96 | /* Temperature in degree for calibration */ |
Deepti | 0:9ac219c9a7df | 97 | float T0_degC, T1_degC; |
Deepti | 0:9ac219c9a7df | 98 | |
Deepti | 0:9ac219c9a7df | 99 | /* Output temperature value for calibration */ |
Deepti | 0:9ac219c9a7df | 100 | int16_t T0_out, T1_out; |
Deepti | 0:9ac219c9a7df | 101 | |
Deepti | 0:9ac219c9a7df | 102 | |
Deepti | 0:9ac219c9a7df | 103 | /* Humidity for calibration */ |
Deepti | 0:9ac219c9a7df | 104 | float H0_rh, H1_rh; |
Deepti | 0:9ac219c9a7df | 105 | |
Deepti | 0:9ac219c9a7df | 106 | /* Output Humidity value for calibration */ |
Deepti | 0:9ac219c9a7df | 107 | int16_t H0_T0_out, H1_T0_out; |
Deepti | 0:9ac219c9a7df | 108 | |
Deepti | 0:9ac219c9a7df | 109 | |
Deepti | 0:9ac219c9a7df | 110 | /** |
Deepti | 0:9ac219c9a7df | 111 | * @} |
Deepti | 0:9ac219c9a7df | 112 | */ |
Deepti | 0:9ac219c9a7df | 113 | |
Deepti | 0:9ac219c9a7df | 114 | /** @defgroup HTS221_Private_FunctionPrototypes |
Deepti | 0:9ac219c9a7df | 115 | * @{ |
Deepti | 0:9ac219c9a7df | 116 | */ |
Deepti | 0:9ac219c9a7df | 117 | static void HTS221_Power_On(void); |
Deepti | 0:9ac219c9a7df | 118 | |
Deepti | 0:9ac219c9a7df | 119 | static void HTS221_Calibration(void); |
Deepti | 0:9ac219c9a7df | 120 | /** |
Deepti | 0:9ac219c9a7df | 121 | * @} |
Deepti | 0:9ac219c9a7df | 122 | */ |
Deepti | 0:9ac219c9a7df | 123 | |
Deepti | 0:9ac219c9a7df | 124 | /** @defgroup HTS221_Private_Functions |
Deepti | 0:9ac219c9a7df | 125 | * @{ |
Deepti | 0:9ac219c9a7df | 126 | */ |
Deepti | 0:9ac219c9a7df | 127 | |
Deepti | 0:9ac219c9a7df | 128 | |
Deepti | 0:9ac219c9a7df | 129 | |
Deepti | 0:9ac219c9a7df | 130 | /** |
Deepti | 0:9ac219c9a7df | 131 | * @brief HTS221 Calibration procedure. |
Deepti | 0:9ac219c9a7df | 132 | * @param None |
Deepti | 0:9ac219c9a7df | 133 | * @retval None |
Deepti | 0:9ac219c9a7df | 134 | */ |
Deepti | 0:9ac219c9a7df | 135 | static void HTS221_Calibration(void) |
Deepti | 0:9ac219c9a7df | 136 | { |
Deepti | 0:9ac219c9a7df | 137 | /* Temperature Calibration */ |
Deepti | 0:9ac219c9a7df | 138 | /* Temperature in degree for calibration ( "/8" to obtain float) */ |
Deepti | 0:9ac219c9a7df | 139 | uint16_t T0_degC_x8_L, T0_degC_x8_H, T1_degC_x8_L, T1_degC_x8_H; |
Deepti | 0:9ac219c9a7df | 140 | uint8_t H0_rh_x2, H1_rh_x2; |
Deepti | 0:9ac219c9a7df | 141 | uint8_t tempReg[2] = {0,0}; |
Deepti | 0:9ac219c9a7df | 142 | |
Deepti | 0:9ac219c9a7df | 143 | HUM_TEMP_IO_Read(tempReg, HTS221_ADDRESS, HTS221_T0_degC_X8_ADDR, 1); |
Deepti | 0:9ac219c9a7df | 144 | T0_degC_x8_L = (uint16_t)tempReg[0]; |
Deepti | 0:9ac219c9a7df | 145 | |
Deepti | 0:9ac219c9a7df | 146 | HUM_TEMP_IO_Read(tempReg, HTS221_ADDRESS, HTS221_T1_T0_MSB_X8_ADDR, 1); |
Deepti | 0:9ac219c9a7df | 147 | T0_degC_x8_H = (uint16_t) (tempReg[0] & 0x03); |
Deepti | 0:9ac219c9a7df | 148 | |
Deepti | 0:9ac219c9a7df | 149 | T0_degC = ((float)((T0_degC_x8_H<<8) | (T0_degC_x8_L)))/8; |
Deepti | 0:9ac219c9a7df | 150 | |
Deepti | 0:9ac219c9a7df | 151 | HUM_TEMP_IO_Read(tempReg, HTS221_ADDRESS, HTS221_T1_degC_X8_ADDR, 1); |
Deepti | 0:9ac219c9a7df | 152 | T1_degC_x8_L = (uint16_t)tempReg[0]; |
Deepti | 0:9ac219c9a7df | 153 | |
Deepti | 0:9ac219c9a7df | 154 | HUM_TEMP_IO_Read(tempReg, HTS221_ADDRESS, HTS221_T1_T0_MSB_X8_ADDR, 1); |
Deepti | 0:9ac219c9a7df | 155 | T1_degC_x8_H = (uint16_t) (tempReg[0] & 0x0C); |
Deepti | 0:9ac219c9a7df | 156 | T1_degC_x8_H = T1_degC_x8_H >> 2; |
Deepti | 0:9ac219c9a7df | 157 | |
Deepti | 0:9ac219c9a7df | 158 | T1_degC = ((float)((T1_degC_x8_H<<8) | (T1_degC_x8_L)))/8; |
Deepti | 0:9ac219c9a7df | 159 | |
Deepti | 0:9ac219c9a7df | 160 | HUM_TEMP_IO_Read(tempReg, HTS221_ADDRESS, HTS221_T0_OUT_L_ADDR + 0x80, 2); |
Deepti | 0:9ac219c9a7df | 161 | T0_out = ((((int16_t)tempReg[1]) << 8)+(int16_t)tempReg[0]); |
Deepti | 0:9ac219c9a7df | 162 | |
Deepti | 0:9ac219c9a7df | 163 | HUM_TEMP_IO_Read(tempReg, HTS221_ADDRESS, HTS221_T1_OUT_L_ADDR + 0x80, 2); |
Deepti | 0:9ac219c9a7df | 164 | T1_out = ((((int16_t)tempReg[1]) << 8)+(int16_t)tempReg[0]); |
Deepti | 0:9ac219c9a7df | 165 | |
Deepti | 0:9ac219c9a7df | 166 | /* Humidity Calibration */ |
Deepti | 0:9ac219c9a7df | 167 | /* Humidity in degree for calibration ( "/2" to obtain float) */ |
Deepti | 0:9ac219c9a7df | 168 | |
Deepti | 0:9ac219c9a7df | 169 | HUM_TEMP_IO_Read(&H0_rh_x2, HTS221_ADDRESS, HTS221_H0_RH_X2_ADDR, 1); |
Deepti | 0:9ac219c9a7df | 170 | |
Deepti | 0:9ac219c9a7df | 171 | HUM_TEMP_IO_Read(&H1_rh_x2, HTS221_ADDRESS, HTS221_H1_RH_X2_ADDR, 1); |
Deepti | 0:9ac219c9a7df | 172 | |
Deepti | 0:9ac219c9a7df | 173 | HUM_TEMP_IO_Read(&tempReg[0], HTS221_ADDRESS, HTS221_H0_T0_OUT_L_ADDR + 0x80, 2); |
Deepti | 0:9ac219c9a7df | 174 | H0_T0_out = ((((int16_t)tempReg[1]) << 8)+(int16_t)tempReg[0]); |
Deepti | 0:9ac219c9a7df | 175 | |
Deepti | 0:9ac219c9a7df | 176 | HUM_TEMP_IO_Read(&tempReg[0], HTS221_ADDRESS, HTS221_H1_T0_OUT_L_ADDR + 0x80, 2); |
Deepti | 0:9ac219c9a7df | 177 | H1_T0_out = ((((int16_t)tempReg[1]) << 8)+(int16_t)tempReg[0]); |
Deepti | 0:9ac219c9a7df | 178 | |
Deepti | 0:9ac219c9a7df | 179 | H0_rh = ((float)H0_rh_x2)/2; |
Deepti | 0:9ac219c9a7df | 180 | H1_rh = ((float)H1_rh_x2)/2; |
Deepti | 0:9ac219c9a7df | 181 | } |
Deepti | 0:9ac219c9a7df | 182 | |
Deepti | 0:9ac219c9a7df | 183 | |
Deepti | 0:9ac219c9a7df | 184 | /** |
Deepti | 0:9ac219c9a7df | 185 | * @brief Set HTS221 Initialization. |
Deepti | 0:9ac219c9a7df | 186 | * @param InitStruct: it contains the configuration setting for the HTS221. |
Deepti | 0:9ac219c9a7df | 187 | * @retval None |
Deepti | 0:9ac219c9a7df | 188 | */ |
Deepti | 0:9ac219c9a7df | 189 | void HTS221_Init(HUM_TEMP_InitTypeDef *HTS221_Init) |
Deepti | 0:9ac219c9a7df | 190 | { |
Deepti | 0:9ac219c9a7df | 191 | uint8_t tmp = 0x00; |
Deepti | 0:9ac219c9a7df | 192 | |
Deepti | 0:9ac219c9a7df | 193 | /* Configure the low level interface ---------------------------------------*/ |
Deepti | 0:9ac219c9a7df | 194 | HUM_TEMP_IO_Init(); |
Deepti | 0:9ac219c9a7df | 195 | |
Deepti | 0:9ac219c9a7df | 196 | HTS221_Power_On(); |
Deepti | 0:9ac219c9a7df | 197 | |
Deepti | 0:9ac219c9a7df | 198 | HTS221_Calibration(); |
Deepti | 0:9ac219c9a7df | 199 | |
Deepti | 0:9ac219c9a7df | 200 | HUM_TEMP_IO_Read(&tmp, HTS221_ADDRESS, HTS221_CTRL_REG1_ADDR, 1); |
Deepti | 0:9ac219c9a7df | 201 | |
Deepti | 0:9ac219c9a7df | 202 | /* Output Data Rate selection */ |
Deepti | 0:9ac219c9a7df | 203 | tmp &= ~(HTS221_ODR_MASK); |
Deepti | 0:9ac219c9a7df | 204 | tmp |= HTS221_Init->OutputDataRate; |
Deepti | 0:9ac219c9a7df | 205 | |
Deepti | 0:9ac219c9a7df | 206 | HUM_TEMP_IO_Write(&tmp, HTS221_ADDRESS, HTS221_CTRL_REG1_ADDR, 1); |
Deepti | 0:9ac219c9a7df | 207 | } |
Deepti | 0:9ac219c9a7df | 208 | |
Deepti | 0:9ac219c9a7df | 209 | /** |
Deepti | 0:9ac219c9a7df | 210 | * @brief Read ID address of HTS221 |
Deepti | 0:9ac219c9a7df | 211 | * @param Device ID address |
Deepti | 0:9ac219c9a7df | 212 | * @retval ID name |
Deepti | 0:9ac219c9a7df | 213 | */ |
Deepti | 0:9ac219c9a7df | 214 | uint8_t HTS221_ReadID(void) |
Deepti | 0:9ac219c9a7df | 215 | { |
Deepti | 0:9ac219c9a7df | 216 | uint8_t tmp; |
Deepti | 0:9ac219c9a7df | 217 | |
Deepti | 0:9ac219c9a7df | 218 | /* Read WHO I AM register */ |
Deepti | 0:9ac219c9a7df | 219 | HUM_TEMP_IO_Read(&tmp, HTS221_ADDRESS, HTS221_WHO_AM_I_ADDR, 1); |
Deepti | 0:9ac219c9a7df | 220 | |
Deepti | 0:9ac219c9a7df | 221 | /* Return the ID */ |
Deepti | 0:9ac219c9a7df | 222 | return (uint8_t)tmp; |
Deepti | 0:9ac219c9a7df | 223 | } |
Deepti | 0:9ac219c9a7df | 224 | |
Deepti | 0:9ac219c9a7df | 225 | /** |
Deepti | 0:9ac219c9a7df | 226 | * @brief Reboot memory content of HTS221 |
Deepti | 0:9ac219c9a7df | 227 | * @param None |
Deepti | 0:9ac219c9a7df | 228 | * @retval None |
Deepti | 0:9ac219c9a7df | 229 | */ |
Deepti | 0:9ac219c9a7df | 230 | void HTS221_RebootCmd(void) |
Deepti | 0:9ac219c9a7df | 231 | { |
Deepti | 0:9ac219c9a7df | 232 | uint8_t tmpreg; |
Deepti | 0:9ac219c9a7df | 233 | |
Deepti | 0:9ac219c9a7df | 234 | /* Read CTRL_REG2 register */ |
Deepti | 0:9ac219c9a7df | 235 | HUM_TEMP_IO_Read(&tmpreg, HTS221_ADDRESS, HTS221_CTRL_REG2_ADDR, 1); |
Deepti | 0:9ac219c9a7df | 236 | |
Deepti | 0:9ac219c9a7df | 237 | /* Enable or Disable the reboot memory */ |
Deepti | 0:9ac219c9a7df | 238 | tmpreg |= HTS221_BOOT_REBOOTMEMORY; |
Deepti | 0:9ac219c9a7df | 239 | |
Deepti | 0:9ac219c9a7df | 240 | /* Write value to MEMS CTRL_REG2 regsister */ |
Deepti | 0:9ac219c9a7df | 241 | HUM_TEMP_IO_Write(&tmpreg, HTS221_ADDRESS, HTS221_CTRL_REG2_ADDR, 1); |
Deepti | 0:9ac219c9a7df | 242 | } |
Deepti | 0:9ac219c9a7df | 243 | |
Deepti | 0:9ac219c9a7df | 244 | /** |
Deepti | 0:9ac219c9a7df | 245 | * @brief Set HTS221 Interrupt INT1 configuration |
Deepti | 0:9ac219c9a7df | 246 | * @param HTS221_InterruptConfig_TypeDef: pointer to a HTS221_InterruptConfig_TypeDef |
Deepti | 0:9ac219c9a7df | 247 | * structure that contains the configuration setting for the HTS221 Interrupt. |
Deepti | 0:9ac219c9a7df | 248 | * @retval None |
Deepti | 0:9ac219c9a7df | 249 | */ |
Deepti | 0:9ac219c9a7df | 250 | void HTS221_INT1InterruptConfig(uint16_t Int1Config) |
Deepti | 0:9ac219c9a7df | 251 | { |
Deepti | 0:9ac219c9a7df | 252 | |
Deepti | 0:9ac219c9a7df | 253 | } |
Deepti | 0:9ac219c9a7df | 254 | |
Deepti | 0:9ac219c9a7df | 255 | /** |
Deepti | 0:9ac219c9a7df | 256 | * @brief Enable INT1 |
Deepti | 0:9ac219c9a7df | 257 | * @retval None |
Deepti | 0:9ac219c9a7df | 258 | */ |
Deepti | 0:9ac219c9a7df | 259 | void HTS221_EnableIT(uint8_t IntPin) |
Deepti | 0:9ac219c9a7df | 260 | { |
Deepti | 0:9ac219c9a7df | 261 | |
Deepti | 0:9ac219c9a7df | 262 | } |
Deepti | 0:9ac219c9a7df | 263 | |
Deepti | 0:9ac219c9a7df | 264 | /** |
Deepti | 0:9ac219c9a7df | 265 | * @brief Disable INT1 |
Deepti | 0:9ac219c9a7df | 266 | * @retval None |
Deepti | 0:9ac219c9a7df | 267 | */ |
Deepti | 0:9ac219c9a7df | 268 | void HTS221_DisableIT(uint8_t IntPin) |
Deepti | 0:9ac219c9a7df | 269 | { |
Deepti | 0:9ac219c9a7df | 270 | |
Deepti | 0:9ac219c9a7df | 271 | } |
Deepti | 0:9ac219c9a7df | 272 | |
Deepti | 0:9ac219c9a7df | 273 | |
Deepti | 0:9ac219c9a7df | 274 | /** |
Deepti | 0:9ac219c9a7df | 275 | * @brief Read HTS221 output register, and calculate the humidity. |
Deepti | 0:9ac219c9a7df | 276 | * @param pfData : Data out pointer |
Deepti | 0:9ac219c9a7df | 277 | * @retval None |
Deepti | 0:9ac219c9a7df | 278 | */ |
Deepti | 0:9ac219c9a7df | 279 | void HTS221_GetHumidity(float* pfData) |
Deepti | 0:9ac219c9a7df | 280 | { |
Deepti | 0:9ac219c9a7df | 281 | int16_t H_T_out, humidity_t; |
Deepti | 0:9ac219c9a7df | 282 | uint8_t tempReg[2] = {0,0}; |
Deepti | 0:9ac219c9a7df | 283 | uint8_t tmp = 0x00; |
Deepti | 0:9ac219c9a7df | 284 | float H_rh; |
Deepti | 0:9ac219c9a7df | 285 | |
Deepti | 0:9ac219c9a7df | 286 | HUM_TEMP_IO_Read(&tmp, HTS221_ADDRESS, HTS221_CTRL_REG1_ADDR, 1); |
Deepti | 0:9ac219c9a7df | 287 | |
Deepti | 0:9ac219c9a7df | 288 | /* Output Data Rate selection */ |
Deepti | 0:9ac219c9a7df | 289 | tmp &= (HTS221_ODR_MASK); |
Deepti | 0:9ac219c9a7df | 290 | |
Deepti | 0:9ac219c9a7df | 291 | if(tmp == 0x00){ |
Deepti | 0:9ac219c9a7df | 292 | |
Deepti | 0:9ac219c9a7df | 293 | HUM_TEMP_IO_Read(&tmp, HTS221_ADDRESS, HTS221_CTRL_REG2_ADDR, 1); |
Deepti | 0:9ac219c9a7df | 294 | |
Deepti | 0:9ac219c9a7df | 295 | /* Serial Interface Mode selection */ |
Deepti | 0:9ac219c9a7df | 296 | tmp &= ~(HTS221_ONE_SHOT_MASK); |
Deepti | 0:9ac219c9a7df | 297 | tmp |= HTS221_ONE_SHOT_START; |
Deepti | 0:9ac219c9a7df | 298 | |
Deepti | 0:9ac219c9a7df | 299 | HUM_TEMP_IO_Write(&tmp, HTS221_ADDRESS, HTS221_CTRL_REG2_ADDR, 1); |
Deepti | 0:9ac219c9a7df | 300 | |
Deepti | 0:9ac219c9a7df | 301 | do{ |
Deepti | 0:9ac219c9a7df | 302 | |
Deepti | 0:9ac219c9a7df | 303 | HUM_TEMP_IO_Read(&tmp, HTS221_ADDRESS, HTS221_STATUS_REG_ADDR, 1); |
Deepti | 0:9ac219c9a7df | 304 | |
Deepti | 0:9ac219c9a7df | 305 | }while(!(tmp&&0x02)); |
Deepti | 0:9ac219c9a7df | 306 | |
Deepti | 0:9ac219c9a7df | 307 | } |
Deepti | 0:9ac219c9a7df | 308 | |
Deepti | 0:9ac219c9a7df | 309 | |
Deepti | 0:9ac219c9a7df | 310 | HUM_TEMP_IO_Read(&tempReg[0], HTS221_ADDRESS, HTS221_HUMIDITY_OUT_L_ADDR + 0x80, 2); |
Deepti | 0:9ac219c9a7df | 311 | H_T_out = ((((int16_t)tempReg[1]) << 8)+(int16_t)tempReg[0]); |
Deepti | 0:9ac219c9a7df | 312 | |
Deepti | 0:9ac219c9a7df | 313 | H_rh = ((float)(H_T_out - H0_T0_out))/(H1_T0_out - H0_T0_out) * (H1_rh - H0_rh) + H0_rh; |
Deepti | 0:9ac219c9a7df | 314 | |
Deepti | 0:9ac219c9a7df | 315 | humidity_t = (uint16_t)(H_rh * pow(10,HUM_DECIMAL_DIGITS)); |
Deepti | 0:9ac219c9a7df | 316 | |
Deepti | 0:9ac219c9a7df | 317 | *pfData = ((float)humidity_t)/pow(10,HUM_DECIMAL_DIGITS); |
Deepti | 0:9ac219c9a7df | 318 | } |
Deepti | 0:9ac219c9a7df | 319 | |
Deepti | 0:9ac219c9a7df | 320 | /** |
Deepti | 0:9ac219c9a7df | 321 | * @brief Read HTS221 output register, and calculate the temperature. |
Deepti | 0:9ac219c9a7df | 322 | * @param pfData : Data out pointer |
Deepti | 0:9ac219c9a7df | 323 | * @retval None |
Deepti | 0:9ac219c9a7df | 324 | */ |
Deepti | 0:9ac219c9a7df | 325 | void HTS221_GetTemperature(float* pfData) |
Deepti | 0:9ac219c9a7df | 326 | { |
Deepti | 0:9ac219c9a7df | 327 | int16_t T_out, temperature_t; |
Deepti | 0:9ac219c9a7df | 328 | uint8_t tempReg[2] = {0,0}; |
Deepti | 0:9ac219c9a7df | 329 | uint8_t tmp = 0x00; |
Deepti | 0:9ac219c9a7df | 330 | float T_degC; |
Deepti | 0:9ac219c9a7df | 331 | |
Deepti | 0:9ac219c9a7df | 332 | HUM_TEMP_IO_Read(&tmp, HTS221_ADDRESS, HTS221_CTRL_REG1_ADDR, 1); |
Deepti | 0:9ac219c9a7df | 333 | |
Deepti | 0:9ac219c9a7df | 334 | /* Output Data Rate selection */ |
Deepti | 0:9ac219c9a7df | 335 | tmp &= (HTS221_ODR_MASK); |
Deepti | 0:9ac219c9a7df | 336 | |
Deepti | 0:9ac219c9a7df | 337 | if(tmp == 0x00){ |
Deepti | 0:9ac219c9a7df | 338 | |
Deepti | 0:9ac219c9a7df | 339 | HUM_TEMP_IO_Read(&tmp, HTS221_ADDRESS, HTS221_CTRL_REG2_ADDR, 1); |
Deepti | 0:9ac219c9a7df | 340 | |
Deepti | 0:9ac219c9a7df | 341 | /* Serial Interface Mode selection */ |
Deepti | 0:9ac219c9a7df | 342 | tmp &= ~(HTS221_ONE_SHOT_MASK); |
Deepti | 0:9ac219c9a7df | 343 | tmp |= HTS221_ONE_SHOT_START; |
Deepti | 0:9ac219c9a7df | 344 | |
Deepti | 0:9ac219c9a7df | 345 | HUM_TEMP_IO_Write(&tmp, HTS221_ADDRESS, HTS221_CTRL_REG2_ADDR, 1); |
Deepti | 0:9ac219c9a7df | 346 | |
Deepti | 0:9ac219c9a7df | 347 | do{ |
Deepti | 0:9ac219c9a7df | 348 | |
Deepti | 0:9ac219c9a7df | 349 | HUM_TEMP_IO_Read(&tmp, HTS221_ADDRESS, HTS221_STATUS_REG_ADDR, 1); |
Deepti | 0:9ac219c9a7df | 350 | |
Deepti | 0:9ac219c9a7df | 351 | }while(!(tmp&&0x01)); |
Deepti | 0:9ac219c9a7df | 352 | |
Deepti | 0:9ac219c9a7df | 353 | } |
Deepti | 0:9ac219c9a7df | 354 | |
Deepti | 0:9ac219c9a7df | 355 | HUM_TEMP_IO_Read(&tempReg[0], HTS221_ADDRESS, HTS221_TEMP_OUT_L_ADDR + 0x80, 2); |
Deepti | 0:9ac219c9a7df | 356 | T_out = ((((int16_t)tempReg[1]) << 8)+(int16_t)tempReg[0]); |
Deepti | 0:9ac219c9a7df | 357 | |
Deepti | 0:9ac219c9a7df | 358 | T_degC = ((float)(T_out - T0_out))/(T1_out - T0_out) * (T1_degC - T0_degC) + T0_degC; |
Deepti | 0:9ac219c9a7df | 359 | |
Deepti | 0:9ac219c9a7df | 360 | temperature_t = (int16_t)(T_degC * pow(10,TEMP_DECIMAL_DIGITS)); |
Deepti | 0:9ac219c9a7df | 361 | |
Deepti | 0:9ac219c9a7df | 362 | *pfData = ((float)temperature_t)/pow(10,TEMP_DECIMAL_DIGITS); |
Deepti | 0:9ac219c9a7df | 363 | } |
Deepti | 0:9ac219c9a7df | 364 | |
Deepti | 0:9ac219c9a7df | 365 | |
Deepti | 0:9ac219c9a7df | 366 | /** |
Deepti | 0:9ac219c9a7df | 367 | * @brief Exit the shutdown mode for HTS221. |
Deepti | 0:9ac219c9a7df | 368 | * @retval None |
Deepti | 0:9ac219c9a7df | 369 | */ |
Deepti | 0:9ac219c9a7df | 370 | static void HTS221_Power_On() |
Deepti | 0:9ac219c9a7df | 371 | { |
Deepti | 0:9ac219c9a7df | 372 | uint8_t tmpReg; |
Deepti | 0:9ac219c9a7df | 373 | |
Deepti | 0:9ac219c9a7df | 374 | /* Read the register content */ |
Deepti | 0:9ac219c9a7df | 375 | HUM_TEMP_IO_Read(&tmpReg, HTS221_ADDRESS, HTS221_CTRL_REG1_ADDR, 1); |
Deepti | 0:9ac219c9a7df | 376 | |
Deepti | 0:9ac219c9a7df | 377 | /* Set the power down bit */ |
Deepti | 0:9ac219c9a7df | 378 | tmpReg |= HTS221_MODE_ACTIVE; |
Deepti | 0:9ac219c9a7df | 379 | |
Deepti | 0:9ac219c9a7df | 380 | /* Write register */ |
Deepti | 0:9ac219c9a7df | 381 | HUM_TEMP_IO_Write(&tmpReg, HTS221_ADDRESS, HTS221_CTRL_REG1_ADDR, 1); |
Deepti | 0:9ac219c9a7df | 382 | } |
Deepti | 0:9ac219c9a7df | 383 | |
Deepti | 0:9ac219c9a7df | 384 | /** |
Deepti | 0:9ac219c9a7df | 385 | * @brief Enter the shutdown mode for HTS221. |
Deepti | 0:9ac219c9a7df | 386 | * @retval None |
Deepti | 0:9ac219c9a7df | 387 | */ |
Deepti | 0:9ac219c9a7df | 388 | void HTS221_Power_OFF() |
Deepti | 0:9ac219c9a7df | 389 | { |
Deepti | 0:9ac219c9a7df | 390 | uint8_t tmpReg; |
Deepti | 0:9ac219c9a7df | 391 | |
Deepti | 0:9ac219c9a7df | 392 | /* Read the register content */ |
Deepti | 0:9ac219c9a7df | 393 | HUM_TEMP_IO_Read(&tmpReg, HTS221_ADDRESS, HTS221_CTRL_REG1_ADDR, 1); |
Deepti | 0:9ac219c9a7df | 394 | |
Deepti | 0:9ac219c9a7df | 395 | /* Reset the power down bit */ |
Deepti | 0:9ac219c9a7df | 396 | tmpReg &= ~(HTS221_MODE_ACTIVE); |
Deepti | 0:9ac219c9a7df | 397 | |
Deepti | 0:9ac219c9a7df | 398 | /* Write register */ |
Deepti | 0:9ac219c9a7df | 399 | HUM_TEMP_IO_Write(&tmpReg, HTS221_ADDRESS, HTS221_CTRL_REG1_ADDR, 1); |
Deepti | 0:9ac219c9a7df | 400 | } |
Deepti | 0:9ac219c9a7df | 401 | |
Deepti | 0:9ac219c9a7df | 402 | /** |
Deepti | 0:9ac219c9a7df | 403 | * @} |
Deepti | 0:9ac219c9a7df | 404 | */ |
Deepti | 0:9ac219c9a7df | 405 | |
Deepti | 0:9ac219c9a7df | 406 | /** |
Deepti | 0:9ac219c9a7df | 407 | * @} |
Deepti | 0:9ac219c9a7df | 408 | */ |
Deepti | 0:9ac219c9a7df | 409 | |
Deepti | 0:9ac219c9a7df | 410 | /** |
Deepti | 0:9ac219c9a7df | 411 | * @} |
Deepti | 0:9ac219c9a7df | 412 | */ |
Deepti | 0:9ac219c9a7df | 413 | |
Deepti | 0:9ac219c9a7df | 414 | /** |
Deepti | 0:9ac219c9a7df | 415 | * @} |
Deepti | 0:9ac219c9a7df | 416 | */ |
Deepti | 0:9ac219c9a7df | 417 | |
Deepti | 0:9ac219c9a7df | 418 | |
Deepti | 0:9ac219c9a7df | 419 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
Deepti | 0:9ac219c9a7df | 420 |