Library for TMPx75 Temperature Sensor
Diff: TMPx75.h
- Revision:
- 0:ba71558a5d0a
- Child:
- 1:ba7de6d38992
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TMPx75.h Wed Dec 12 21:48:42 2018 +0000 @@ -0,0 +1,95 @@ +/* +Copyright (c) 2018 Jacobus L de Jager + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ + +#ifndef TMPx75_h +#define TMPx75_h + +#include "mbed.h" + +/* +Library for TMP175 and TMP75 Temperature Sensors +For reference, read the datasheet: http://www.ti.com/lit/ds/symlink/tmp75.pdf + +I2C ADDR (TMP75): 1 0 0 1 A2 A1 A0 (1001000 = 0x48) +*/ + +#define TEMPERATURE_REGISTER 0x00 +#define CONFIGURATION_REGISTER 0x01 +#define T_LOW_REGISTER 0x02 +#define T_HIGH_REGISTER 0x03 + +//COnfiguration Register +//Register Byte: OS R1 R0 F1 F0 POL TM SD + +//Default: continuous, comparator, high to low, 1 fault, 9 bits +#define DEFAULT_CONFIG 0x00 + +//Shutdown Mode (SD) +#define CONTINUOUS_MODE 0x00 +#define SHUTDOWN_MODE 0x01 + +//Thermostat Mode (TM) +#define COMPARATOR_MODE 0x00 +#define INTERRUPT_MODE 0x02 + +//Polarity (POL) +#define HIGH_TO_LOW_POL 0x00 +#define LOW_TO_HIGH_POL 0x04 + +//Fault Queue (F1/F0) +#define CONSECUTIVE_FAULTS_1 0x00 +#define CONSECUTIVE_FAULTS_2 0x08 +#define CONSECUTIVE_FAULTS_4 0x10 +#define CONSECUTIVE_FAULTS_6 0x18 + +//Converter Resolution (R1/R0) +#define RESOLUTION_9_BITS 0x00 // (0.5°C) 27.5 ms +#define RESOLUTION_10_BITS 0x20 // (0.25°C) 55 ms +#define RESOLUTION_11_BITS 0x40 // (0.125°C) 110 ms +#define RESOLUTION_12_BITS 0x60 // (0.0625°C) 220 ms + +//One-Shot (OS) +#define ONE_SHOT_MODE 0x80 + + +class TMPx75 +{ +public: + TMPx75(I2C *i2c, uint8_t i2c_addr); + virtual ~TMPx75(); + Serial pc; + + float read_temperature(); + int read_configuration(); + void write_configuration(uint8_t config_byte); + float read_T_LOW(); + void write_T_LOW(float temp); + float read_T_HIGH(); + void write_T_HIGH(float temp); + +private: + I2C *_i2c; + uint8_t _i2c_addr; +}; + +#endif +