Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: ou_OLED_TMP102 ou_mbed_tmp102
test_TMP102.h
00001 /** A practice code for class library development 00002 * 00003 * @author Yasubumi KANAZAWA 00004 * @version 1.0 00005 * @date 26-Nov-2017 00006 * 00007 * This code is plactice of the class code development. 00008 * The sample is a I2C temperature sensor TMP102. 00009 * 00010 * Reference page 00011 * https://os.mbed.com/users/okano/notebook/mbed-library-study-meeting-2014-nov-07/" 00012 * 00013 * About TMP102: 00014 * http://www.sparkfun.com/datasheets/Sensors/Temperature/tmp102.pdf 00015 * 00016 * 00017 * extended by Poushen Ou to provide more API function 00018 * 17-Jul-2018 00019 * 00020 */ 00021 00022 #include "mbed.h" 00023 00024 /** Default slave address(ADD0 connected to GND) */ 00025 #define ADDR_TMP102 0x90 00026 00027 /** TMP102 register names and addresses */ 00028 #define TMP102_Temp 0x00 00029 #define TMP102_Conf 0x01 00030 #define TMP102_Tlow 0x02 00031 #define TMP102_Thigh 0x03 00032 00033 /** test_TMP102 Class Library 00034 * to provide very simple interface for mbed 00035 * 00036 * Example: 00037 * @code 00038 * #include "mbed.h" 00039 * #include "test_TMP102.h" 00040 * 00041 * // make test_TMP102 instance using GPIO pin name. 00042 * test_TMP102 temp0(dp4,dp5); 00043 * 00044 * // make test_TMP102 instance using I2C object. 00045 * I2C i2c(dp4,dp5); 00046 * test_TMP102 temp1(i2c); 00047 * 00048 * int main() 00049 * { 00050 * float t0,t1; 00051 * 00052 * i2c.frequency(400*1000); 00053 * 00054 * while(1) { 00055 * t0=temp0; 00056 * t1=temp1; 00057 * printf("Temp: %7.3f, %7.3f\r\n", t0, t1); 00058 * wait(1.0); 00059 * } 00060 * } 00061 * @endcode 00062 */ 00063 class test_TMP102 00064 { 00065 public: 00066 /** Create a test_TMP102 instance connected to specified I2C pins with specified address 00067 * 00068 * @param sda I2C-bus SDA pin 00069 * @param scl I2C-bus SCL pin 00070 * @param address (option) I2C-bus slave address (default: 0x90) 00071 */ 00072 test_TMP102(PinName sda, PinName scl, char address = ADDR_TMP102); 00073 00074 /** Create a test_TMP102 instance connected to specified I2C pins with specified address 00075 * 00076 * @param i2c_obj I2C object (instance) 00077 * @param address (option) I2C-bus slave address (default: 0x90) 00078 */ 00079 test_TMP102(I2C &i2c_obj, char address = ADDR_TMP102); 00080 00081 /** Destractor */ 00082 ~test_TMP102(); 00083 00084 /** Initialization */ 00085 void init(void); 00086 00087 /** Read temperature 00088 * 00089 * @return value of degree Celsius (in float) 00090 */ 00091 float read(void); 00092 00093 /** Read temperature 00094 * 00095 * @return value of degree C (in float) 00096 */ 00097 float readTempC(void); 00098 00099 /** Read temperature 00100 * 00101 * @return value of degree F (in float) 00102 */ 00103 float readTempF(void); 00104 00105 /** Read temperature 00106 * 00107 * @return the object returns the read value 00108 */ 00109 operator float(void); 00110 00111 /** Set the conversion rate (0-3) 00112 * 00113 * @param rate Conversion Rate 00114 * 0 - 0.25Hz 00115 * 1 - 1 Hz 00116 * 2 - 4 Hz (default) 00117 * 3 - 8 Hz 00118 */ 00119 void setConversionRate(char rate); 00120 00121 /** Enable or disable extened mode 00122 * 00123 * @param mode Extend Mode (0 disable, 1 enabled) 00124 * 00125 */ 00126 void setExtendedMode(bool mode); 00127 00128 /** Switch sensor to low power mode */ 00129 void sleep(void); 00130 00131 /** Wakeup and start running in normal power mode */ 00132 void wakeup(void); 00133 00134 /** enter One-Shot mode, and wait for temperature sample complete (about 26ms) */ 00135 void oneShot(void); 00136 00137 private: 00138 I2C *i2c_p; 00139 I2C &i2c; 00140 char adr; 00141 };
Generated on Sat Jul 16 2022 01:40:29 by
1.7.2