FRDM-K64F, Avnet M14A2A, Grove Shield, to create smart home system. In use with AT&Ts M2x & Flow.
Dependencies: mbed FXOS8700CQ MODSERIAL
HTS221.h
00001 /* =================================================================== 00002 Copyright © 2016, AVNET Inc. 00003 00004 Licensed under the Apache License, Version 2.0 (the "License"); 00005 you may not use this file except in compliance with the License. 00006 You may obtain a copy of the License at 00007 00008 http://www.apache.org/licenses/LICENSE-2.0 00009 00010 Unless required by applicable law or agreed to in writing, 00011 software distributed under the License is distributed on an 00012 "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 00013 either express or implied. See the License for the specific 00014 language governing permissions and limitations under the License. 00015 00016 ======================================================================== */ 00017 00018 #ifndef HTS221_H_ 00019 #define HTS221_H_ 00020 00021 class HTS221 { 00022 public: 00023 HTS221(void); 00024 int begin(void); 00025 int activate(void); 00026 int deactivate(void); 00027 00028 int bduActivate(void); 00029 int bduDeactivate(void); 00030 00031 int readHumidity(void); 00032 double readTemperature(void); 00033 private: 00034 int storeCalibration(void); 00035 unsigned char _h0_rH, _h1_rH; 00036 unsigned int _T0_degC, _T1_degC; 00037 unsigned int _H0_T0, _H1_T0; 00038 unsigned int _T0_OUT, _T1_OUT; 00039 double _temperature; 00040 int _humidity; 00041 unsigned char _address; 00042 00043 unsigned char readRegister(unsigned char slaveAddress, unsigned char regToRead); 00044 int writeRegister(unsigned char slaveAddress, unsigned char regToWrite, unsigned char dataToWrite); 00045 }; 00046 00047 #define HTS221_ADDRESS 0xBF 00048 00049 //Define a few of the registers that we will be accessing on the HTS221 00050 #define WHO_AM_I 0x0F 00051 #define WHO_AM_I_RETURN 0xBC //This read-only register contains the device identifier, set to BCh 00052 00053 #define AVERAGE_REG 0x10 // To configure humidity/temperature average. 00054 #define AVERAGE_DEFAULT 0x1B 00055 00056 /* 00057 * [7] PD: power down control 00058 * (0: power-down mode; 1: active mode) 00059 * 00060 * [6:3] Reserved 00061 * 00062 * [2] BDU: block data update 00063 * (0: continuous update; 1: output registers not updated until MSB and LSB reading) 00064 The BDU bit is used to inhibit the output register update between the reading of the upper 00065 and lower register parts. In default mode (BDU = ?0?), the lower and upper register parts are 00066 updated continuously. If it is not certain whether the read will be faster than output data rate, 00067 it is recommended to set the BDU bit to ?1?. In this way, after the reading of the lower (upper) 00068 register part, the content of that output register is not updated until the upper (lower) part is 00069 read also. 00070 * 00071 * [1:0] ODR1, ODR0: output data rate selection (see table 17) 00072 */ 00073 #define CTRL_REG1 0x20 00074 #define POWER_UP 0x80 00075 #define BDU_SET 0x4 00076 #define ODR0_SET 0x1 // setting sensor reading period 1Hz 00077 00078 #define CTRL_REG2 0x21 00079 #define CTRL_REG3 0x22 00080 #define REG_DEFAULT 0x00 00081 00082 #define STATUS_REG 0x27 00083 #define TEMPERATURE_READY 0x1 00084 #define HUMIDITY_READY 0x2 00085 00086 #define HUMIDITY_L_REG 0x28 00087 #define HUMIDITY_H_REG 0x29 00088 #define TEMP_L_REG 0x2A 00089 #define TEMP_H_REG 0x2B 00090 /* 00091 * calibration registry should be read for temperature and humidity calculation. 00092 * Before the first calculation of temperature and humidity, 00093 * the master reads out the calibration coefficients. 00094 * will do at init phase 00095 */ 00096 #define CALIB_START 0x30 00097 #define CALIB_END 0x3F 00098 /* 00099 #define CALIB_T0_DEGC_X8 0x32 00100 #define CALIB_T1_DEGC_X8 0x33 00101 #define CALIB_T1_T0_MSB 0x35 00102 #define CALIB_T0_OUT_L 0x3C 00103 #define CALIB_T0_OUT_H 0x3D 00104 #define CALIB_T1_OUT_L 0x3E 00105 #define CALIB_T1_OUT_H 0x3F 00106 */ 00107 00108 #endif
Generated on Wed Jul 13 2022 15:25:27 by 1.7.2