Environmental_Shield_F4_API

Dependencies:   mbed

Fork of Environmental_sheild_F4 by Sumit Johar

Committer:
Deepti
Date:
Thu Aug 14 05:25:37 2014 +0000
Revision:
2:e88266f73a67
Parent:
0:c3c9b1c8e3cb
Environmental_Shield_F4_API

Who changed what in which revision?

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