Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: AmbientExampleLPC1768 HumidifierController_LPC824 TYBLE16_mbedlized_Thermometer
HDC1000.h
00001 /* 00002 * mbed library program 00003 * Low Power, High Accuracy Digital Humidity Sensor with Integrated Temperature Sensor 00004 * HDC1000 Texas Instruments 00005 * 00006 * Copyright (c) 2015,'17 Kenji Arai / JH1PJL 00007 * http://www.page.sannet.ne.jp/kenjia/index.html 00008 * http://mbed.org/users/kenjiArai/ 00009 * Created: Feburary 9th, 2015 00010 * Revised: AAugust 21st, 2017 00011 */ 00012 /* 00013 *---------------- REFERENCE ---------------------------------------------------------------------- 00014 * http://www.ti.com/product/HDC1000/description 00015 * http://akizukidenshi.com/catalog/g/gM-08775/ (Not avairable now) 00016 */ 00017 00018 #ifndef HDC1000_H 00019 #define HDC1000_H 00020 00021 #include "mbed.h" 00022 00023 // Humidity / Temperature Sensor, HDC1000 T.I. 00024 // Address b7=1,b6=0,b5=0,b4=0,b3=0,b2=0,b1=0, b0=R/W 00025 #define HDC1000ADDR (0x40 << 1) // Akizuki Module (No other choice) 00026 #define HDC1000ADDR1 (0x41 << 1) // ADR1=0, ADR0=1 00027 #define HDC1000ADDR2 (0x42 << 1) // ADR1=1, ADR0=0 00028 #define HDC1000ADDR3 (0x43 << 1) // ADR1=1, ADR0=1 00029 00030 ////////////// Registers ////////////////////////////////// 00031 // Register definition 00032 #define HDC1000_REG_TEMP 0x00 00033 #define HDC1000_REG_HUMI 0x01 00034 #define HDC1000_REG_CONFIG 0x02 00035 #define HDC1000_REG_S_ID_F 0xfb 00036 #define HDC1000_REG_S_ID_M 0xfc 00037 #define HDC1000_REG_S_ID_L 0xfd 00038 #define HDC1000_REG_M_ID 0xfe 00039 #define HDC1000_REG_D_ID 0xff 00040 00041 ////////////// ID ///////////////////////////////////////// 00042 #define I_AM_HDC1000 0x1000 00043 #define DEV_REG_ID 0x5449 00044 00045 ////////////// Operating mode /////////////////// 00046 #define ACQ_MODE_SEPARETE (0UL << 12) 00047 #define ACQ_MODE_BOTH (1UL << 12) 00048 #define TRES_14BIT (0UL << 10) 00049 #define TRES_11BIT (1UL << 10) 00050 #define HRES_14BIT (0UL << 8) 00051 #define HRES_11BIT (1UL << 8) 00052 #define HRES_08BIT (2UL << 8) 00053 #define BOTH_T_14_H_14 (TRES_14BIT + HRES_14BIT + ACQ_MODE_BOTH) 00054 00055 /** Interface for Humidity / Temperature Sensor, HDC1000 00056 * @code 00057 * #include "mbed.h" 00058 * #include "HDC1000.h" 00059 * 00060 * // I2C Communication 00061 * HDC1000 hmtp(dp5,dp27); // HDC1000 SDA, SCL (Akizuki module) 00062 * // If you connected I2C line not only this device but also other devices, 00063 * // you need to declare following method. 00064 * I2C i2c(dp5,dp27); // SDA, SCL 00065 * HDC1000 hmtp(i2c); // HDC1000 SDA, SCL (Akizuki module) 00066 * 00067 * int main() {; 00068 * while(true){ 00069 * hmtp.get(); // Triger conversion 00070 * printf("Temp: %+4.1fC, Humid: %4.1f%%\r\n", hmtp.temperature(), hmtp.humidity()); 00071 * wait(1.0); 00072 * } 00073 * } 00074 * @endcode 00075 */ 00076 00077 class HDC1000 00078 { 00079 public: 00080 /** Configure data pin (with other devices on I2C line) 00081 * @param data SDA and SCL pins 00082 */ 00083 HDC1000(PinName p_sda, PinName p_scl); 00084 00085 /** Configure data pin (with other devices on I2C line) 00086 * @param data SDA and SCL pins 00087 * @param device address 00088 */ 00089 HDC1000(PinName p_sda, PinName p_scl, uint8_t addr); 00090 00091 /** Configure data pin (with other devices on I2C line) 00092 * @param I2C previous definition 00093 */ 00094 HDC1000(I2C& p_i2c); 00095 HDC1000(I2C& p_i2c, uint8_t addr); 00096 00097 /** Start convertion & data save 00098 * @param none 00099 * @return none 00100 */ 00101 void get(void); 00102 00103 /** Read temperature data 00104 * @param none 00105 * @return temperature 00106 */ 00107 float temperature(void); 00108 00109 /** Read humidity data 00110 * @param none 00111 * @return humidity 00112 */ 00113 float humidity(void); 00114 00115 /** HDC1000 Configuration 00116 * @param none 00117 * @return none 00118 */ 00119 void config(void); 00120 00121 /** Read Configuration 00122 * @param none 00123 * @return config. data 00124 */ 00125 uint16_t read_config(void); 00126 00127 /** Set config register 00128 * @param config parameter 00129 * @return config read data 00130 */ 00131 uint16_t set_config(uint16_t cfg); 00132 00133 /** Set I2C clock frequency 00134 * @param freq. 00135 * @return none 00136 */ 00137 void frequency(int hz); 00138 00139 /** check Device ID number 00140 * @param none 00141 * @return HDC1000 = 1, others 0 00142 */ 00143 uint8_t who_am_i(void); 00144 00145 /** Read Manufacturer ID 00146 * @param none 00147 * @return ID 00148 */ 00149 uint16_t read_M_ID(void); 00150 00151 /** Read Device ID 00152 * @param none 00153 * @return ID 00154 */ 00155 uint16_t read_D_ID(void); 00156 00157 protected: 00158 I2C *_i2c_p; 00159 I2C &_i2c; 00160 00161 void get_IDs(void); 00162 void init(void); 00163 00164 private: 00165 uint8_t HDC1000_addr; 00166 uint8_t dt[4]; 00167 uint16_t temp; 00168 uint16_t humi; 00169 uint16_t manufacturer_id_number; 00170 uint16_t device_id_number; 00171 }; 00172 00173 #endif // HDC1000_H
Generated on Mon Jul 18 2022 02:20:43 by
1.7.2