Farnell-Element14 Bologna IOT Team / BSP_B-L475E-IOT01

Dependencies:   VL53L0X

Fork of BSP_B-L475E-IOT01 by ST

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers hts221.h Source File

hts221.h

Go to the documentation of this file.
00001 /**
00002  ******************************************************************************
00003  * @file    hts221.h
00004  * @author  MCD Application Team
00005  * @version V1.0.0
00006  * @date    14-February-2017
00007  * @brief   HTS221 header driver file
00008  ******************************************************************************
00009  * @attention
00010  *
00011  * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
00012  *
00013  * Redistribution and use in source and binary forms, with or without modification,
00014  * are permitted provided that the following conditions are met:
00015  *   1. Redistributions of source code must retain the above copyright notice,
00016  *      this list of conditions and the following disclaimer.
00017  *   2. Redistributions in binary form must reproduce the above copyright notice,
00018  *      this list of conditions and the following disclaimer in the documentation
00019  *      and/or other materials provided with the distribution.
00020  *   3. Neither the name of STMicroelectronics nor the names of its contributors
00021  *      may be used to endorse or promote products derived from this software
00022  *      without specific prior written permission.
00023  *
00024  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00025  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00026  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00027  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
00028  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00029  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00030  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00031  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00032  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00033  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00034  *
00035  ******************************************************************************
00036  */
00037 
00038 /* Define to prevent recursive inclusion -------------------------------------*/
00039 #ifndef __HTS221__H
00040 #define __HTS221__H
00041 
00042 #ifdef __cplusplus
00043 extern "C" {
00044 #endif
00045   
00046 /* Includes ------------------------------------------------------------------*/
00047 #include "../Common/hsensor.h"
00048 #include "../Common/tsensor.h"  
00049 
00050 /** @addtogroup BSP
00051   * @{
00052   */
00053 
00054 /** @addtogroup Component
00055   * @{
00056   */
00057 
00058 /** @addtogroup HTS221 
00059   * @{
00060   */
00061 
00062 /** @defgroup HTS221_Exported_Constants HTS221 Exported Constants
00063   * @{
00064   */
00065 
00066 /**
00067   * @brief  Bitfield positioning.
00068   */
00069 #define HTS221_BIT(x) ((uint8_t)x)
00070 
00071 
00072 /**
00073   * @brief Device Identification register.
00074   *        Read
00075   *        Default value: 0xBC
00076   *        7:0 This read-only register contains the device identifier for HTS221.
00077   */
00078 #define HTS221_WHO_AM_I_REG          (uint8_t)0x0F
00079 
00080 /**
00081   * @brief Device Identification value.
00082   */
00083 #define HTS221_WHO_AM_I_VAL         (uint8_t)0xBC
00084 
00085 
00086 /**
00087   * @brief Humidity and temperature average mode register.
00088   *        Read/write
00089   *        Default value: 0x1B
00090   *        7:6 Reserved.
00091   *        5:3 AVGT2-AVGT1-AVGT0: Select the temperature internal average.
00092   *        
00093   *             AVGT2 | AVGT1 | AVGT0 | Nr. Internal Average
00094   *          ----------------------------------------------------
00095   *              0    |   0   |   0   |    2
00096   *              0    |   0   |   1   |    4
00097   *              0    |   1   |   0   |    8
00098   *              0    |   1   |   1   |    16
00099   *              1    |   0   |   0   |    32
00100   *              1    |   0   |   1   |    64
00101   *              1    |   1   |   0   |    128
00102   *              1    |   1   |   1   |    256
00103   *        
00104   *        2:0 AVGH2-AVGH1-AVGH0: Select humidity internal average.
00105   *             AVGH2 | AVGH1 |  AVGH0 | Nr. Internal Average
00106   *          ------------------------------------------------------
00107   *              0    |   0   |   0   |    4
00108   *              0    |   0   |   1   |    8
00109   *              0    |   1   |   0   |    16
00110   *              0    |   1   |   1   |    32
00111   *              1    |   0   |   0   |    64
00112   *              1    |   0   |   1   |    128
00113   *              1    |   1   |   0   |    256
00114   *              1    |   1   |   1   |    512
00115   *
00116   */
00117 #define HTS221_AV_CONF_REG        (uint8_t)0x10
00118 
00119 #define HTS221_AVGT_BIT           HTS221_BIT(3)
00120 #define HTS221_AVGH_BIT           HTS221_BIT(0)
00121 
00122 #define HTS221_AVGH_MASK          (uint8_t)0x07
00123 #define HTS221_AVGT_MASK          (uint8_t)0x38
00124 
00125 /**
00126   * @brief Control register 1.
00127   *        Read/write
00128   *        Default value: 0x00
00129   *        7 PD: power down control. 0 - power down mode; 1 - active mode.
00130   *        6:3 Reserved.
00131   *        2 BDU: block data update. 0 - continuous update
00132   *                                  1 - output registers not updated until MSB and LSB reading.
00133   *        1:0 ODR1, ODR0: output data rate selection.
00134   *       
00135   *          ODR1  | ODR0  | Humidity output data-rate(Hz)  | Pressure output data-rate(Hz)
00136   *          ----------------------------------------------------------------------------------
00137   *            0   |   0   |         one shot               |         one shot
00138   *            0   |   1   |            1                   |            1
00139   *            1   |   0   |            7                   |            7
00140   *            1   |   1   |           12.5                 |           12.5
00141   *       
00142   */
00143 #define HTS221_CTRL_REG1      (uint8_t)0x20
00144 
00145 #define HTS221_PD_BIT          HTS221_BIT(7)
00146 #define HTS221_BDU_BIT         HTS221_BIT(2)
00147 #define HTS221_ODR_BIT         HTS221_BIT(0)
00148 
00149 #define HTS221_PD_MASK        (uint8_t)0x80
00150 #define HTS221_BDU_MASK       (uint8_t)0x04
00151 #define HTS221_ODR_MASK       (uint8_t)0x03
00152 
00153 /**
00154   * @brief Control register 2.
00155   *        Read/write
00156   *        Default value: 0x00
00157   *        7 BOOT:  Reboot memory content. 0: normal mode 
00158   *                                        1: reboot memory content. Self-cleared upon completation.
00159   *        6:2 Reserved.
00160   *        1 HEATHER: 0: heater enable; 1: heater disable.
00161   *        0 ONE_SHOT: 0: waiting for start of conversion 
00162   *                    1: start for a new dataset. Self-cleared upon completation.
00163   */
00164 #define HTS221_CTRL_REG2      (uint8_t)0x21
00165 
00166 #define HTS221_BOOT_BIT        HTS221_BIT(7)
00167 #define HTS221_HEATHER_BIT     HTS221_BIT(1)
00168 #define HTS221_ONESHOT_BIT     HTS221_BIT(0)
00169 
00170 #define HTS221_BOOT_MASK      (uint8_t)0x80
00171 #define HTS221_HEATHER_MASK   (uint8_t)0x02
00172 #define HTS221_ONE_SHOT_MASK  (uint8_t)0x01
00173 
00174 /**
00175   * @brief Control register 3.
00176   *        Read/write
00177   *        Default value: 0x00
00178   *        7 DRDY_H_L: Interrupt edge. 0: active high, 1: active low.
00179   *        6 PP_OD: Push-Pull/OpenDrain selection on interrupt pads. 0: push-pull 
00180   *                                                                  1: open drain.
00181   *        5:3 Reserved.
00182   *        2 DRDY: interrupt config. 0: disable, 1: enable.
00183   */
00184 #define HTS221_CTRL_REG3      (uint8_t)0x22
00185 
00186 #define HTS221_DRDY_H_L_BIT    HTS221_BIT(7)
00187 #define HTS221_PP_OD_BIT       HTS221_BIT(6)
00188 #define HTS221_DRDY_BIT        HTS221_BIT(2)
00189 
00190 #define HTS221_DRDY_H_L_MASK  (uint8_t)0x80
00191 #define HTS221_PP_OD_MASK     (uint8_t)0x40
00192 #define HTS221_DRDY_MASK      (uint8_t)0x04
00193 
00194 /**
00195   * @brief  Status register.
00196   *         Read
00197   *         Default value: 0x00
00198   *         7:2 Reserved.
00199   *         1 H_DA: Humidity data available. 0: new data for humidity is not yet available 
00200   *                                          1: new data for humidity is available.
00201   *         0 T_DA: Temperature data available. 0: new data for temperature is not yet available
00202   *                                             1: new data for temperature is available.
00203   */
00204 #define HTS221_STATUS_REG    (uint8_t)0x27
00205 
00206 #define HTS221_H_DA_BIT       HTS221_BIT(1)
00207 #define HTS221_T_DA_BIT       HTS221_BIT(0)
00208 
00209 #define HTS221_HDA_MASK      (uint8_t)0x02
00210 #define HTS221_TDA_MASK      (uint8_t)0x01
00211 
00212 /**
00213   * @brief  Humidity data (LSB).
00214   *         Read
00215   *         Default value: 0x00.
00216   *         HOUT7 - HOUT0: Humidity data LSB (2's complement).
00217   */
00218 #define HTS221_HR_OUT_L_REG        (uint8_t)0x28
00219 
00220 /**
00221   * @brief  Humidity data (MSB).
00222   *         Read
00223   *         Default value: 0x00.
00224   *         HOUT15 - HOUT8: Humidity data MSB (2's complement).
00225   */
00226 #define HTS221_HR_OUT_H_REG        (uint8_t)0x29
00227 
00228 /**
00229   * @brief  Temperature data (LSB).
00230   *         Read
00231   *         Default value: 0x00.
00232   *         TOUT7 - TOUT0: temperature data LSB.
00233   */
00234 #define HTS221_TEMP_OUT_L_REG         (uint8_t)0x2A
00235 
00236 /**
00237   * @brief  Temperature data (MSB).
00238   *         Read
00239   *         Default value: 0x00.
00240   *         TOUT15 - TOUT8: temperature data MSB.
00241   */
00242 #define HTS221_TEMP_OUT_H_REG         (uint8_t)0x2B
00243 
00244 /**
00245   * @brief  Calibration registers.
00246   * Read
00247   */
00248 #define HTS221_H0_RH_X2        (uint8_t)0x30
00249 #define HTS221_H1_RH_X2        (uint8_t)0x31
00250 #define HTS221_T0_DEGC_X8      (uint8_t)0x32
00251 #define HTS221_T1_DEGC_X8      (uint8_t)0x33
00252 #define HTS221_T0_T1_DEGC_H2   (uint8_t)0x35
00253 #define HTS221_H0_T0_OUT_L     (uint8_t)0x36
00254 #define HTS221_H0_T0_OUT_H     (uint8_t)0x37
00255 #define HTS221_H1_T0_OUT_L     (uint8_t)0x3A
00256 #define HTS221_H1_T0_OUT_H     (uint8_t)0x3B
00257 #define HTS221_T0_OUT_L        (uint8_t)0x3C
00258 #define HTS221_T0_OUT_H        (uint8_t)0x3D
00259 #define HTS221_T1_OUT_L        (uint8_t)0x3E
00260 #define HTS221_T1_OUT_H        (uint8_t)0x3F
00261 
00262 /**
00263 * @}
00264 */
00265 
00266 
00267 /** @defgroup HTS221_Humidity_Exported_Functions HTS221 Humidity Exported Functions
00268   * @{
00269   */  
00270 /* HUMIDITY functions */
00271 void HTS221_H_Init(uint16_t DeviceAddr);
00272 uint8_t HTS221_H_ReadID(uint16_t DeviceAddr);
00273 float HTS221_H_ReadHumidity(uint16_t DeviceAddr);
00274 /**
00275   * @}
00276   */
00277 
00278 /** @defgroup HTS221_HumImported_Globals  Humidity Imported Globals
00279   * @{
00280   */
00281 /* Humidity driver structure */
00282 extern HSENSOR_DrvTypeDef HTS221_H_Drv;
00283 /**
00284   * @}
00285   */
00286 
00287 /** @defgroup HTS221_Temperature_Exported_Functions HTS221 Temperature Exported Functions
00288   * @{
00289   */
00290 /* TEMPERATURE functions */
00291 void HTS221_T_Init(uint16_t DeviceAddr, TSENSOR_InitTypeDef *pInitStruct);
00292 float HTS221_T_ReadTemp(uint16_t DeviceAddr);
00293 /**
00294   * @}
00295   */
00296   
00297 /** @defgroup HTS221_TempImported_Globals  Temperature Imported Globals
00298   * @{
00299   */
00300 /* Temperature driver structure */
00301 extern TSENSOR_DrvTypeDef HTS221_T_Drv;
00302 
00303 /**
00304   * @}
00305   */
00306 
00307 /** @defgroup HTS221_Imported_Functions HTS221 Imported Functions
00308   * @{
00309   */
00310 /* IO functions */
00311 extern void     SENSOR_IO_Init(void);
00312 extern void     SENSOR_IO_Write(uint8_t Addr, uint8_t Reg, uint8_t Value);
00313 extern uint8_t  SENSOR_IO_Read(uint8_t Addr, uint8_t Reg);
00314 extern uint16_t SENSOR_IO_ReadMultiple(uint8_t Addr, uint8_t Reg, uint8_t *Buffer, uint16_t Length);
00315 extern void     SENSOR_IO_WriteMultiple(uint8_t Addr, uint8_t Reg, uint8_t *Buffer, uint16_t Length);
00316 /**
00317   * @}
00318   */
00319 
00320 #ifdef __cplusplus
00321 }
00322 #endif
00323 
00324 #endif /* __HTS221__H */
00325 
00326 /**
00327   * @}
00328   */
00329   
00330 /**
00331   * @}
00332   */
00333   
00334 /**
00335   * @}
00336   */
00337 
00338 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/