20170911
Dependents: Hexi_Click_HDC1000 Hexi_Click_HDC1000_v2
HDC1000.h@0:2dee66cf94c2, 2017-09-11 (annotated)
- Committer:
- i_am_kitsune
- Date:
- Mon Sep 11 02:06:47 2017 +0000
- Revision:
- 0:2dee66cf94c2
- Child:
- 1:383429056bd4
20170911
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| i_am_kitsune | 0:2dee66cf94c2 | 1 | |
| i_am_kitsune | 0:2dee66cf94c2 | 2 | /* |
| i_am_kitsune | 0:2dee66cf94c2 | 3 | * mbed library program |
| i_am_kitsune | 0:2dee66cf94c2 | 4 | * Low Power, High Accuracy Digital Humidity Sensor with Integrated Temperature Sensor |
| i_am_kitsune | 0:2dee66cf94c2 | 5 | * HDC1000 Texas Instruments |
| i_am_kitsune | 0:2dee66cf94c2 | 6 | * |
| i_am_kitsune | 0:2dee66cf94c2 | 7 | * Copyright (c) 2015,'17 Kenji Arai / JH1PJL |
| i_am_kitsune | 0:2dee66cf94c2 | 8 | * http://www.page.sannet.ne.jp/kenjia/index.html |
| i_am_kitsune | 0:2dee66cf94c2 | 9 | * http://mbed.org/users/kenjiArai/ |
| i_am_kitsune | 0:2dee66cf94c2 | 10 | * Created: Feburary 9th, 2015 |
| i_am_kitsune | 0:2dee66cf94c2 | 11 | * Revised: AAugust 21st, 2017 |
| i_am_kitsune | 0:2dee66cf94c2 | 12 | */ |
| i_am_kitsune | 0:2dee66cf94c2 | 13 | /* |
| i_am_kitsune | 0:2dee66cf94c2 | 14 | *---------------- REFERENCE ---------------------------------------------------------------------- |
| i_am_kitsune | 0:2dee66cf94c2 | 15 | * http://www.ti.com/product/HDC1000/description |
| i_am_kitsune | 0:2dee66cf94c2 | 16 | * http://akizukidenshi.com/catalog/g/gM-08775/ (Not avairable now) |
| i_am_kitsune | 0:2dee66cf94c2 | 17 | */ |
| i_am_kitsune | 0:2dee66cf94c2 | 18 | |
| i_am_kitsune | 0:2dee66cf94c2 | 19 | #ifndef HDC1000_H |
| i_am_kitsune | 0:2dee66cf94c2 | 20 | #define HDC1000_H |
| i_am_kitsune | 0:2dee66cf94c2 | 21 | |
| i_am_kitsune | 0:2dee66cf94c2 | 22 | #include "mbed.h" |
| i_am_kitsune | 0:2dee66cf94c2 | 23 | |
| i_am_kitsune | 0:2dee66cf94c2 | 24 | // Humidity / Temperature Sensor, HDC1000 T.I. |
| i_am_kitsune | 0:2dee66cf94c2 | 25 | // Address b7=1,b6=0,b5=0,b4=0,b3=0,b2=0,b1=0, b0=R/W |
| i_am_kitsune | 0:2dee66cf94c2 | 26 | #define HDC1000ADDR (0x40 << 1) // CLICK BOARD |
| i_am_kitsune | 0:2dee66cf94c2 | 27 | |
| i_am_kitsune | 0:2dee66cf94c2 | 28 | |
| i_am_kitsune | 0:2dee66cf94c2 | 29 | ////////////// Registers ////////////////////////////////// |
| i_am_kitsune | 0:2dee66cf94c2 | 30 | // Register definition |
| i_am_kitsune | 0:2dee66cf94c2 | 31 | #define HDC1000_REG_TEMP 0x00 |
| i_am_kitsune | 0:2dee66cf94c2 | 32 | #define HDC1000_REG_HUMI 0x01 |
| i_am_kitsune | 0:2dee66cf94c2 | 33 | #define HDC1000_REG_CONFIG 0x02 |
| i_am_kitsune | 0:2dee66cf94c2 | 34 | #define HDC1000_REG_S_ID_F 0xfb |
| i_am_kitsune | 0:2dee66cf94c2 | 35 | #define HDC1000_REG_S_ID_M 0xfc |
| i_am_kitsune | 0:2dee66cf94c2 | 36 | #define HDC1000_REG_S_ID_L 0xfd |
| i_am_kitsune | 0:2dee66cf94c2 | 37 | #define HDC1000_REG_M_ID 0xfe |
| i_am_kitsune | 0:2dee66cf94c2 | 38 | #define HDC1000_REG_D_ID 0xff |
| i_am_kitsune | 0:2dee66cf94c2 | 39 | |
| i_am_kitsune | 0:2dee66cf94c2 | 40 | ////////////// ID ///////////////////////////////////////// |
| i_am_kitsune | 0:2dee66cf94c2 | 41 | #define I_AM_HDC1000 0x1000 |
| i_am_kitsune | 0:2dee66cf94c2 | 42 | #define DEV_REG_ID 0x5449 |
| i_am_kitsune | 0:2dee66cf94c2 | 43 | |
| i_am_kitsune | 0:2dee66cf94c2 | 44 | ////////////// Operating mode /////////////////// |
| i_am_kitsune | 0:2dee66cf94c2 | 45 | #define ACQ_MODE_SEPARETE (0UL << 12) |
| i_am_kitsune | 0:2dee66cf94c2 | 46 | #define ACQ_MODE_BOTH (1UL << 12) |
| i_am_kitsune | 0:2dee66cf94c2 | 47 | #define TRES_14BIT (0UL << 10) |
| i_am_kitsune | 0:2dee66cf94c2 | 48 | #define TRES_11BIT (1UL << 10) |
| i_am_kitsune | 0:2dee66cf94c2 | 49 | #define HRES_14BIT (0UL << 8) |
| i_am_kitsune | 0:2dee66cf94c2 | 50 | #define HRES_11BIT (1UL << 8) |
| i_am_kitsune | 0:2dee66cf94c2 | 51 | #define HRES_08BIT (2UL << 8) |
| i_am_kitsune | 0:2dee66cf94c2 | 52 | #define BOTH_T_14_H_14 (TRES_14BIT + HRES_14BIT + ACQ_MODE_BOTH) |
| i_am_kitsune | 0:2dee66cf94c2 | 53 | |
| i_am_kitsune | 0:2dee66cf94c2 | 54 | |
| i_am_kitsune | 0:2dee66cf94c2 | 55 | class HDC1000 |
| i_am_kitsune | 0:2dee66cf94c2 | 56 | { |
| i_am_kitsune | 0:2dee66cf94c2 | 57 | public: |
| i_am_kitsune | 0:2dee66cf94c2 | 58 | /** Configure data pin (with other devices on I2C line) |
| i_am_kitsune | 0:2dee66cf94c2 | 59 | * @param data SDA and SCL pins |
| i_am_kitsune | 0:2dee66cf94c2 | 60 | */ |
| i_am_kitsune | 0:2dee66cf94c2 | 61 | HDC1000(PinName p_sda, PinName p_scl); |
| i_am_kitsune | 0:2dee66cf94c2 | 62 | |
| i_am_kitsune | 0:2dee66cf94c2 | 63 | /** Configure data pin (with other devices on I2C line) |
| i_am_kitsune | 0:2dee66cf94c2 | 64 | * @param data SDA and SCL pins |
| i_am_kitsune | 0:2dee66cf94c2 | 65 | * @param device address |
| i_am_kitsune | 0:2dee66cf94c2 | 66 | */ |
| i_am_kitsune | 0:2dee66cf94c2 | 67 | HDC1000(PinName p_sda, PinName p_scl, uint8_t addr); |
| i_am_kitsune | 0:2dee66cf94c2 | 68 | |
| i_am_kitsune | 0:2dee66cf94c2 | 69 | /** Configure data pin (with other devices on I2C line) |
| i_am_kitsune | 0:2dee66cf94c2 | 70 | * @param I2C previous definition |
| i_am_kitsune | 0:2dee66cf94c2 | 71 | */ |
| i_am_kitsune | 0:2dee66cf94c2 | 72 | HDC1000(I2C& p_i2c); |
| i_am_kitsune | 0:2dee66cf94c2 | 73 | HDC1000(I2C& p_i2c, uint8_t addr); |
| i_am_kitsune | 0:2dee66cf94c2 | 74 | |
| i_am_kitsune | 0:2dee66cf94c2 | 75 | /** Start convertion & data save |
| i_am_kitsune | 0:2dee66cf94c2 | 76 | * @param none |
| i_am_kitsune | 0:2dee66cf94c2 | 77 | * @return none |
| i_am_kitsune | 0:2dee66cf94c2 | 78 | */ |
| i_am_kitsune | 0:2dee66cf94c2 | 79 | void get(void); |
| i_am_kitsune | 0:2dee66cf94c2 | 80 | |
| i_am_kitsune | 0:2dee66cf94c2 | 81 | /** Read temperature data |
| i_am_kitsune | 0:2dee66cf94c2 | 82 | * @param none |
| i_am_kitsune | 0:2dee66cf94c2 | 83 | * @return temperature |
| i_am_kitsune | 0:2dee66cf94c2 | 84 | */ |
| i_am_kitsune | 0:2dee66cf94c2 | 85 | float temperature(void); |
| i_am_kitsune | 0:2dee66cf94c2 | 86 | |
| i_am_kitsune | 0:2dee66cf94c2 | 87 | float conv_c_to_f(void); |
| i_am_kitsune | 0:2dee66cf94c2 | 88 | |
| i_am_kitsune | 0:2dee66cf94c2 | 89 | /** Read humidity data |
| i_am_kitsune | 0:2dee66cf94c2 | 90 | * @param none |
| i_am_kitsune | 0:2dee66cf94c2 | 91 | * @return humidity |
| i_am_kitsune | 0:2dee66cf94c2 | 92 | */ |
| i_am_kitsune | 0:2dee66cf94c2 | 93 | float humidity(void); |
| i_am_kitsune | 0:2dee66cf94c2 | 94 | |
| i_am_kitsune | 0:2dee66cf94c2 | 95 | /** HDC1000 Configuration |
| i_am_kitsune | 0:2dee66cf94c2 | 96 | * @param none |
| i_am_kitsune | 0:2dee66cf94c2 | 97 | * @return none |
| i_am_kitsune | 0:2dee66cf94c2 | 98 | */ |
| i_am_kitsune | 0:2dee66cf94c2 | 99 | void config(void); |
| i_am_kitsune | 0:2dee66cf94c2 | 100 | |
| i_am_kitsune | 0:2dee66cf94c2 | 101 | /** Read Configuration |
| i_am_kitsune | 0:2dee66cf94c2 | 102 | * @param none |
| i_am_kitsune | 0:2dee66cf94c2 | 103 | * @return config. data |
| i_am_kitsune | 0:2dee66cf94c2 | 104 | */ |
| i_am_kitsune | 0:2dee66cf94c2 | 105 | uint16_t read_config(void); |
| i_am_kitsune | 0:2dee66cf94c2 | 106 | |
| i_am_kitsune | 0:2dee66cf94c2 | 107 | /** Set config register |
| i_am_kitsune | 0:2dee66cf94c2 | 108 | * @param config parameter |
| i_am_kitsune | 0:2dee66cf94c2 | 109 | * @return config read data |
| i_am_kitsune | 0:2dee66cf94c2 | 110 | */ |
| i_am_kitsune | 0:2dee66cf94c2 | 111 | uint16_t set_config(uint16_t cfg); |
| i_am_kitsune | 0:2dee66cf94c2 | 112 | |
| i_am_kitsune | 0:2dee66cf94c2 | 113 | /** Set I2C clock frequency |
| i_am_kitsune | 0:2dee66cf94c2 | 114 | * @param freq. |
| i_am_kitsune | 0:2dee66cf94c2 | 115 | * @return none |
| i_am_kitsune | 0:2dee66cf94c2 | 116 | */ |
| i_am_kitsune | 0:2dee66cf94c2 | 117 | void frequency(int hz); |
| i_am_kitsune | 0:2dee66cf94c2 | 118 | |
| i_am_kitsune | 0:2dee66cf94c2 | 119 | /** check Device ID number |
| i_am_kitsune | 0:2dee66cf94c2 | 120 | * @param none |
| i_am_kitsune | 0:2dee66cf94c2 | 121 | * @return HDC1000 = 1, others 0 |
| i_am_kitsune | 0:2dee66cf94c2 | 122 | */ |
| i_am_kitsune | 0:2dee66cf94c2 | 123 | uint8_t who_am_i(void); |
| i_am_kitsune | 0:2dee66cf94c2 | 124 | |
| i_am_kitsune | 0:2dee66cf94c2 | 125 | /** Read Manufacturer ID |
| i_am_kitsune | 0:2dee66cf94c2 | 126 | * @param none |
| i_am_kitsune | 0:2dee66cf94c2 | 127 | * @return ID |
| i_am_kitsune | 0:2dee66cf94c2 | 128 | */ |
| i_am_kitsune | 0:2dee66cf94c2 | 129 | uint16_t read_M_ID(void); |
| i_am_kitsune | 0:2dee66cf94c2 | 130 | |
| i_am_kitsune | 0:2dee66cf94c2 | 131 | /** Read Device ID |
| i_am_kitsune | 0:2dee66cf94c2 | 132 | * @param none |
| i_am_kitsune | 0:2dee66cf94c2 | 133 | * @return ID |
| i_am_kitsune | 0:2dee66cf94c2 | 134 | */ |
| i_am_kitsune | 0:2dee66cf94c2 | 135 | uint16_t read_D_ID(void); |
| i_am_kitsune | 0:2dee66cf94c2 | 136 | |
| i_am_kitsune | 0:2dee66cf94c2 | 137 | protected: |
| i_am_kitsune | 0:2dee66cf94c2 | 138 | I2C *_i2c_p; |
| i_am_kitsune | 0:2dee66cf94c2 | 139 | I2C &_i2c; |
| i_am_kitsune | 0:2dee66cf94c2 | 140 | |
| i_am_kitsune | 0:2dee66cf94c2 | 141 | void get_IDs(void); |
| i_am_kitsune | 0:2dee66cf94c2 | 142 | void init(void); |
| i_am_kitsune | 0:2dee66cf94c2 | 143 | |
| i_am_kitsune | 0:2dee66cf94c2 | 144 | private: |
| i_am_kitsune | 0:2dee66cf94c2 | 145 | uint8_t HDC1000_addr; |
| i_am_kitsune | 0:2dee66cf94c2 | 146 | uint8_t dt[4]; |
| i_am_kitsune | 0:2dee66cf94c2 | 147 | uint16_t temp; |
| i_am_kitsune | 0:2dee66cf94c2 | 148 | uint16_t humi; |
| i_am_kitsune | 0:2dee66cf94c2 | 149 | uint16_t manufacturer_id_number; |
| i_am_kitsune | 0:2dee66cf94c2 | 150 | uint16_t device_id_number; |
| i_am_kitsune | 0:2dee66cf94c2 | 151 | }; |
| i_am_kitsune | 0:2dee66cf94c2 | 152 | |
| i_am_kitsune | 0:2dee66cf94c2 | 153 | #endif // HDC1000_H |