20170911

Dependents:   Hexi_Click_HDC1000 Hexi_Click_HDC1000_v2

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers HDC1000.h Source File

HDC1000.h

00001 
00002 /*
00003  * mbed library program
00004  *  Low Power, High Accuracy Digital Humidity Sensor with Integrated Temperature Sensor
00005  *  HDC1000 Texas Instruments
00006  *
00007  * Copyright (c) 2015,'17 Kenji Arai / JH1PJL
00008  *  http://www.page.sannet.ne.jp/kenjia/index.html
00009  *  http://mbed.org/users/kenjiArai/
00010  *      Created: Feburary   9th, 2015
00011  *      Revised: AAugust   21st, 2017
00012  */
00013 /*
00014  *---------------- REFERENCE ----------------------------------------------------------------------
00015  *  http://www.ti.com/product/HDC1000/description
00016  *  http://akizukidenshi.com/catalog/g/gM-08775/ (Not avairable now)
00017  */
00018  
00019 #ifndef HDC1000_H
00020 #define HDC1000_H
00021  
00022 #include "mbed.h"
00023  
00024 // Humidity / Temperature Sensor, HDC1000 T.I.
00025 // Address b7=1,b6=0,b5=0,b4=0,b3=0,b2=0,b1=0, b0=R/W
00026 #define HDC1000ADDR   (0x40 << 1)  // CLICK BOARD
00027 
00028  
00029 ////////////// Registers //////////////////////////////////
00030 // Register definition
00031 #define HDC1000_REG_TEMP    0x00
00032 #define HDC1000_REG_HUMI    0x01
00033 #define HDC1000_REG_CONFIG  0x02
00034 #define HDC1000_REG_S_ID_F  0xfb
00035 #define HDC1000_REG_S_ID_M  0xfc
00036 #define HDC1000_REG_S_ID_L  0xfd
00037 #define HDC1000_REG_M_ID    0xfe
00038 #define HDC1000_REG_D_ID    0xff
00039  
00040 ////////////// ID /////////////////////////////////////////
00041 #define I_AM_HDC1000        0x1000
00042 #define DEV_REG_ID          0x5449
00043  
00044 ////////////// Operating mode ///////////////////
00045 #define ACQ_MODE_SEPARETE   (0UL << 12)
00046 #define ACQ_MODE_BOTH       (1UL << 12)
00047 #define TRES_14BIT          (0UL << 10)
00048 #define TRES_11BIT          (1UL << 10)
00049 #define HRES_14BIT          (0UL << 8)
00050 #define HRES_11BIT          (1UL << 8)
00051 #define HRES_08BIT          (2UL << 8)
00052 #define BOTH_T_14_H_14      (TRES_14BIT + HRES_14BIT + ACQ_MODE_BOTH)
00053  
00054 
00055 class HDC1000
00056 {
00057 public:
00058     /** Configure data pin (with other devices on I2C line)
00059       * @param data SDA and SCL pins
00060       */
00061     HDC1000(PinName p_sda, PinName p_scl);
00062  
00063     /** Configure data pin (with other devices on I2C line)
00064       * @param data SDA and SCL pins
00065       * @param device address
00066       */
00067     HDC1000(PinName p_sda, PinName p_scl, uint8_t addr);
00068  
00069     /** Configure data pin (with other devices on I2C line)
00070       * @param I2C previous definition
00071       */
00072     HDC1000(I2C& p_i2c);
00073     HDC1000(I2C& p_i2c, uint8_t addr);
00074  
00075     /** Start convertion & data save
00076       * @param none
00077       * @return none
00078       */
00079     void get(void);
00080  
00081     /** Read temperature data
00082       * @param none
00083       * @return temperature
00084       */
00085     float temperature(void);
00086     
00087     float conv_c_to_f(void);
00088     
00089     uint16_t send_temp(void);
00090     uint16_t send_humi(void);
00091     
00092     /** Read humidity data
00093       * @param none
00094       * @return humidity
00095       */
00096     float humidity(void);
00097  
00098     /** HDC1000 Configuration
00099       * @param none
00100       * @return none
00101       */
00102     void config(void);
00103  
00104     /** Read Configuration
00105       * @param none
00106       * @return config. data
00107       */
00108     uint16_t read_config(void);
00109  
00110     /** Set config register
00111       * @param config parameter
00112       * @return config read data
00113       */
00114     uint16_t set_config(uint16_t cfg);
00115  
00116     /** Set I2C clock frequency
00117       * @param freq.
00118       * @return none
00119       */
00120     void frequency(int hz);
00121  
00122     /** check Device ID number
00123       * @param none
00124       * @return HDC1000 = 1, others  0
00125       */
00126     uint8_t who_am_i(void);
00127  
00128     /** Read Manufacturer ID
00129       * @param none
00130       * @return ID
00131       */
00132     uint16_t read_M_ID(void);
00133  
00134     /** Read Device ID
00135       * @param none
00136       * @return ID
00137       */
00138     uint16_t read_D_ID(void);
00139  
00140 protected:
00141     I2C *_i2c_p;
00142     I2C &_i2c;
00143  
00144     void get_IDs(void);
00145     void init(void);
00146  
00147 private:
00148     uint8_t  HDC1000_addr;
00149     uint8_t  dt[4];
00150     uint16_t temp;
00151     uint16_t humi;
00152     uint16_t manufacturer_id_number;
00153     uint16_t device_id_number;
00154 };
00155  
00156 #endif      // HDC1000_H