1-Wire® library for mbed. Complete 1-Wire library that supports our silicon masters along with a bit-bang master on the MAX32600MBED platform with one common interface for mbed. Slave support has also been included and more slaves will be added as time permits.

Dependents:   MAXREFDES131_Qt_Demo MAX32630FTHR_iButton_uSD_Logger MAX32630FTHR_DS18B20_uSD_Logger MAXREFDES130_131_Demo ... more

Superseded by MaximInterface.

Committer:
j3
Date:
Sun Jul 03 20:39:30 2016 +0000
Revision:
102:d3a7e4990b59
Parent:
101:e7f76cb49584
Child:
104:3f48daed532b
Added scope to return values of DS18B20 mbr fxs

Who changed what in which revision?

UserRevisionLine numberNew 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 101:e7f76cb49584 36 #include "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 ///DS18B20 Family Code
j3 101:e7f76cb49584 62 static const uint8_t FAMILY_CODE = 0x28;
j3 101:e7f76cb49584 63
j3 101:e7f76cb49584 64 ///Available resolutions of the DS18B20
j3 101:e7f76cb49584 65 enum Resolution
j3 101:e7f76cb49584 66 {
j3 101:e7f76cb49584 67 NINE_BIT = 0x1F,
j3 101:e7f76cb49584 68 TEN_BIT = 0x3F,
j3 101:e7f76cb49584 69 ELEVEN_BIT = 0x5F,
j3 101:e7f76cb49584 70 TWELVE_BIT = 0x7F
j3 101:e7f76cb49584 71 };
j3 101:e7f76cb49584 72
j3 101:e7f76cb49584 73 /**********************************************************//**
j3 101:e7f76cb49584 74 * @brief DS18B20 constructor
j3 101:e7f76cb49584 75 *
j3 101:e7f76cb49584 76 * @details
j3 101:e7f76cb49584 77 *
j3 101:e7f76cb49584 78 * On Entry:
j3 101:e7f76cb49584 79 * @param[in] selector - Reference to RandomAccessRomiteraor
j3 101:e7f76cb49584 80 * object that encapsulates owm master that has access to this
j3 101:e7f76cb49584 81 * device and ROM function commands used to a select device
j3 101:e7f76cb49584 82 *
j3 101:e7f76cb49584 83 * On Exit:
j3 101:e7f76cb49584 84 *
j3 101:e7f76cb49584 85 * @return
j3 101:e7f76cb49584 86 **************************************************************/
j3 101:e7f76cb49584 87 DS18B20(RandomAccessRomIterator &selector);
j3 101:e7f76cb49584 88
j3 101:e7f76cb49584 89
j3 101:e7f76cb49584 90 /**********************************************************//**
j3 101:e7f76cb49584 91 * @brief Write Scratchpad Command
j3 101:e7f76cb49584 92 *
j3 101:e7f76cb49584 93 * @details If the result of a temperature measurement is higher
j3 101:e7f76cb49584 94 * than TH or lower than TL, an alarm flag inside the device is
j3 101:e7f76cb49584 95 * set. This flag is updated with every temperature measurement.
j3 101:e7f76cb49584 96 * As long as the alarm flag is set, the DS1920 will respond to
j3 101:e7f76cb49584 97 * the alarm search command.
j3 101:e7f76cb49584 98 *
j3 101:e7f76cb49584 99 * On Entry:
j3 101:e7f76cb49584 100 * @param[in] th - 8-bit upper temperature threshold, MSB
j3 101:e7f76cb49584 101 * indicates sign
j3 101:e7f76cb49584 102 * @param[in] tl - 8-bit lower temperature threshold, LSB
j3 101:e7f76cb49584 103 * indicates sign
j3 101:e7f76cb49584 104 * @param[in] res - Resolution of the DS18B20
j3 101:e7f76cb49584 105 *
j3 101:e7f76cb49584 106 * On Exit:
j3 101:e7f76cb49584 107 * @param[out]
j3 101:e7f76cb49584 108 *
j3 101:e7f76cb49584 109 * @return CmdResult - result of operation
j3 101:e7f76cb49584 110 **************************************************************/
j3 102:d3a7e4990b59 111 OneWireSlave::CmdResult writeScratchPad(uint8_t th, uint8_t tl, Resolution res);
j3 101:e7f76cb49584 112
j3 101:e7f76cb49584 113
j3 101:e7f76cb49584 114 /**********************************************************//**
j3 101:e7f76cb49584 115 * @brief Read Scratchpad Command
j3 101:e7f76cb49584 116 *
j3 101:e7f76cb49584 117 * @details This command reads the complete scratchpad.
j3 101:e7f76cb49584 118 *
j3 101:e7f76cb49584 119 * On Entry:
j3 101:e7f76cb49584 120 * @param[in] scratchPadBuff - array for receiving contents of
j3 101:e7f76cb49584 121 * scratchpad, this buffer will be over written
j3 101:e7f76cb49584 122 *
j3 101:e7f76cb49584 123 * On Exit:
j3 101:e7f76cb49584 124 * @param[out] scratchPadBuff - contents of scratchpad
j3 101:e7f76cb49584 125 *
j3 101:e7f76cb49584 126 * @return CmdResult - result of operation
j3 101:e7f76cb49584 127 **************************************************************/
j3 102:d3a7e4990b59 128 OneWireSlave::CmdResult readScratchPad(uint8_t * scratchPadBuff);
j3 101:e7f76cb49584 129
j3 101:e7f76cb49584 130 /**********************************************************//**
j3 101:e7f76cb49584 131 * @brief Copy Scratchpad Command
j3 101:e7f76cb49584 132 *
j3 101:e7f76cb49584 133 * @details This command copies from the scratchpad into the
j3 101:e7f76cb49584 134 * EEPROM of the DS18B20, storing the temperature trigger bytes
j3 101:e7f76cb49584 135 * and resolution in nonvolatile memory.
j3 101:e7f76cb49584 136 *
j3 101:e7f76cb49584 137 * On Entry:
j3 101:e7f76cb49584 138 * @param[in]
j3 101:e7f76cb49584 139 *
j3 101:e7f76cb49584 140 * On Exit:
j3 101:e7f76cb49584 141 * @param[out]
j3 101:e7f76cb49584 142 *
j3 101:e7f76cb49584 143 * @return CmdResult - result of operation
j3 101:e7f76cb49584 144 **************************************************************/
j3 102:d3a7e4990b59 145 OneWireSlave::CmdResult copyScratchPad( void );
j3 101:e7f76cb49584 146
j3 101:e7f76cb49584 147
j3 101:e7f76cb49584 148 /**********************************************************//**
j3 101:e7f76cb49584 149 * @brief Read Power Supply command
j3 101:e7f76cb49584 150 *
j3 101:e7f76cb49584 151 * @details This command determines if the DS18B20 is parasite
j3 101:e7f76cb49584 152 * powered or has a local supply
j3 101:e7f76cb49584 153 *
j3 101:e7f76cb49584 154 * On Entry:
j3 101:e7f76cb49584 155 * @param[in]
j3 101:e7f76cb49584 156 *
j3 101:e7f76cb49584 157 * On Exit:
j3 101:e7f76cb49584 158 * @param[out] localPower - Will be False on exit if the DS18B20
j3 101:e7f76cb49584 159 * is parasite powered
j3 101:e7f76cb49584 160 *
j3 101:e7f76cb49584 161 * @return CmdResult - result of operation
j3 101:e7f76cb49584 162 **************************************************************/
j3 102:d3a7e4990b59 163 OneWireSlave::CmdResult readPowerSupply(bool & localPower);
j3 101:e7f76cb49584 164
j3 101:e7f76cb49584 165
j3 101:e7f76cb49584 166 /**********************************************************//**
j3 101:e7f76cb49584 167 * @brief Convert Temperature Command
j3 101:e7f76cb49584 168 *
j3 101:e7f76cb49584 169 * @details This command begins a temperature conversion.
j3 101:e7f76cb49584 170 *
j3 101:e7f76cb49584 171 * On Entry:
j3 101:e7f76cb49584 172 * @param[in]
j3 101:e7f76cb49584 173 *
j3 101:e7f76cb49584 174 * On Exit:
j3 101:e7f76cb49584 175 * @param[out] temp - temperature conversion results
j3 101:e7f76cb49584 176 *
j3 101:e7f76cb49584 177 * @return CmdResult - result of operation
j3 101:e7f76cb49584 178 **************************************************************/
j3 102:d3a7e4990b59 179 OneWireSlave::CmdResult convertTemperature(float & temp);
j3 101:e7f76cb49584 180
j3 101:e7f76cb49584 181
j3 101:e7f76cb49584 182 /**********************************************************//**
j3 101:e7f76cb49584 183 * @brief Recall Command
j3 101:e7f76cb49584 184 *
j3 101:e7f76cb49584 185 * @details This command recalls the temperature trigger values
j3 101:e7f76cb49584 186 * and resolution stored in EEPROM to the scratchpad
j3 101:e7f76cb49584 187 *
j3 101:e7f76cb49584 188 * On Entry:
j3 101:e7f76cb49584 189 * @param[in]
j3 101:e7f76cb49584 190 *
j3 101:e7f76cb49584 191 * On Exit:
j3 101:e7f76cb49584 192 * @param[out]
j3 101:e7f76cb49584 193 *
j3 101:e7f76cb49584 194 * @return CmdResult - result of operation
j3 101:e7f76cb49584 195 **************************************************************/
j3 102:d3a7e4990b59 196 OneWireSlave::CmdResult recallEEPROM( void );
j3 101:e7f76cb49584 197
j3 101:e7f76cb49584 198 };
j3 101:e7f76cb49584 199 }
j3 101:e7f76cb49584 200
j3 101:e7f76cb49584 201 #endif /* OneWire_Slaves_Sensors_DS18B20 */