Deepti AST / Envt_Shield_F4_API
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  AST Robotics Team
00005   * @version V0.0.1
00006   * @date    08-April-2014
00007   * @brief   This file contains definitions hts221.h 
00008   *          firmware driver.
00009   ******************************************************************************
00010   * @attention
00011   *
00012   * <h2><center>&copy; COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
00013   *
00014   * Redistribution and use in source and binary forms, with or without modification,
00015   * are permitted provided that the following conditions are met:
00016   *   1. Redistributions of source code must retain the above copyright notice,
00017   *      this list of conditions and the following disclaimer.
00018   *   2. Redistributions in binary form must reproduce the above copyright notice,
00019   *      this list of conditions and the following disclaimer in the documentation
00020   *      and/or other materials provided with the distribution.
00021   *   3. Neither the name of STMicroelectronics nor the names of its contributors
00022   *      may be used to endorse or promote products derived from this software
00023   *      without specific prior written permission.
00024   *
00025   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00026   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00027   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00028   * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
00029   * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00030   * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00031   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00032   * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00033   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00034   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00035   *
00036   ******************************************************************************
00037   */
00038   
00039 
00040 /* Define to prevent recursive inclusion -------------------------------------*/
00041 #ifndef __HTS221_H
00042 #define __HTS221_H
00043 
00044 #ifdef __cplusplus
00045  extern "C" {
00046 #endif
00047 
00048 /* Includes ------------------------------------------------------------------*/
00049 #include "../Common/hum_temp.h"
00050 
00051 /** @addtogroup BSP
00052   * @{
00053   */
00054 
00055 /** @addtogroup HTS221
00056   * @{
00057   */
00058   
00059 /** @defgroup HTS221_Exported_Constants
00060   * @{
00061   */
00062 
00063 /**
00064   * @brief Device Address
00065   */
00066 #define HTS221_ADDRESS                              0xBE
00067 
00068 /******************************************************************************/
00069 /*************************** START REGISTER MAPPING  **************************/
00070 /******************************************************************************/
00071 
00072 
00073 /**
00074  * @brief Device identification register.
00075  * \code
00076    * Read
00077  * Default value: 0xBC
00078  * 7:0 This read-only register contains the device identifier that, for HTS221, is set to BCh.
00079  * \endcode
00080 */
00081 #define HTS221_WHO_AM_I_ADDR                        0x0F
00082   
00083 
00084    /**
00085     * @brief Humidity resolution Register
00086     * \code
00087     * Read/write
00088     * Default value: 0x1B
00089     * 7:6 RFU
00090     * 5:3 AVGT2-AVGT0: Temperature internal average.
00091     *     AVGT2 | AVGT1 | AVGT0 | Nr. Internal Average
00092     *   ------------------------------------------------------
00093     *      0    |  0    |  0    |     2
00094     *      0    |  0    |  1    |     4
00095     *      0    |  1    |  0    |     8
00096     *      0    |  1    |  1    |     16
00097     *      1    |  0    |  0    |     32
00098     *      1    |  0    |  1    |     64
00099     *      1    |  1    |  0    |     128
00100     *      1    |  1    |  1    |     256
00101     *
00102     * 2:0 AVGH2-AVGH0: Humidity internal average.
00103     *     AVGH2 | AVGH1 | AVGH0 | Nr. Internal Average
00104     *   ------------------------------------------------------
00105     *      0    |  0    |  0    |     4
00106     *      0    |  0    |  1    |     8
00107     *      0    |  1    |  0    |     16
00108     *      0    |  1    |  1    |     32
00109     *      1    |  0    |  0    |     64
00110     *      1    |  0    |  1    |     128
00111     *      1    |  1    |  0    |     256
00112     *      1    |  1    |  1    |     512
00113     *
00114     * \endcode
00115     */
00116 #define HTS221_RES_CONF_ADDR                        0x10
00117 
00118 
00119     /**
00120     * @brief INFO Register  (LSB data)
00121     * \code
00122     * Read/write
00123     * Default value: 0x00
00124     * 7:0 INFO7-INFO0: Lower part of the INFO reference
00125     *                  used for traceability of the sample.
00126     * \endcode
00127     */
00128 #define HTS221_INFO_L_ADDR                          0x1E
00129 
00130 
00131     /**
00132     * @brief INFO & Calibration Version Register  (LSB data)
00133     * \code
00134     * Read/write
00135     * Default value: 0x00
00136     * 7:6 CALVER1:CALVER0
00137     * 5:0 INFO13-INFO8: Higher part of the INFO reference
00138     *                  used for traceability of the sample.
00139     * \endcode
00140     */
00141 #define HTS221_INFO_H_ADDR                          0x1F
00142 
00143 
00144     /**
00145     * @brief Humidity sensor control register 1
00146     * \code
00147     * Read/write
00148     * Default value: 0x00
00149     * 7    PD: power down control. 0 - disable; 1 - enable
00150     * 6:3  RFU
00151     * 2    BDU: block data update. 0 - disable; 1 - enable
00152     * 1:0  RFU
00153     * \endcode
00154     */
00155 
00156 #define HTS221_CTRL_REG1_ADDR                       0x20
00157 
00158 
00159     /**
00160     * @brief Humidity sensor control register 2
00161     * \code
00162     * Read/write
00163     * Default value: 0x00
00164     * 7    BOOT:  Reboot memory content. 0: normal mode; 1: reboot memory content
00165     * 6:3  Reserved.
00166     * 2    Reserved.
00167     * 1    Reserved.
00168     * 0    ONE_SHOT: One shot enable. 0: waiting for start of conversion; 1: start for a new dataset
00169     * \endcode
00170     */
00171 #define HTS221_CTRL_REG2_ADDR                       0x21
00172 
00173 
00174     /**
00175     * @brief  Status Register
00176     * \code
00177     * Read
00178     * Default value: 0x00
00179     * 7:2  RFU
00180     * 1    H_DA: Humidity data available. 0: new data for Humidity is not yet available; 1: new data for Humidity is available.
00181     * 0    T_DA: Temperature data available. 0: new data for temperature is not yet available; 1: new data for temperature is available.
00182     * \endcode
00183     */
00184 #define HTS221_STATUS_REG_ADDR                      0x27
00185 
00186 
00187     /**
00188     * @brief  Humidity data (LSB).
00189     * \code
00190     * Read
00191     * Default value: 0x00.
00192     * POUT7 - POUT0: Humidity data LSB (2's complement) => signed 16 bits
00193     * RAW Humidity output data: Hout(%)=(HUMIDITY_OUT_H & HUMIDITY_OUT_L).
00194     * \endcode
00195     */
00196 #define HTS221_HUMIDITY_OUT_L_ADDR                  0x28
00197 
00198 
00199     /**
00200     * @brief  Humidity data (MSB).
00201     * \code
00202     * Read
00203     * Default value: 0x00.
00204     * POUT7 - POUT0: Humidity data LSB (2's complement) => signed 16 bits
00205     * RAW Humidity output data: Hout(%)=(HUMIDITY_OUT_H & HUMIDITY_OUT_L).
00206     * \endcode
00207     */
00208 #define HTS221_HUMIDITY_OUT_H_ADDR                  0x29
00209 
00210 
00211     /**
00212     * @brief  Temperature data (LSB).
00213     * \code
00214     * Read
00215     * Default value: 0x00.
00216     * TOUT7 - TOUT0: temperature data LSB (2's complement) => signed 16 bits
00217     * RAW Temperature output data: Tout (LSB)=(TEMP_OUT_H & TEMP_OUT_L).
00218     * \endcode
00219     */
00220 #define HTS221_TEMP_OUT_L_ADDR                      0x2A
00221 
00222 
00223     /**
00224     * @brief  Temperature data (MSB).
00225     * \code
00226     * Read
00227     * Default value: 0x00.
00228     * TOUT15 - TOUT8: temperature data MSB (2's complement) => signed 16 bits
00229     * RAW Temperature output data: Tout (LSB)=(TEMP_OUT_H & TEMP_OUT_L).
00230     * \endcode
00231     */
00232 #define HTS221_TEMP_OUT_H_ADDR                      0x2B
00233 
00234 
00235     /*
00236     *@brief Humidity 0 Register in %RH with sensitivity=2
00237     *\code
00238     * Read
00239     * Value: (Unsigned 8 Bit)/2
00240     *\endcode
00241     */
00242 #define HTS221_H0_RH_X2_ADDR                        0x30
00243 
00244 
00245     /*
00246     *@brief Humidity 1 Register in %RH with sensitivity=2
00247     *\code
00248     * Read
00249     * Value: (Unsigned 8 Bit)/2
00250     *\endcode
00251     */
00252 #define HTS221_H1_RH_X2_ADDR                        0x31
00253 
00254 
00255     /*
00256     *@brief Temperature 0 Register in deg with sensitivity=8
00257     *\code
00258     * Read
00259     * Value: (Unsigned 16 Bit)/2
00260     *\endcode
00261     */
00262 #define HTS221_T0_degC_X8_ADDR                      0x32
00263 
00264 
00265     /*
00266     *@brief Temperature 1 Register in deg with sensitivity=8
00267     *\code
00268     * Read
00269     * Value: (Unsigned 16 Bit)/2
00270     *\endcode
00271     */
00272 #define HTS221_T1_degC_X8_ADDR                      0x33
00273 
00274 
00275     /*
00276     *@brief Temperature 1/0 MSB Register in deg with sensitivity=8
00277     *\code
00278     * Read
00279     * Value: (Unsigned 16 Bit)/2
00280     * 3:2  T1(9):T1(8) MSB T1_degC_X8 bits
00281     * 1:0  T0(9):T0(8) MSB T0_degC_X8 bits
00282     *\endcode
00283     */
00284 #define HTS221_T1_T0_MSB_X8_ADDR                    0x35
00285 
00286 
00287     /*
00288     *@brief Humidity LOW CALIBRATION Register
00289     *\code
00290     * Read
00291     * Default value: 0x00.
00292     * H0_T0_TOUT7 - H0_T0_TOUT0: HUMIDITY data lSB (2's complement) => signed 16 bits
00293     *\endcode
00294     */
00295 #define HTS221_H0_T0_OUT_L_ADDR                     0x36
00296 
00297 
00298     /*
00299     *@brief Humidity LOW CALIBRATION Register
00300     *\code
00301     * Read
00302     * Default value: 0x00.
00303     * H0_T0_TOUT15 - H0_T0_TOUT8: HUMIDITY data mSB (2's complement) => signed 16 bits
00304     *\endcode
00305     */
00306 #define HTS221_H0_T0_OUT_H_ADDR                       0x37
00307 
00308 
00309     /*
00310     *@brief Humidity HIGH CALIBRATION Register
00311     *\code
00312     * Read
00313     * Default value: 0x00.
00314     * H1_T0_TOUT7 - H1_T0_TOUT0: HUMIDITY data lSB (2's complement) => signed 16 bits
00315     *\endcode
00316     */
00317 #define HTS221_H1_T0_OUT_L_ADDR                       0x3A
00318 
00319 
00320     /*
00321     *@brief Humidity HIGH CALIBRATION Register
00322     *\code
00323     * Read
00324     * Default value: 0x00.
00325     * H1_T0_TOUT15 - H1_T0_TOUT8: HUMIDITY data mSB (2's complement) => signed 16 bits
00326     *\endcode
00327     */
00328 #define HTS221_H1_T0_OUT_H_ADDR                       0x3B
00329 
00330 
00331     /**
00332     * @brief  Low Calibration Temperature Register (LSB).
00333     * \code
00334     * Read
00335     * Default value: 0x00.
00336     * T0_OUT7 - T0_OUT0: temperature data LSB (2's complement) => signed 16 bits
00337     *  RAW LOW Calibration data: T0_OUT (LSB)=(T0_OUT_H & T0_OUT_L).
00338     * \endcode
00339     */
00340 #define HTS221_T0_OUT_L_ADDR                        0x3C
00341 
00342 
00343     /**
00344     * @brief  Low Calibration Temperature Register (MSB)
00345     * \code
00346     * Read
00347     * Default value: 0x00.
00348     * T0_OUT15 - T0_OUT8: temperature data MSB (2's complement) => signed 16 bits
00349     * RAW LOW Calibration data: T0_OUT (LSB)=(T0_OUT_H & T0_OUT_L).
00350     * \endcode
00351     */
00352 #define HTS221_T0_OUT_H_ADDR                        0x3D
00353 
00354 
00355     /**
00356     * @brief  Low Calibration Temperature Register (LSB).
00357     * \code
00358     * Read
00359     * Default value: 0x00.
00360     * T1_OUT7 - T1_OUT0: temperature data LSB (2's complement) => signed 16 bits
00361     *  RAW LOW Calibration data: T1_OUT (LSB)=(T1_OUT_H & T1_OUT_L).
00362     * \endcode
00363     */
00364 #define HTS221_T1_OUT_L_ADDR                        0x3E
00365 
00366 
00367     /**
00368     * @brief  Low Calibration Temperature Register (MSB)
00369     * \code
00370     * Read
00371     * Default value: 0x00.
00372     * T1_OUT15 - T1_OUT8: temperature data MSB (2's complement) => signed 16 bits
00373     * RAW LOW Calibration data: T1_OUT (LSB)=(T1_OUT_H & T1_OUT_L).
00374     * \endcode
00375     */
00376 #define HTS221_T1_OUT_H_ADDR                        0x3F
00377 
00378 
00379 /******************************************************************************/
00380 /**************************** END REGISTER MAPPING  ***************************/
00381 /******************************************************************************/
00382 
00383 
00384 /**
00385  * @brief Device Identifier. Default value of the WHO_AM_I register.
00386  */
00387 #define I_AM_HTS221                         ((uint8_t)0xBC)
00388 
00389 
00390 /** @defgroup HTS221 Power Mode selection - CTRL_REG1
00391   * @{
00392   */
00393 #define HTS221_MODE_POWERDOWN               ((uint8_t)0x00)
00394 #define HTS221_MODE_ACTIVE                  ((uint8_t)0x80)
00395 
00396 #define HTS221_MODE_MASK                    ((uint8_t)0x80)
00397 /**
00398   * @}
00399   */ 
00400 
00401 
00402 /** @defgroup HTS221 Block Data Update Mode selection - CTRL_REG1
00403   * @{
00404   */
00405 #define HTS221_BDU_CONTINUOUS               ((uint8_t)0x00)
00406 #define HTS221_BDU_NOT_UNTIL_READING        ((uint8_t)0x04)
00407 
00408 #define HTS221_BDU_MASK                     ((uint8_t)0x04)
00409 /**
00410   * @}
00411   */
00412 
00413 /** @defgroup HTS221 Output Data Rate selection - CTRL_REG1
00414  * @{
00415  */
00416 #define HTS221_ODR_ONE_SHOT             ((uint8_t)0x00) /*!< Output Data Rate: H - one shot, T - one shot */
00417 #define HTS221_ODR_1Hz                  ((uint8_t)0x01) /*!< Output Data Rate: H - 1Hz, T - 1Hz */
00418 #define HTS221_ODR_7Hz                  ((uint8_t)0x02) /*!< Output Data Rate: H - 7Hz, T - 7Hz */
00419 #define HTS221_ODR_12_5Hz               ((uint8_t)0x03) /*!< Output Data Rate: H - 12.5Hz, T - 12.5Hz */
00420 
00421 #define HTS221_ODR_MASK                 ((uint8_t)0x03)
00422 /**
00423 * @}
00424 */
00425 
00426 
00427 /** @defgroup HTS221 Boot Mode selection - CTRL_REG2
00428   * @{
00429   */
00430 #define HTS221_BOOT_NORMALMODE              ((uint8_t)0x00)
00431 #define HTS221_BOOT_REBOOTMEMORY            ((uint8_t)0x80)
00432 
00433 #define HTS221_BOOT_MASK                    ((uint8_t)0x80)
00434 /**
00435   * @}
00436   */  
00437 
00438 
00439 /** @defgroup HTS221 One Shot selection - CTRL_REG2
00440  * @{
00441  */
00442 #define HTS221_ONE_SHOT_START               ((uint8_t)0x01)
00443 
00444 #define HTS221_ONE_SHOT_MASK                ((uint8_t)0x01)
00445 /**
00446  * @}
00447  */
00448 
00449 
00450 /** @defgroup HTS221 Boot Mode selection - CTRL_REG2
00451   * @{
00452   */
00453 #define HTS221_BOOT_NORMALMODE              ((uint8_t)0x00)
00454 #define HTS221_BOOT_REBOOTMEMORY            ((uint8_t)0x80)
00455 
00456 #define HTS221_BOOT_MASK                    ((uint8_t)0x80)
00457 /**
00458   * @}
00459   */
00460 
00461 
00462 /** @defgroup HTS221 PushPull_OpenDrain selection - CTRL_REG3
00463   * @{
00464   */
00465 #define HTS221_PP_OD_PUSH_PULL              ((uint8_t)0x00)
00466 #define HTS221_PP_OD_OPEN_DRAIN             ((uint8_t)0x40)
00467 
00468 #define HTS221_PP_OD_MASK                   ((uint8_t)0x40)
00469 /**
00470   * @}
00471   */
00472 
00473 
00474 /** @defgroup HTS221 Data ready selection - CTRL_REG3
00475   * @{
00476   */
00477 #define HTS221_DRDY_DISABLE                 ((uint8_t)0x00)
00478 #define HTS221_DRDY_AVAILABLE               ((uint8_t)0x40)
00479 
00480 #define HTS221_DRDY_MASK                    ((uint8_t)0x40)
00481 /**
00482   * @}
00483   */
00484 
00485 
00486 /** @defgroup HTS221 Humidity resolution selection - RES_CONF
00487   * @{
00488   */
00489 #define HTS221_H_RES_AVG_4                  ((uint8_t)0x00)
00490 #define HTS221_H_RES_AVG_8                  ((uint8_t)0x01)
00491 #define HTS221_H_RES_AVG_16                 ((uint8_t)0x02)
00492 #define HTS221_H_RES_AVG_32                 ((uint8_t)0x03)
00493 #define HTS221_H_RES_AVG_64                 ((uint8_t)0x04)
00494 #define HTS221_H_RES_AVG_128                ((uint8_t)0x05)
00495 
00496 #define HTS221_H_RES_MASK                   ((uint8_t)0x07)
00497 /**
00498   * @}
00499   */
00500 
00501 
00502 /** @defgroup HTS221 Temperature resolution - RES_CONF
00503   * @{
00504   */
00505 #define HTS221_T_RES_AVG_2                  ((uint8_t)0x00)
00506 #define HTS221_T_RES_AVG_4                  ((uint8_t)0x08)
00507 #define HTS221_T_RES_AVG_8                  ((uint8_t)0x10)
00508 #define HTS221_T_RES_AVG_16                 ((uint8_t)0x18)
00509 #define HTS221_T_RES_AVG_32                 ((uint8_t)0x20)
00510 #define HTS221_T_RES_AVG_64                 ((uint8_t)0x28)
00511 
00512 #define HTS221_T_RES_MASK                   ((uint8_t)0x38)
00513 /**
00514   * @}
00515   */
00516 
00517 
00518 /** @defgroup HTS221 Temperature Humidity data available - STATUS_REG
00519   * @{
00520   */
00521 #define HTS221_H_DATA_AVAILABLE_MASK        ((uint8_t)0x02)
00522 #define HTS221_T_DATA_AVAILABLE_MASK        ((uint8_t)0x01)
00523 /**
00524   * @}
00525   */
00526 
00527 
00528 
00529 /* Data resolution */
00530 #define HUM_DECIMAL_DIGITS                  (2)
00531 #define TEMP_DECIMAL_DIGITS                 (2)
00532 
00533 
00534 
00535 /**
00536   * @}
00537   */
00538 
00539 
00540  
00541 /** @defgroup UVIS3_Exported_Functions
00542   * @{
00543   */
00544 /* Sensor Configuration Functions */ 
00545 void      HTS221_Init(HUM_TEMP_InitTypeDef *HTS221_Init);
00546 uint8_t   HTS221_ReadID(void);
00547 void      HTS221_RebootCmd(void);
00548 void      HTS221_Power_OFF(void);
00549 void      HTS221_GetHumidity(float* pfData);
00550 void      HTS221_GetTemperature(float* pfData);
00551 
00552 /* Interrupt Configuration Functions */
00553 void      HTS221_INT1InterruptConfig(uint16_t Int1Config);
00554 void      HTS221_EnableIT(uint8_t IntPin);
00555 void      HTS221_DisableIT(uint8_t IntPin);
00556 
00557 /* HUM_TEMP sensor driver structure */
00558 extern HUM_TEMP_DrvTypeDef Hts221Drv;
00559 
00560 /* HUM_TEMP sensor IO functions */
00561 void      HUM_TEMP_IO_Init(void);
00562 void      HUM_TEMP_IO_DeInit(void);
00563 void      HUM_TEMP_IO_Write(uint8_t* pBuffer, uint8_t DeviceAddr, uint8_t WriteAddr, uint16_t NumByteToWrite);
00564 void      HUM_TEMP_IO_Read(uint8_t* pBuffer, uint8_t DeviceAddr, uint8_t RegisterAddr, uint16_t NumByteToRead);
00565 
00566 /**
00567   * @}
00568   */
00569 
00570 /**
00571   * @}
00572   */ 
00573   
00574 /**
00575   * @}
00576   */ 
00577   
00578 #ifdef __cplusplus
00579   }
00580 #endif
00581   
00582 #endif /* __HTS221_H */
00583 
00584 
00585 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 
00586