ATT example code
Dependencies: WNCInterface mbed-rtos mbed
HTS221.h@0:2bfa06d10e28, 2017-05-22 (annotated)
- Committer:
- surajdagar
- Date:
- Mon May 22 19:50:26 2017 +0000
- Revision:
- 0:2bfa06d10e28
Wireless solution ATT kit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
surajdagar | 0:2bfa06d10e28 | 1 | /* =================================================================== |
surajdagar | 0:2bfa06d10e28 | 2 | Copyright © 2016, AVNET Inc. |
surajdagar | 0:2bfa06d10e28 | 3 | |
surajdagar | 0:2bfa06d10e28 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); |
surajdagar | 0:2bfa06d10e28 | 5 | you may not use this file except in compliance with the License. |
surajdagar | 0:2bfa06d10e28 | 6 | You may obtain a copy of the License at |
surajdagar | 0:2bfa06d10e28 | 7 | |
surajdagar | 0:2bfa06d10e28 | 8 | http://www.apache.org/licenses/LICENSE-2.0 |
surajdagar | 0:2bfa06d10e28 | 9 | |
surajdagar | 0:2bfa06d10e28 | 10 | Unless required by applicable law or agreed to in writing, |
surajdagar | 0:2bfa06d10e28 | 11 | software distributed under the License is distributed on an |
surajdagar | 0:2bfa06d10e28 | 12 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, |
surajdagar | 0:2bfa06d10e28 | 13 | either express or implied. See the License for the specific |
surajdagar | 0:2bfa06d10e28 | 14 | language governing permissions and limitations under the License. |
surajdagar | 0:2bfa06d10e28 | 15 | |
surajdagar | 0:2bfa06d10e28 | 16 | ======================================================================== */ |
surajdagar | 0:2bfa06d10e28 | 17 | |
surajdagar | 0:2bfa06d10e28 | 18 | #ifndef HTS221_H_ |
surajdagar | 0:2bfa06d10e28 | 19 | #define HTS221_H_ |
surajdagar | 0:2bfa06d10e28 | 20 | |
surajdagar | 0:2bfa06d10e28 | 21 | class HTS221 { |
surajdagar | 0:2bfa06d10e28 | 22 | public: |
surajdagar | 0:2bfa06d10e28 | 23 | HTS221(void); |
surajdagar | 0:2bfa06d10e28 | 24 | int init(void); |
surajdagar | 0:2bfa06d10e28 | 25 | int activate(void); |
surajdagar | 0:2bfa06d10e28 | 26 | int deactivate(void); |
surajdagar | 0:2bfa06d10e28 | 27 | |
surajdagar | 0:2bfa06d10e28 | 28 | int bduActivate(void); |
surajdagar | 0:2bfa06d10e28 | 29 | int bduDeactivate(void); |
surajdagar | 0:2bfa06d10e28 | 30 | |
surajdagar | 0:2bfa06d10e28 | 31 | int readHumidity(void); |
surajdagar | 0:2bfa06d10e28 | 32 | double readTemperature(void); |
surajdagar | 0:2bfa06d10e28 | 33 | private: |
surajdagar | 0:2bfa06d10e28 | 34 | int storeCalibration(void); |
surajdagar | 0:2bfa06d10e28 | 35 | unsigned char _h0_rH, _h1_rH; |
surajdagar | 0:2bfa06d10e28 | 36 | unsigned int _T0_degC, _T1_degC; |
surajdagar | 0:2bfa06d10e28 | 37 | unsigned int _H0_T0, _H1_T0; |
surajdagar | 0:2bfa06d10e28 | 38 | unsigned int _T0_OUT, _T1_OUT; |
surajdagar | 0:2bfa06d10e28 | 39 | double _temperature; |
surajdagar | 0:2bfa06d10e28 | 40 | int _humidity; |
surajdagar | 0:2bfa06d10e28 | 41 | unsigned char _address; |
surajdagar | 0:2bfa06d10e28 | 42 | |
surajdagar | 0:2bfa06d10e28 | 43 | unsigned char readRegister(unsigned char slaveAddress, unsigned char regToRead); |
surajdagar | 0:2bfa06d10e28 | 44 | int writeRegister(unsigned char slaveAddress, unsigned char regToWrite, unsigned char dataToWrite); |
surajdagar | 0:2bfa06d10e28 | 45 | }; |
surajdagar | 0:2bfa06d10e28 | 46 | |
surajdagar | 0:2bfa06d10e28 | 47 | #define HTS221_ADDRESS 0xBF |
surajdagar | 0:2bfa06d10e28 | 48 | |
surajdagar | 0:2bfa06d10e28 | 49 | //Define a few of the registers that we will be accessing on the HTS221 |
surajdagar | 0:2bfa06d10e28 | 50 | #define WHO_AM_I 0x0F |
surajdagar | 0:2bfa06d10e28 | 51 | #define WHO_AM_I_RETURN 0xBC //This read-only register contains the device identifier, set to BCh |
surajdagar | 0:2bfa06d10e28 | 52 | |
surajdagar | 0:2bfa06d10e28 | 53 | #define AVERAGE_REG 0x10 // To configure humidity/temperature average. |
surajdagar | 0:2bfa06d10e28 | 54 | #define AVERAGE_DEFAULT 0x1B |
surajdagar | 0:2bfa06d10e28 | 55 | |
surajdagar | 0:2bfa06d10e28 | 56 | /* |
surajdagar | 0:2bfa06d10e28 | 57 | * [7] PD: power down control |
surajdagar | 0:2bfa06d10e28 | 58 | * (0: power-down mode; 1: active mode) |
surajdagar | 0:2bfa06d10e28 | 59 | * |
surajdagar | 0:2bfa06d10e28 | 60 | * [6:3] Reserved |
surajdagar | 0:2bfa06d10e28 | 61 | * |
surajdagar | 0:2bfa06d10e28 | 62 | * [2] BDU: block data update |
surajdagar | 0:2bfa06d10e28 | 63 | * (0: continuous update; 1: output registers not updated until MSB and LSB reading) |
surajdagar | 0:2bfa06d10e28 | 64 | The BDU bit is used to inhibit the output register update between the reading of the upper |
surajdagar | 0:2bfa06d10e28 | 65 | and lower register parts. In default mode (BDU = ?0?), the lower and upper register parts are |
surajdagar | 0:2bfa06d10e28 | 66 | updated continuously. If it is not certain whether the read will be faster than output data rate, |
surajdagar | 0:2bfa06d10e28 | 67 | it is recommended to set the BDU bit to ?1?. In this way, after the reading of the lower (upper) |
surajdagar | 0:2bfa06d10e28 | 68 | register part, the content of that output register is not updated until the upper (lower) part is |
surajdagar | 0:2bfa06d10e28 | 69 | read also. |
surajdagar | 0:2bfa06d10e28 | 70 | * |
surajdagar | 0:2bfa06d10e28 | 71 | * [1:0] ODR1, ODR0: output data rate selection (see table 17) |
surajdagar | 0:2bfa06d10e28 | 72 | */ |
surajdagar | 0:2bfa06d10e28 | 73 | #define CTRL_REG1 0x20 |
surajdagar | 0:2bfa06d10e28 | 74 | #define POWER_UP 0x80 |
surajdagar | 0:2bfa06d10e28 | 75 | #define BDU_SET 0x4 |
surajdagar | 0:2bfa06d10e28 | 76 | #define ODR0_SET 0x1 // setting sensor reading period 1Hz |
surajdagar | 0:2bfa06d10e28 | 77 | |
surajdagar | 0:2bfa06d10e28 | 78 | #define CTRL_REG2 0x21 |
surajdagar | 0:2bfa06d10e28 | 79 | #define CTRL_REG3 0x22 |
surajdagar | 0:2bfa06d10e28 | 80 | #define REG_DEFAULT 0x00 |
surajdagar | 0:2bfa06d10e28 | 81 | |
surajdagar | 0:2bfa06d10e28 | 82 | #define STATUS_REG 0x27 |
surajdagar | 0:2bfa06d10e28 | 83 | #define TEMPERATURE_READY 0x1 |
surajdagar | 0:2bfa06d10e28 | 84 | #define HUMIDITY_READY 0x2 |
surajdagar | 0:2bfa06d10e28 | 85 | |
surajdagar | 0:2bfa06d10e28 | 86 | #define HUMIDITY_L_REG 0x28 |
surajdagar | 0:2bfa06d10e28 | 87 | #define HUMIDITY_H_REG 0x29 |
surajdagar | 0:2bfa06d10e28 | 88 | #define TEMP_L_REG 0x2A |
surajdagar | 0:2bfa06d10e28 | 89 | #define TEMP_H_REG 0x2B |
surajdagar | 0:2bfa06d10e28 | 90 | /* |
surajdagar | 0:2bfa06d10e28 | 91 | * calibration registry should be read for temperature and humidity calculation. |
surajdagar | 0:2bfa06d10e28 | 92 | * Before the first calculation of temperature and humidity, |
surajdagar | 0:2bfa06d10e28 | 93 | * the master reads out the calibration coefficients. |
surajdagar | 0:2bfa06d10e28 | 94 | * will do at init phase |
surajdagar | 0:2bfa06d10e28 | 95 | */ |
surajdagar | 0:2bfa06d10e28 | 96 | #define CALIB_START 0x30 |
surajdagar | 0:2bfa06d10e28 | 97 | #define CALIB_END 0x3F |
surajdagar | 0:2bfa06d10e28 | 98 | /* |
surajdagar | 0:2bfa06d10e28 | 99 | #define CALIB_T0_DEGC_X8 0x32 |
surajdagar | 0:2bfa06d10e28 | 100 | #define CALIB_T1_DEGC_X8 0x33 |
surajdagar | 0:2bfa06d10e28 | 101 | #define CALIB_T1_T0_MSB 0x35 |
surajdagar | 0:2bfa06d10e28 | 102 | #define CALIB_T0_OUT_L 0x3C |
surajdagar | 0:2bfa06d10e28 | 103 | #define CALIB_T0_OUT_H 0x3D |
surajdagar | 0:2bfa06d10e28 | 104 | #define CALIB_T1_OUT_L 0x3E |
surajdagar | 0:2bfa06d10e28 | 105 | #define CALIB_T1_OUT_H 0x3F |
surajdagar | 0:2bfa06d10e28 | 106 | */ |
surajdagar | 0:2bfa06d10e28 | 107 | |
surajdagar | 0:2bfa06d10e28 | 108 | #endif |