NimbeLink / hts221

Dependents:   WeatherSensor-Joe PAG-CourseWork-NicksEdits SOFT253_Assignment SOFT253_Assignment_V2 ... more

Fork of hts221 by Kyle Rodgers

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers hts221.h Source File

hts221.h

00001 /* Copyright (c) 2009 Nordic Semiconductor. All Rights Reserved.
00002  *
00003  * The information contained herein is property of Nordic Semiconductor ASA.
00004  * Terms and conditions of usage are described in detail in NORDIC
00005  * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
00006  *
00007  * Licensees are granted free, non-transferable use of the information. NO
00008  * WARRANTY of ANY KIND is provided. This heading must NOT be removed from
00009  * the file.
00010  *
00011  */
00012 
00013 #ifndef HTS221_H
00014 #define HTS221_H
00015 
00016 /*lint ++flb "Enter library region" */
00017 
00018 #include <stdbool.h>
00019 #include <stdint.h>
00020 
00021 #define ADDRESS_WHO_AM_I (0x0FU) //!< WHO_AM_I register identifies the device. Expected value is 0xBC.
00022 
00023 #define HTS221_WriteADDE         0xBE
00024 #define HTS221_ReadADDE          0xBF
00025 #define HTS221_TempHumi_OUT      0x28
00026 #define HTS221_CALIB             0x30
00027 
00028 #define MaxTemp       120
00029 #define MinTemp       -40
00030 #define MaxHumi       100
00031 #define MinHumi       0
00032 
00033 // Humidity and temperature resolution mode, to ocnfigure sample average
00034 #define TRes_1        000 // Number of temperature samples take 2^1,2^2...etc.
00035 #define TRes_2        001
00036 #define TRes_3        010
00037 #define TRes_4        011
00038 #define TRes_5        100
00039 #define TRes_6        101
00040 #define TRes_7        102
00041 #define TRes_8        103
00042 
00043 #define HRes_2        000 // Number of humidity samples take 2^2,2^3...etc.
00044 #define HRes_3        001
00045 #define HRes_4        010
00046 #define HRes_5        011
00047 #define HRes_6        100
00048 #define HRes_7        101
00049 #define HRes_8        102
00050 #define HRes_9        103
00051 
00052 // Control register 1
00053 #define PD_On                    0x80 // Power down mode
00054 #define PD_Off                   0x00 // Active mode
00055 
00056 #define BDU_On                   0x04 // Block data update, this feature prevents the reading of LSB and MSB related to different samples.
00057 #define BDU_Off                  0x00 
00058 // Define output data rate
00059 #define ODR_OneShot              0x00
00060 #define ODR_1Hz                  0x01
00061 #define ODR_7Hz                  0x02
00062 #define ODR_12_5Hz               0x03
00063 // Control register 2
00064 #define Boot                     0x80
00065 #define NoBoot                   0x00
00066 #define HeaterOn                 0x02
00067 #define HeaterOff                0x00
00068 #define New_OS                   0x01 // One shot, a single acquisition of temperature and humidity is started
00069 #define No_OS                    0x00
00070 // Control register 3
00071 #define DRDY_H                   0x00 // Data Ready output signal active high(default)
00072 #define DRDY_L                   0x80 // Data Ready output signal active low
00073 #define PP_OD_PP                 0x00 // Push-pull on PIN3(DRDY)(default)
00074 #define PP_OD_OD                 0x40 // Open Drain on PIN3(DRDY)
00075 #define DRDY_EN                  0x04 // Data Ready enable
00076 #define DRDY_NON                 0x00 // Data Ready disable(default)
00077 
00078 // Status register
00079 #define H_DA_On                  0x02 // Humidity data avialable, set to 1 whenever a new humidity sample is available.
00080 #define H_DA_Off                 0x00
00081 #define T_DA_On                  0x01 // Temperature data avialable, set to 1 whenever a new humidity sample is available.
00082 #define T_DA_Off                 0x00
00083  
00084 class HTS221{
00085 public:
00086     enum PowerMode {
00087         POWER_NORMAL,   
00088         POWER_SHUTDOWN  /**< Chip is in low-power shutdown mode */
00089     };    
00090     HTS221 (PinName sda, PinName scl);
00091     void calib(void);
00092     bool init(void);
00093     void ReadTempHumi( float *pTemp , float *pHumi);
00094     void powerMode(PowerMode mode);
00095     
00096 private:
00097     void register_write(uint8_t register_address, const uint8_t value);
00098     void register_read(char register_address, char *destination, uint8_t number_of_bytes);
00099     bool verify_product_id(void);
00100     float linear_interpolation(int16_t x0, float y0, int16_t x1, float y1, float mes);
00101     
00102     I2C _i2c;
00103     
00104     static const char expected_who_am_i = 0xBCU; //!< Expected value to get from WHO_AM_I register.
00105 
00106     uint8_t H0_rH_x2; 
00107     uint8_t H1_rH_x2;
00108     uint16_t T0_degC_x8;
00109     uint16_t T1_degC_x8;
00110 
00111     int16_t H0_T0_OUT;
00112     int16_t H1_T0_OUT;
00113     int16_t T0_OUT;
00114     int16_t T1_OUT;
00115 
00116     float T0_DegC_cal;
00117     float T1_DegC_cal;
00118     float H0_RH_cal;
00119     float H1_RH_cal;
00120 
00121 };
00122 
00123 #endif /* HTS221_H */
00124