Implementation of 1-Wire with added Alarm Search Functionality
Dependents: Max32630_One_Wire_Interface
Slaves/Sensors/DS18B20/DS18B20.h@142:85b71cfd617e, 2019-08-13 (annotated)
- Committer:
- mfruge
- Date:
- Tue Aug 13 14:42:37 2019 +0000
- Revision:
- 142:85b71cfd617e
- Parent:
- 105:e6ba25711c05
Added functions to ROMCommands to add Alarm Search functionality
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
j3 | 101:e7f76cb49584 | 1 | /******************************************************************//** |
j3 | 101:e7f76cb49584 | 2 | * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. |
j3 | 101:e7f76cb49584 | 3 | * |
j3 | 101:e7f76cb49584 | 4 | * Permission is hereby granted, free of charge, to any person obtaining a |
j3 | 101:e7f76cb49584 | 5 | * copy of this software and associated documentation files (the "Software"), |
j3 | 101:e7f76cb49584 | 6 | * to deal in the Software without restriction, including without limitation |
j3 | 101:e7f76cb49584 | 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
j3 | 101:e7f76cb49584 | 8 | * and/or sell copies of the Software, and to permit persons to whom the |
j3 | 101:e7f76cb49584 | 9 | * Software is furnished to do so, subject to the following conditions: |
j3 | 101:e7f76cb49584 | 10 | * |
j3 | 101:e7f76cb49584 | 11 | * The above copyright notice and this permission notice shall be included |
j3 | 101:e7f76cb49584 | 12 | * in all copies or substantial portions of the Software. |
j3 | 101:e7f76cb49584 | 13 | * |
j3 | 101:e7f76cb49584 | 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
j3 | 101:e7f76cb49584 | 15 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
j3 | 101:e7f76cb49584 | 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
j3 | 101:e7f76cb49584 | 17 | * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES |
j3 | 101:e7f76cb49584 | 18 | * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
j3 | 101:e7f76cb49584 | 19 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
j3 | 101:e7f76cb49584 | 20 | * OTHER DEALINGS IN THE SOFTWARE. |
j3 | 101:e7f76cb49584 | 21 | * |
j3 | 101:e7f76cb49584 | 22 | * Except as contained in this notice, the name of Maxim Integrated |
j3 | 101:e7f76cb49584 | 23 | * Products, Inc. shall not be used except as stated in the Maxim Integrated |
j3 | 101:e7f76cb49584 | 24 | * Products, Inc. Branding Policy. |
j3 | 101:e7f76cb49584 | 25 | * |
j3 | 101:e7f76cb49584 | 26 | * The mere transfer of this software does not imply any licenses |
j3 | 101:e7f76cb49584 | 27 | * of trade secrets, proprietary technology, copyrights, patents, |
j3 | 101:e7f76cb49584 | 28 | * trademarks, maskwork rights, or any other form of intellectual |
j3 | 101:e7f76cb49584 | 29 | * property whatsoever. Maxim Integrated Products, Inc. retains all |
j3 | 101:e7f76cb49584 | 30 | * ownership rights. |
j3 | 101:e7f76cb49584 | 31 | **********************************************************************/ |
j3 | 101:e7f76cb49584 | 32 | |
j3 | 101:e7f76cb49584 | 33 | #ifndef OneWire_Slaves_Sensors_DS18B20 |
j3 | 101:e7f76cb49584 | 34 | #define OneWire_Slaves_Sensors_DS18B20 |
j3 | 101:e7f76cb49584 | 35 | |
j3 | 104:3f48daed532b | 36 | #include "Slaves/OneWireSlave.h" |
j3 | 101:e7f76cb49584 | 37 | |
j3 | 101:e7f76cb49584 | 38 | namespace OneWire |
j3 | 101:e7f76cb49584 | 39 | { |
j3 | 101:e7f76cb49584 | 40 | class OneWireMaster; |
j3 | 101:e7f76cb49584 | 41 | |
j3 | 101:e7f76cb49584 | 42 | /** |
j3 | 101:e7f76cb49584 | 43 | * @brief DS18B20 Programmable Resolution 1-Wire Digital Thermometer |
j3 | 101:e7f76cb49584 | 44 | * |
j3 | 101:e7f76cb49584 | 45 | * @details The DS18B20 digital thermometer provides 9-bit to 12-bit |
j3 | 101:e7f76cb49584 | 46 | * Celsius temperature measurements and has an alarm function with |
j3 | 101:e7f76cb49584 | 47 | * nonvolatile user-programmable upper and lower trigger points. The |
j3 | 101:e7f76cb49584 | 48 | * DS18B20 communicates over a 1-Wire bus that by definition requires |
j3 | 101:e7f76cb49584 | 49 | * only one data line (and ground) for communication with a central |
j3 | 101:e7f76cb49584 | 50 | * microprocessor. In addition, the DS18B20 can derive power directly |
j3 | 101:e7f76cb49584 | 51 | * from the data line ("parasite power"), eliminating the need for an |
j3 | 101:e7f76cb49584 | 52 | * external power supply. |
j3 | 101:e7f76cb49584 | 53 | * |
j3 | 101:e7f76cb49584 | 54 | * @code |
j3 | 101:e7f76cb49584 | 55 | * @endcode |
j3 | 101:e7f76cb49584 | 56 | */ |
j3 | 101:e7f76cb49584 | 57 | class DS18B20 : public OneWireSlave |
j3 | 101:e7f76cb49584 | 58 | { |
j3 | 101:e7f76cb49584 | 59 | public: |
j3 | 101:e7f76cb49584 | 60 | |
j3 | 101:e7f76cb49584 | 61 | ///Available resolutions of the DS18B20 |
j3 | 101:e7f76cb49584 | 62 | enum Resolution |
j3 | 101:e7f76cb49584 | 63 | { |
j3 | 105:e6ba25711c05 | 64 | NineBit = 0x1F, |
j3 | 105:e6ba25711c05 | 65 | TenBit = 0x3F, |
j3 | 105:e6ba25711c05 | 66 | ElevenBit = 0x5F, |
j3 | 105:e6ba25711c05 | 67 | TwelveBit = 0x7F |
j3 | 101:e7f76cb49584 | 68 | }; |
j3 | 101:e7f76cb49584 | 69 | |
j3 | 101:e7f76cb49584 | 70 | /**********************************************************//** |
j3 | 101:e7f76cb49584 | 71 | * @brief DS18B20 constructor |
j3 | 101:e7f76cb49584 | 72 | * |
j3 | 101:e7f76cb49584 | 73 | * @details |
j3 | 101:e7f76cb49584 | 74 | * |
j3 | 101:e7f76cb49584 | 75 | * On Entry: |
j3 | 101:e7f76cb49584 | 76 | * @param[in] selector - Reference to RandomAccessRomiteraor |
j3 | 101:e7f76cb49584 | 77 | * object that encapsulates owm master that has access to this |
j3 | 101:e7f76cb49584 | 78 | * device and ROM function commands used to a select device |
j3 | 101:e7f76cb49584 | 79 | * |
j3 | 101:e7f76cb49584 | 80 | * On Exit: |
j3 | 101:e7f76cb49584 | 81 | * |
j3 | 101:e7f76cb49584 | 82 | * @return |
j3 | 101:e7f76cb49584 | 83 | **************************************************************/ |
j3 | 101:e7f76cb49584 | 84 | DS18B20(RandomAccessRomIterator &selector); |
j3 | 101:e7f76cb49584 | 85 | |
j3 | 101:e7f76cb49584 | 86 | |
j3 | 101:e7f76cb49584 | 87 | /**********************************************************//** |
j3 | 101:e7f76cb49584 | 88 | * @brief Write Scratchpad Command |
j3 | 101:e7f76cb49584 | 89 | * |
j3 | 101:e7f76cb49584 | 90 | * @details If the result of a temperature measurement is higher |
j3 | 101:e7f76cb49584 | 91 | * than TH or lower than TL, an alarm flag inside the device is |
j3 | 101:e7f76cb49584 | 92 | * set. This flag is updated with every temperature measurement. |
j3 | 101:e7f76cb49584 | 93 | * As long as the alarm flag is set, the DS1920 will respond to |
j3 | 101:e7f76cb49584 | 94 | * the alarm search command. |
j3 | 101:e7f76cb49584 | 95 | * |
j3 | 101:e7f76cb49584 | 96 | * On Entry: |
j3 | 101:e7f76cb49584 | 97 | * @param[in] th - 8-bit upper temperature threshold, MSB |
j3 | 101:e7f76cb49584 | 98 | * indicates sign |
j3 | 101:e7f76cb49584 | 99 | * @param[in] tl - 8-bit lower temperature threshold, LSB |
j3 | 101:e7f76cb49584 | 100 | * indicates sign |
j3 | 101:e7f76cb49584 | 101 | * @param[in] res - Resolution of the DS18B20 |
j3 | 101:e7f76cb49584 | 102 | * |
j3 | 101:e7f76cb49584 | 103 | * On Exit: |
j3 | 101:e7f76cb49584 | 104 | * @param[out] |
j3 | 101:e7f76cb49584 | 105 | * |
j3 | 101:e7f76cb49584 | 106 | * @return CmdResult - result of operation |
j3 | 101:e7f76cb49584 | 107 | **************************************************************/ |
j3 | 102:d3a7e4990b59 | 108 | OneWireSlave::CmdResult writeScratchPad(uint8_t th, uint8_t tl, Resolution res); |
j3 | 101:e7f76cb49584 | 109 | |
j3 | 101:e7f76cb49584 | 110 | |
j3 | 101:e7f76cb49584 | 111 | /**********************************************************//** |
j3 | 101:e7f76cb49584 | 112 | * @brief Read Scratchpad Command |
j3 | 101:e7f76cb49584 | 113 | * |
j3 | 101:e7f76cb49584 | 114 | * @details This command reads the complete scratchpad. |
j3 | 101:e7f76cb49584 | 115 | * |
j3 | 101:e7f76cb49584 | 116 | * On Entry: |
j3 | 101:e7f76cb49584 | 117 | * @param[in] scratchPadBuff - array for receiving contents of |
j3 | 101:e7f76cb49584 | 118 | * scratchpad, this buffer will be over written |
j3 | 101:e7f76cb49584 | 119 | * |
j3 | 101:e7f76cb49584 | 120 | * On Exit: |
j3 | 101:e7f76cb49584 | 121 | * @param[out] scratchPadBuff - contents of scratchpad |
j3 | 101:e7f76cb49584 | 122 | * |
j3 | 101:e7f76cb49584 | 123 | * @return CmdResult - result of operation |
j3 | 101:e7f76cb49584 | 124 | **************************************************************/ |
j3 | 102:d3a7e4990b59 | 125 | OneWireSlave::CmdResult readScratchPad(uint8_t * scratchPadBuff); |
j3 | 101:e7f76cb49584 | 126 | |
j3 | 101:e7f76cb49584 | 127 | /**********************************************************//** |
j3 | 101:e7f76cb49584 | 128 | * @brief Copy Scratchpad Command |
j3 | 101:e7f76cb49584 | 129 | * |
j3 | 101:e7f76cb49584 | 130 | * @details This command copies from the scratchpad into the |
j3 | 101:e7f76cb49584 | 131 | * EEPROM of the DS18B20, storing the temperature trigger bytes |
j3 | 101:e7f76cb49584 | 132 | * and resolution in nonvolatile memory. |
j3 | 101:e7f76cb49584 | 133 | * |
j3 | 101:e7f76cb49584 | 134 | * On Entry: |
j3 | 101:e7f76cb49584 | 135 | * @param[in] |
j3 | 101:e7f76cb49584 | 136 | * |
j3 | 101:e7f76cb49584 | 137 | * On Exit: |
j3 | 101:e7f76cb49584 | 138 | * @param[out] |
j3 | 101:e7f76cb49584 | 139 | * |
j3 | 101:e7f76cb49584 | 140 | * @return CmdResult - result of operation |
j3 | 101:e7f76cb49584 | 141 | **************************************************************/ |
j3 | 102:d3a7e4990b59 | 142 | OneWireSlave::CmdResult copyScratchPad( void ); |
j3 | 101:e7f76cb49584 | 143 | |
j3 | 101:e7f76cb49584 | 144 | |
j3 | 101:e7f76cb49584 | 145 | /**********************************************************//** |
j3 | 101:e7f76cb49584 | 146 | * @brief Read Power Supply command |
j3 | 101:e7f76cb49584 | 147 | * |
j3 | 101:e7f76cb49584 | 148 | * @details This command determines if the DS18B20 is parasite |
j3 | 101:e7f76cb49584 | 149 | * powered or has a local supply |
j3 | 101:e7f76cb49584 | 150 | * |
j3 | 101:e7f76cb49584 | 151 | * On Entry: |
j3 | 101:e7f76cb49584 | 152 | * @param[in] |
j3 | 101:e7f76cb49584 | 153 | * |
j3 | 101:e7f76cb49584 | 154 | * On Exit: |
j3 | 101:e7f76cb49584 | 155 | * @param[out] localPower - Will be False on exit if the DS18B20 |
j3 | 101:e7f76cb49584 | 156 | * is parasite powered |
j3 | 101:e7f76cb49584 | 157 | * |
j3 | 101:e7f76cb49584 | 158 | * @return CmdResult - result of operation |
j3 | 101:e7f76cb49584 | 159 | **************************************************************/ |
j3 | 102:d3a7e4990b59 | 160 | OneWireSlave::CmdResult readPowerSupply(bool & localPower); |
j3 | 101:e7f76cb49584 | 161 | |
j3 | 101:e7f76cb49584 | 162 | |
j3 | 101:e7f76cb49584 | 163 | /**********************************************************//** |
j3 | 101:e7f76cb49584 | 164 | * @brief Convert Temperature Command |
j3 | 101:e7f76cb49584 | 165 | * |
j3 | 101:e7f76cb49584 | 166 | * @details This command begins a temperature conversion. |
j3 | 101:e7f76cb49584 | 167 | * |
j3 | 101:e7f76cb49584 | 168 | * On Entry: |
j3 | 101:e7f76cb49584 | 169 | * @param[in] |
j3 | 101:e7f76cb49584 | 170 | * |
j3 | 101:e7f76cb49584 | 171 | * On Exit: |
j3 | 101:e7f76cb49584 | 172 | * @param[out] temp - temperature conversion results |
j3 | 101:e7f76cb49584 | 173 | * |
j3 | 101:e7f76cb49584 | 174 | * @return CmdResult - result of operation |
j3 | 101:e7f76cb49584 | 175 | **************************************************************/ |
j3 | 102:d3a7e4990b59 | 176 | OneWireSlave::CmdResult convertTemperature(float & temp); |
j3 | 101:e7f76cb49584 | 177 | |
j3 | 101:e7f76cb49584 | 178 | |
j3 | 101:e7f76cb49584 | 179 | /**********************************************************//** |
j3 | 101:e7f76cb49584 | 180 | * @brief Recall Command |
j3 | 101:e7f76cb49584 | 181 | * |
j3 | 101:e7f76cb49584 | 182 | * @details This command recalls the temperature trigger values |
j3 | 101:e7f76cb49584 | 183 | * and resolution stored in EEPROM to the scratchpad |
j3 | 101:e7f76cb49584 | 184 | * |
j3 | 101:e7f76cb49584 | 185 | * On Entry: |
j3 | 101:e7f76cb49584 | 186 | * @param[in] |
j3 | 101:e7f76cb49584 | 187 | * |
j3 | 101:e7f76cb49584 | 188 | * On Exit: |
j3 | 101:e7f76cb49584 | 189 | * @param[out] |
j3 | 101:e7f76cb49584 | 190 | * |
j3 | 101:e7f76cb49584 | 191 | * @return CmdResult - result of operation |
j3 | 101:e7f76cb49584 | 192 | **************************************************************/ |
j3 | 102:d3a7e4990b59 | 193 | OneWireSlave::CmdResult recallEEPROM( void ); |
j3 | 101:e7f76cb49584 | 194 | |
j3 | 101:e7f76cb49584 | 195 | }; |
j3 | 101:e7f76cb49584 | 196 | } |
j3 | 101:e7f76cb49584 | 197 | |
j3 | 101:e7f76cb49584 | 198 | #endif /* OneWire_Slaves_Sensors_DS18B20 */ |