A library for STMicroelectronics STTS751 I2C temperature sensor
STTS751.h@1:b0a3645a3dba, 2014-01-18 (annotated)
- Committer:
- takuo
- Date:
- Sat Jan 18 02:31:12 2014 +0000
- Revision:
- 1:b0a3645a3dba
- Parent:
- 0:4211e78bfa5d
- Child:
- 2:3116fe4a0079
Fixed the documents
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
takuo | 1:b0a3645a3dba | 1 | /* A library for STMicroelectronics STTS751 I2C temperature sensor |
takuo | 0:4211e78bfa5d | 2 | * Copyright 2014, Takuo WATANABE (wtakuo) |
takuo | 0:4211e78bfa5d | 3 | * |
takuo | 0:4211e78bfa5d | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
takuo | 0:4211e78bfa5d | 5 | * you may not use this file except in compliance with the License. |
takuo | 0:4211e78bfa5d | 6 | * You may obtain a copy of the License at |
takuo | 0:4211e78bfa5d | 7 | * |
takuo | 0:4211e78bfa5d | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
takuo | 0:4211e78bfa5d | 9 | * |
takuo | 0:4211e78bfa5d | 10 | * Unless required by applicable law or agreed to in writing, software |
takuo | 0:4211e78bfa5d | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
takuo | 0:4211e78bfa5d | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
takuo | 0:4211e78bfa5d | 13 | * See the License for the specific language governing permissions and |
takuo | 0:4211e78bfa5d | 14 | * limitations under the License. |
takuo | 0:4211e78bfa5d | 15 | */ |
takuo | 0:4211e78bfa5d | 16 | |
takuo | 0:4211e78bfa5d | 17 | #ifndef STTS751_H |
takuo | 0:4211e78bfa5d | 18 | #define STTS751_H |
takuo | 0:4211e78bfa5d | 19 | |
takuo | 0:4211e78bfa5d | 20 | #include "mbed.h" |
takuo | 0:4211e78bfa5d | 21 | |
takuo | 0:4211e78bfa5d | 22 | /** A library for STMicroelectronics STTS751 I2C temperature sensor |
takuo | 0:4211e78bfa5d | 23 | * http://www.st.com/web/catalog/sense_power/FM89/SC294/PF220116 |
takuo | 0:4211e78bfa5d | 24 | * |
takuo | 0:4211e78bfa5d | 25 | * Example: |
takuo | 0:4211e78bfa5d | 26 | * @code |
takuo | 0:4211e78bfa5d | 27 | * #include "mbed.h" |
takuo | 0:4211e78bfa5d | 28 | * |
takuo | 0:4211e78bfa5d | 29 | * // I2C Text LCD: http://mbed.org/users/takuo/code/ACM1602NI/ |
takuo | 0:4211e78bfa5d | 30 | * #include "ACM1602NI.h" |
takuo | 0:4211e78bfa5d | 31 | * // I2C Temperature Sensor: http://mbed.org/users/takuo/code/STTS751/ |
takuo | 0:4211e78bfa5d | 32 | * #include "STTS751.h" |
takuo | 0:4211e78bfa5d | 33 | * |
takuo | 0:4211e78bfa5d | 34 | * // I2C pins: p9 = sda, p10 = scl |
takuo | 0:4211e78bfa5d | 35 | * ACM1602NI lcd(p9, p10); |
takuo | 0:4211e78bfa5d | 36 | * STTS751 temp(p9, p10); |
takuo | 0:4211e78bfa5d | 37 | * |
takuo | 0:4211e78bfa5d | 38 | * // You can specify an I2C object instead. |
takuo | 0:4211e78bfa5d | 39 | * // I2C i2c(p2, p10); |
takuo | 0:4211e78bfa5d | 40 | * // ACM1602NI lcd(i2c); |
takuo | 0:4211e78bfa5d | 41 | * // STTS751 temp(i2c); |
takuo | 0:4211e78bfa5d | 42 | * |
takuo | 0:4211e78bfa5d | 43 | * int main() { |
takuo | 0:4211e78bfa5d | 44 | * while (true) { |
takuo | 0:4211e78bfa5d | 45 | * lcd.locate(0, 0); |
takuo | 0:4211e78bfa5d | 46 | * lcd.printf("tmp: %.3f", (float)temp); |
takuo | 0:4211e78bfa5d | 47 | * wait(1); |
takuo | 0:4211e78bfa5d | 48 | * } |
takuo | 0:4211e78bfa5d | 49 | * } |
takuo | 0:4211e78bfa5d | 50 | * @endcode |
takuo | 0:4211e78bfa5d | 51 | */ |
takuo | 0:4211e78bfa5d | 52 | class STTS751 |
takuo | 0:4211e78bfa5d | 53 | { |
takuo | 0:4211e78bfa5d | 54 | public: |
takuo | 0:4211e78bfa5d | 55 | /** Device models |
takuo | 0:4211e78bfa5d | 56 | */ |
takuo | 0:4211e78bfa5d | 57 | enum Model { |
takuo | 0:4211e78bfa5d | 58 | MODEL_0 = 0x00, /**< Model 0 (default) */ |
takuo | 0:4211e78bfa5d | 59 | MODEL_1 = 0x40 /**< Model 1 */ |
takuo | 0:4211e78bfa5d | 60 | }; |
takuo | 0:4211e78bfa5d | 61 | |
takuo | 0:4211e78bfa5d | 62 | /** I2C addresses |
takuo | 0:4211e78bfa5d | 63 | */ |
takuo | 0:4211e78bfa5d | 64 | enum Address { |
takuo | 0:4211e78bfa5d | 65 | ADDRESS_0 = (0x48 << 1), /**< pull up resistor = 7.5K */ |
takuo | 0:4211e78bfa5d | 66 | ADDRESS_1 = (0x49 << 1), /**< pull up resistor = 12K */ |
takuo | 0:4211e78bfa5d | 67 | ADDRESS_2 = (0x38 << 1), /**< pull up resistor = 20K */ |
takuo | 0:4211e78bfa5d | 68 | ADDRESS_3 = (0x39 << 1) /**< pull up resistor = 33K or GND (default) */ |
takuo | 0:4211e78bfa5d | 69 | }; |
takuo | 0:4211e78bfa5d | 70 | |
takuo | 0:4211e78bfa5d | 71 | /** Create an STTS751 object connected to the specified I2C pins. |
takuo | 0:4211e78bfa5d | 72 | * |
takuo | 0:4211e78bfa5d | 73 | * @param sda I2C data pin |
takuo | 0:4211e78bfa5d | 74 | * @param scl I2C clock pin |
takuo | 0:4211e78bfa5d | 75 | * @param addr I2C slave address (defaults to ADDRESS_3) |
takuo | 0:4211e78bfa5d | 76 | * @param model Device model (defaults to MODEL_0) |
takuo | 0:4211e78bfa5d | 77 | */ |
takuo | 0:4211e78bfa5d | 78 | STTS751(PinName sda, PinName scl, Address addr = ADDRESS_3, Model model = MODEL_0); |
takuo | 0:4211e78bfa5d | 79 | |
takuo | 0:4211e78bfa5d | 80 | /** Create an STTS751 object connected to the specified I2C port. |
takuo | 0:4211e78bfa5d | 81 | * |
takuo | 0:4211e78bfa5d | 82 | * @param i2c I2C port |
takuo | 0:4211e78bfa5d | 83 | * @param addr I2C slave address (defaults to ADDRESS_3) |
takuo | 0:4211e78bfa5d | 84 | * @param model Device model (defaults to MODEL_0) |
takuo | 0:4211e78bfa5d | 85 | */ |
takuo | 0:4211e78bfa5d | 86 | STTS751(I2C &_i2c, Address addr = ADDRESS_3, Model model = MODEL_0); |
takuo | 0:4211e78bfa5d | 87 | |
takuo | 0:4211e78bfa5d | 88 | /** Obtain the current temperature measurement |
takuo | 0:4211e78bfa5d | 89 | * |
takuo | 0:4211e78bfa5d | 90 | * @returns The current temperature measurement in Celsius. |
takuo | 0:4211e78bfa5d | 91 | */ |
takuo | 0:4211e78bfa5d | 92 | float temp(); |
takuo | 0:4211e78bfa5d | 93 | |
takuo | 0:4211e78bfa5d | 94 | #ifdef MBED_OPERATORS |
takuo | 0:4211e78bfa5d | 95 | /** A shorthand for temp() |
takuo | 0:4211e78bfa5d | 96 | * |
takuo | 0:4211e78bfa5d | 97 | * @returns The current temperature measurement in Celsius. |
takuo | 0:4211e78bfa5d | 98 | */ |
takuo | 0:4211e78bfa5d | 99 | operator float(); |
takuo | 0:4211e78bfa5d | 100 | #endif |
takuo | 0:4211e78bfa5d | 101 | |
takuo | 0:4211e78bfa5d | 102 | protected: |
takuo | 0:4211e78bfa5d | 103 | enum Register { |
takuo | 0:4211e78bfa5d | 104 | REG_TEMPERATURE_H = 0x00, |
takuo | 0:4211e78bfa5d | 105 | REG_STATUS = 0x01, |
takuo | 0:4211e78bfa5d | 106 | REG_TEMPERATURE_L = 0x02, |
takuo | 0:4211e78bfa5d | 107 | REG_CONFIGURATION = 0x03, |
takuo | 0:4211e78bfa5d | 108 | REG_CONV_RATE = 0x04, |
takuo | 0:4211e78bfa5d | 109 | REG_HIGH_LIMIT_H = 0x05, |
takuo | 0:4211e78bfa5d | 110 | REG_HIGH_LIMIT_L = 0x06, |
takuo | 0:4211e78bfa5d | 111 | REG_LOW_LIMIT_H = 0x07, |
takuo | 0:4211e78bfa5d | 112 | REG_LOW_LIMIT_L = 0x08, |
takuo | 0:4211e78bfa5d | 113 | REG_ONESHOT = 0x0f, |
takuo | 0:4211e78bfa5d | 114 | REG_THERM = 0x20, |
takuo | 0:4211e78bfa5d | 115 | REG_THERM_HYSTERESIS = 0x21, |
takuo | 0:4211e78bfa5d | 116 | REG_SMBUS_TIMEOUT = 0x22, |
takuo | 0:4211e78bfa5d | 117 | REG_PRODUCT_ID = 0xfd, |
takuo | 0:4211e78bfa5d | 118 | REG_MFG_ID = 0xfe, |
takuo | 0:4211e78bfa5d | 119 | REG_REVISION_ID = 0xff |
takuo | 0:4211e78bfa5d | 120 | }; |
takuo | 0:4211e78bfa5d | 121 | |
takuo | 0:4211e78bfa5d | 122 | I2C _i2c; |
takuo | 0:4211e78bfa5d | 123 | const int _addr; |
takuo | 0:4211e78bfa5d | 124 | |
takuo | 0:4211e78bfa5d | 125 | void init(); |
takuo | 0:4211e78bfa5d | 126 | char read8(char reg); |
takuo | 0:4211e78bfa5d | 127 | }; |
takuo | 0:4211e78bfa5d | 128 | |
takuo | 0:4211e78bfa5d | 129 | #endif |