ble

Dependencies:   HC_SR04_Ultrasonic_Library Servo mbed

Fork of FIP_REV1 by Robotique FIP

Committer:
julientiron
Date:
Thu Jul 09 13:33:36 2015 +0000
Revision:
4:69a35a56ac48
Parent:
1:bdbf36f8408d
BLE

Who changed what in which revision?

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