Implementation of 1-Wire with added Alarm Search Functionality

Dependents:   Max32630_One_Wire_Interface

Committer:
j3
Date:
Sun Jul 03 20:35:38 2016 +0000
Revision:
101:e7f76cb49584
Parent:
93:e496a45ce796
Child:
104:3f48daed532b
Added DS18B20 support to OW Library

Who changed what in which revision?

UserRevisionLine numberNew contents of line
j3 80:83b0d879cc32 1 /******************************************************************//**
j3 80:83b0d879cc32 2 * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved.
j3 80:83b0d879cc32 3 *
j3 80:83b0d879cc32 4 * Permission is hereby granted, free of charge, to any person obtaining a
j3 80:83b0d879cc32 5 * copy of this software and associated documentation files (the "Software"),
j3 80:83b0d879cc32 6 * to deal in the Software without restriction, including without limitation
j3 80:83b0d879cc32 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
j3 80:83b0d879cc32 8 * and/or sell copies of the Software, and to permit persons to whom the
j3 80:83b0d879cc32 9 * Software is furnished to do so, subject to the following conditions:
j3 80:83b0d879cc32 10 *
j3 80:83b0d879cc32 11 * The above copyright notice and this permission notice shall be included
j3 80:83b0d879cc32 12 * in all copies or substantial portions of the Software.
j3 80:83b0d879cc32 13 *
j3 80:83b0d879cc32 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
j3 80:83b0d879cc32 15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
j3 80:83b0d879cc32 16 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
j3 80:83b0d879cc32 17 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
j3 80:83b0d879cc32 18 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
j3 80:83b0d879cc32 19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
j3 80:83b0d879cc32 20 * OTHER DEALINGS IN THE SOFTWARE.
j3 80:83b0d879cc32 21 *
j3 80:83b0d879cc32 22 * Except as contained in this notice, the name of Maxim Integrated
j3 80:83b0d879cc32 23 * Products, Inc. shall not be used except as stated in the Maxim Integrated
j3 80:83b0d879cc32 24 * Products, Inc. Branding Policy.
j3 80:83b0d879cc32 25 *
j3 80:83b0d879cc32 26 * The mere transfer of this software does not imply any licenses
j3 80:83b0d879cc32 27 * of trade secrets, proprietary technology, copyrights, patents,
j3 80:83b0d879cc32 28 * trademarks, maskwork rights, or any other form of intellectual
j3 80:83b0d879cc32 29 * property whatsoever. Maxim Integrated Products, Inc. retains all
j3 80:83b0d879cc32 30 * ownership rights.
j3 80:83b0d879cc32 31 **********************************************************************/
j3 80:83b0d879cc32 32
j3 80:83b0d879cc32 33 #ifndef OneWire_Temperature_DS1920
j3 80:83b0d879cc32 34 #define OneWire_Temperature_DS1920
j3 80:83b0d879cc32 35
j3 80:83b0d879cc32 36 #include "OneWireSlave.h"
j3 80:83b0d879cc32 37
j3 80:83b0d879cc32 38 namespace OneWire
j3 80:83b0d879cc32 39 {
j3 80:83b0d879cc32 40 class OneWireMaster;
j3 80:83b0d879cc32 41
j3 80:83b0d879cc32 42 /**
j3 80:83b0d879cc32 43 * @brief DS1920 1-wire temperature i-button
j3 80:83b0d879cc32 44 *
j3 80:83b0d879cc32 45 * @details The iButton® temperature logger (DS1920) provides
j3 80:83b0d879cc32 46 * direct-to-digital 9-bit temperature readings over a range of
j3 80:83b0d879cc32 47 * -55°C to +100°C in 0.5° increments. The iButton communicates with
j3 80:83b0d879cc32 48 * a processor using the 1-Wire® protocol through a hardware port
j3 80:83b0d879cc32 49 * interface. The port interface provides both the physical link and
j3 80:83b0d879cc32 50 * handles the communication protocols that enable the processor to
j3 80:83b0d879cc32 51 * access iButton resources with simple commands. Two bytes of
j3 80:83b0d879cc32 52 * EEPROM can be used either to set alarm triggers or for storing
j3 80:83b0d879cc32 53 * user data.
j3 80:83b0d879cc32 54 *
j3 80:83b0d879cc32 55 * @code
j3 80:83b0d879cc32 56 * @endcode
j3 80:83b0d879cc32 57 */
j3 80:83b0d879cc32 58 class DS1920 : public OneWireSlave
j3 80:83b0d879cc32 59 {
j3 80:83b0d879cc32 60 public:
j3 93:e496a45ce796 61
j3 101:e7f76cb49584 62 static const uint8_t DS1920_FAMILY_CODE = 0x10;
j3 101:e7f76cb49584 63
j3 93:e496a45ce796 64 ///Result of operations
j3 80:83b0d879cc32 65 enum CmdResult
j3 80:83b0d879cc32 66 {
j3 80:83b0d879cc32 67 Success,
j3 80:83b0d879cc32 68 CommsReadError,
j3 80:83b0d879cc32 69 CommsWriteError,
j3 80:83b0d879cc32 70 OpFailure
j3 80:83b0d879cc32 71 };
j3 80:83b0d879cc32 72
j3 80:83b0d879cc32 73 /**********************************************************//**
j3 80:83b0d879cc32 74 * @brief DS1920 constructor
j3 80:83b0d879cc32 75 *
j3 80:83b0d879cc32 76 * @details
j3 80:83b0d879cc32 77 *
j3 80:83b0d879cc32 78 * On Entry:
j3 80:83b0d879cc32 79 * @param[in] selector - Reference to RandomAccessRomiteraor
j3 80:83b0d879cc32 80 * object that encapsulates owm master that has access to this
j3 80:83b0d879cc32 81 * device and ROM function commands used to a select device
j3 80:83b0d879cc32 82 *
j3 80:83b0d879cc32 83 * On Exit:
j3 80:83b0d879cc32 84 *
j3 80:83b0d879cc32 85 * @return
j3 80:83b0d879cc32 86 **************************************************************/
j3 80:83b0d879cc32 87 DS1920(RandomAccessRomIterator &selector);
j3 80:83b0d879cc32 88
j3 80:83b0d879cc32 89
j3 80:83b0d879cc32 90 /**********************************************************//**
j3 80:83b0d879cc32 91 * @brief Write Scratchpad Command
j3 80:83b0d879cc32 92 *
j3 80:83b0d879cc32 93 * @details If the result of a temperature measurement is higher
j3 80:83b0d879cc32 94 * than TH or lower than TL, an alarm flag inside the device is
j3 80:83b0d879cc32 95 * set. This flag is updated with every temperature measurement.
j3 80:83b0d879cc32 96 * As long as the alarm flag is set, the DS1920 will respond to
j3 80:83b0d879cc32 97 * the alarm search command.
j3 80:83b0d879cc32 98 *
j3 80:83b0d879cc32 99 * On Entry:
j3 80:83b0d879cc32 100 * @param[in] th - 8-bit upper temperature threshold, MSB
j3 80:83b0d879cc32 101 * indicates sign
j3 80:83b0d879cc32 102 * @param[in] tl - 8-bit lower temperature threshold, MSB
j3 80:83b0d879cc32 103 * indicates sign
j3 80:83b0d879cc32 104 *
j3 80:83b0d879cc32 105 * On Exit:
j3 80:83b0d879cc32 106 * @param[out]
j3 80:83b0d879cc32 107 *
j3 80:83b0d879cc32 108 * @return CmdResult - result of operation
j3 80:83b0d879cc32 109 **************************************************************/
j3 80:83b0d879cc32 110 CmdResult writeScratchPad(uint8_t th, uint8_t tl);
j3 80:83b0d879cc32 111
j3 80:83b0d879cc32 112
j3 80:83b0d879cc32 113 /**********************************************************//**
j3 80:83b0d879cc32 114 * @brief Read Scratchpad Command
j3 80:83b0d879cc32 115 *
j3 80:83b0d879cc32 116 * @details This command reads the complete scratchpad.
j3 80:83b0d879cc32 117 *
j3 80:83b0d879cc32 118 * On Entry:
j3 80:83b0d879cc32 119 * @param[in] scratchPadBuff - array for receiving contents of
j3 80:83b0d879cc32 120 * scratchpad, this buffer will be over written
j3 80:83b0d879cc32 121 *
j3 80:83b0d879cc32 122 * On Exit:
j3 80:83b0d879cc32 123 * @param[out] scratchPadBuff - contents of scratchpad
j3 80:83b0d879cc32 124 *
j3 80:83b0d879cc32 125 * @return CmdResult - result of operation
j3 80:83b0d879cc32 126 **************************************************************/
j3 80:83b0d879cc32 127 CmdResult readScratchPad(uint8_t * scratchPadBuff);
j3 80:83b0d879cc32 128
j3 80:83b0d879cc32 129 /**********************************************************//**
j3 80:83b0d879cc32 130 * @brief Copy Scratchpad Command
j3 80:83b0d879cc32 131 *
j3 80:83b0d879cc32 132 * @details This command copies from the scratchpad into the
j3 80:83b0d879cc32 133 * EEPROM of the DS1920, storing the temperature trigger bytes
j3 80:83b0d879cc32 134 * in nonvolatile memory.
j3 80:83b0d879cc32 135 *
j3 80:83b0d879cc32 136 * On Entry:
j3 80:83b0d879cc32 137 * @param[in]
j3 80:83b0d879cc32 138 *
j3 80:83b0d879cc32 139 * On Exit:
j3 80:83b0d879cc32 140 * @param[out]
j3 80:83b0d879cc32 141 *
j3 80:83b0d879cc32 142 * @return CmdResult - result of operation
j3 80:83b0d879cc32 143 **************************************************************/
j3 80:83b0d879cc32 144 CmdResult copyScratchPad( void );
j3 80:83b0d879cc32 145
j3 80:83b0d879cc32 146 /**********************************************************//**
j3 80:83b0d879cc32 147 * @brief Convert Temperature Command
j3 80:83b0d879cc32 148 *
j3 80:83b0d879cc32 149 * @details This command begins a temperature conversion.
j3 80:83b0d879cc32 150 *
j3 80:83b0d879cc32 151 * On Entry:
j3 80:83b0d879cc32 152 * @param[in]
j3 80:83b0d879cc32 153 *
j3 80:83b0d879cc32 154 * On Exit:
j3 80:83b0d879cc32 155 * @param[out] temp - temperature conversion results
j3 80:83b0d879cc32 156 *
j3 80:83b0d879cc32 157 * @return CmdResult - result of operation
j3 80:83b0d879cc32 158 **************************************************************/
j3 81:e2a3ad98874e 159 CmdResult convertTemperature(float & temp);
j3 80:83b0d879cc32 160
j3 80:83b0d879cc32 161
j3 80:83b0d879cc32 162 /**********************************************************//**
j3 80:83b0d879cc32 163 * @brief Recall Command
j3 80:83b0d879cc32 164 *
j3 80:83b0d879cc32 165 * @details This command recalls the temperature trigger values
j3 80:83b0d879cc32 166 * stored in EEPROM to the scratchpad
j3 80:83b0d879cc32 167 *
j3 80:83b0d879cc32 168 * On Entry:
j3 80:83b0d879cc32 169 * @param[in]
j3 80:83b0d879cc32 170 *
j3 80:83b0d879cc32 171 * On Exit:
j3 80:83b0d879cc32 172 * @param[out]
j3 80:83b0d879cc32 173 *
j3 80:83b0d879cc32 174 * @return CmdResult - result of operation
j3 80:83b0d879cc32 175 **************************************************************/
j3 80:83b0d879cc32 176 CmdResult recallEEPROM( void );
j3 80:83b0d879cc32 177
j3 80:83b0d879cc32 178 private:
j3 80:83b0d879cc32 179
j3 80:83b0d879cc32 180 };
j3 80:83b0d879cc32 181 }
j3 80:83b0d879cc32 182
IanBenzMaxim 86:2ce08ca58b9e 183 #endif /* OneWire_Temperature_DS1920 */