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: MAXREFDES131_Qt_Demo MAX32630FTHR_iButton_uSD_Logger MAX32630FTHR_DS18B20_uSD_Logger MAXREFDES130_131_Demo ... more
DS18B20.h
00001 /******************************************************************//** 00002 * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. 00003 * 00004 * Permission is hereby granted, free of charge, to any person obtaining a 00005 * copy of this software and associated documentation files (the "Software"), 00006 * to deal in the Software without restriction, including without limitation 00007 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 00008 * and/or sell copies of the Software, and to permit persons to whom the 00009 * Software is furnished to do so, subject to the following conditions: 00010 * 00011 * The above copyright notice and this permission notice shall be included 00012 * in all copies or substantial portions of the Software. 00013 * 00014 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 00015 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 00016 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 00017 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES 00018 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 00019 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 00020 * OTHER DEALINGS IN THE SOFTWARE. 00021 * 00022 * Except as contained in this notice, the name of Maxim Integrated 00023 * Products, Inc. shall not be used except as stated in the Maxim Integrated 00024 * Products, Inc. Branding Policy. 00025 * 00026 * The mere transfer of this software does not imply any licenses 00027 * of trade secrets, proprietary technology, copyrights, patents, 00028 * trademarks, maskwork rights, or any other form of intellectual 00029 * property whatsoever. Maxim Integrated Products, Inc. retains all 00030 * ownership rights. 00031 **********************************************************************/ 00032 00033 #ifndef OneWire_Slaves_Sensors_DS18B20 00034 #define OneWire_Slaves_Sensors_DS18B20 00035 00036 #include "Slaves/OneWireSlave.h" 00037 00038 namespace OneWire 00039 { 00040 class OneWireMaster; 00041 00042 /** 00043 * @brief DS18B20 Programmable Resolution 1-Wire Digital Thermometer 00044 * 00045 * @details The DS18B20 digital thermometer provides 9-bit to 12-bit 00046 * Celsius temperature measurements and has an alarm function with 00047 * nonvolatile user-programmable upper and lower trigger points. The 00048 * DS18B20 communicates over a 1-Wire bus that by definition requires 00049 * only one data line (and ground) for communication with a central 00050 * microprocessor. In addition, the DS18B20 can derive power directly 00051 * from the data line ("parasite power"), eliminating the need for an 00052 * external power supply. 00053 * 00054 * @code 00055 * @endcode 00056 */ 00057 class DS18B20 : public OneWireSlave 00058 { 00059 public: 00060 00061 ///Available resolutions of the DS18B20 00062 enum Resolution 00063 { 00064 NineBit = 0x1F, 00065 TenBit = 0x3F, 00066 ElevenBit = 0x5F, 00067 TwelveBit = 0x7F 00068 }; 00069 00070 /**********************************************************//** 00071 * @brief DS18B20 constructor 00072 * 00073 * @details 00074 * 00075 * On Entry: 00076 * @param[in] selector - Reference to RandomAccessRomiteraor 00077 * object that encapsulates owm master that has access to this 00078 * device and ROM function commands used to a select device 00079 * 00080 * On Exit: 00081 * 00082 * @return 00083 **************************************************************/ 00084 DS18B20(RandomAccessRomIterator &selector); 00085 00086 00087 /**********************************************************//** 00088 * @brief Write Scratchpad Command 00089 * 00090 * @details If the result of a temperature measurement is higher 00091 * than TH or lower than TL, an alarm flag inside the device is 00092 * set. This flag is updated with every temperature measurement. 00093 * As long as the alarm flag is set, the DS1920 will respond to 00094 * the alarm search command. 00095 * 00096 * On Entry: 00097 * @param[in] th - 8-bit upper temperature threshold, MSB 00098 * indicates sign 00099 * @param[in] tl - 8-bit lower temperature threshold, LSB 00100 * indicates sign 00101 * @param[in] res - Resolution of the DS18B20 00102 * 00103 * On Exit: 00104 * @param[out] 00105 * 00106 * @return CmdResult - result of operation 00107 **************************************************************/ 00108 OneWireSlave::CmdResult writeScratchPad(uint8_t th, uint8_t tl, Resolution res); 00109 00110 00111 /**********************************************************//** 00112 * @brief Read Scratchpad Command 00113 * 00114 * @details This command reads the complete scratchpad. 00115 * 00116 * On Entry: 00117 * @param[in] scratchPadBuff - array for receiving contents of 00118 * scratchpad, this buffer will be over written 00119 * 00120 * On Exit: 00121 * @param[out] scratchPadBuff - contents of scratchpad 00122 * 00123 * @return CmdResult - result of operation 00124 **************************************************************/ 00125 OneWireSlave::CmdResult readScratchPad(uint8_t * scratchPadBuff); 00126 00127 /**********************************************************//** 00128 * @brief Copy Scratchpad Command 00129 * 00130 * @details This command copies from the scratchpad into the 00131 * EEPROM of the DS18B20, storing the temperature trigger bytes 00132 * and resolution in nonvolatile memory. 00133 * 00134 * On Entry: 00135 * @param[in] 00136 * 00137 * On Exit: 00138 * @param[out] 00139 * 00140 * @return CmdResult - result of operation 00141 **************************************************************/ 00142 OneWireSlave::CmdResult copyScratchPad( void ); 00143 00144 00145 /**********************************************************//** 00146 * @brief Read Power Supply command 00147 * 00148 * @details This command determines if the DS18B20 is parasite 00149 * powered or has a local supply 00150 * 00151 * On Entry: 00152 * @param[in] 00153 * 00154 * On Exit: 00155 * @param[out] localPower - Will be False on exit if the DS18B20 00156 * is parasite powered 00157 * 00158 * @return CmdResult - result of operation 00159 **************************************************************/ 00160 OneWireSlave::CmdResult readPowerSupply(bool & localPower); 00161 00162 00163 /**********************************************************//** 00164 * @brief Convert Temperature Command 00165 * 00166 * @details This command begins a temperature conversion. 00167 * 00168 * On Entry: 00169 * @param[in] 00170 * 00171 * On Exit: 00172 * @param[out] temp - temperature conversion results 00173 * 00174 * @return CmdResult - result of operation 00175 **************************************************************/ 00176 OneWireSlave::CmdResult convertTemperature(float & temp); 00177 00178 00179 /**********************************************************//** 00180 * @brief Recall Command 00181 * 00182 * @details This command recalls the temperature trigger values 00183 * and resolution stored in EEPROM to the scratchpad 00184 * 00185 * On Entry: 00186 * @param[in] 00187 * 00188 * On Exit: 00189 * @param[out] 00190 * 00191 * @return CmdResult - result of operation 00192 **************************************************************/ 00193 OneWireSlave::CmdResult recallEEPROM( void ); 00194 00195 }; 00196 } 00197 00198 #endif /* OneWire_Slaves_Sensors_DS18B20 */
Generated on Tue Jul 12 2022 15:46:20 by
