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:
Fri Jun 03 22:15:59 2016 +0000
Revision:
81:e2a3ad98874e
Parent:
80:83b0d879cc32
DS1920 convertTemperature updates float passed by ref now

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 "mbed.h"
j3 80:83b0d879cc32 37 #include "Masters/OneWireMasters.h"
j3 80:83b0d879cc32 38 #include "OneWireSlave.h"
j3 80:83b0d879cc32 39 #include "crc.h"
j3 80:83b0d879cc32 40
j3 80:83b0d879cc32 41 namespace OneWire
j3 80:83b0d879cc32 42 {
j3 80:83b0d879cc32 43 class OneWireMaster;
j3 80:83b0d879cc32 44
j3 80:83b0d879cc32 45 /**
j3 80:83b0d879cc32 46 * @brief DS1920 1-wire temperature i-button
j3 80:83b0d879cc32 47 *
j3 80:83b0d879cc32 48 * @details The iButton® temperature logger (DS1920) provides
j3 80:83b0d879cc32 49 * direct-to-digital 9-bit temperature readings over a range of
j3 80:83b0d879cc32 50 * -55°C to +100°C in 0.5° increments. The iButton communicates with
j3 80:83b0d879cc32 51 * a processor using the 1-Wire® protocol through a hardware port
j3 80:83b0d879cc32 52 * interface. The port interface provides both the physical link and
j3 80:83b0d879cc32 53 * handles the communication protocols that enable the processor to
j3 80:83b0d879cc32 54 * access iButton resources with simple commands. Two bytes of
j3 80:83b0d879cc32 55 * EEPROM can be used either to set alarm triggers or for storing
j3 80:83b0d879cc32 56 * user data.
j3 80:83b0d879cc32 57 *
j3 80:83b0d879cc32 58 * @code
j3 80:83b0d879cc32 59 * @endcode
j3 80:83b0d879cc32 60 */
j3 80:83b0d879cc32 61 class DS1920 : public OneWireSlave
j3 80:83b0d879cc32 62 {
j3 80:83b0d879cc32 63 public:
j3 80:83b0d879cc32 64 enum CmdResult
j3 80:83b0d879cc32 65 {
j3 80:83b0d879cc32 66 Success,
j3 80:83b0d879cc32 67 CommsReadError,
j3 80:83b0d879cc32 68 CommsWriteError,
j3 80:83b0d879cc32 69 OpFailure
j3 80:83b0d879cc32 70 };
j3 80:83b0d879cc32 71
j3 80:83b0d879cc32 72 /**********************************************************//**
j3 80:83b0d879cc32 73 * @brief DS1920 constructor
j3 80:83b0d879cc32 74 *
j3 80:83b0d879cc32 75 * @details
j3 80:83b0d879cc32 76 *
j3 80:83b0d879cc32 77 * On Entry:
j3 80:83b0d879cc32 78 * @param[in] selector - Reference to RandomAccessRomiteraor
j3 80:83b0d879cc32 79 * object that encapsulates owm master that has access to this
j3 80:83b0d879cc32 80 * device and ROM function commands used to a select device
j3 80:83b0d879cc32 81 *
j3 80:83b0d879cc32 82 * On Exit:
j3 80:83b0d879cc32 83 *
j3 80:83b0d879cc32 84 * @return
j3 80:83b0d879cc32 85 **************************************************************/
j3 80:83b0d879cc32 86 DS1920(RandomAccessRomIterator &selector);
j3 80:83b0d879cc32 87
j3 80:83b0d879cc32 88
j3 80:83b0d879cc32 89 /**********************************************************//**
j3 80:83b0d879cc32 90 * @brief Write Scratchpad Command
j3 80:83b0d879cc32 91 *
j3 80:83b0d879cc32 92 * @details If the result of a temperature measurement is higher
j3 80:83b0d879cc32 93 * than TH or lower than TL, an alarm flag inside the device is
j3 80:83b0d879cc32 94 * set. This flag is updated with every temperature measurement.
j3 80:83b0d879cc32 95 * As long as the alarm flag is set, the DS1920 will respond to
j3 80:83b0d879cc32 96 * the alarm search command.
j3 80:83b0d879cc32 97 *
j3 80:83b0d879cc32 98 * On Entry:
j3 80:83b0d879cc32 99 * @param[in] th - 8-bit upper temperature threshold, MSB
j3 80:83b0d879cc32 100 * indicates sign
j3 80:83b0d879cc32 101 * @param[in] tl - 8-bit lower temperature threshold, MSB
j3 80:83b0d879cc32 102 * indicates sign
j3 80:83b0d879cc32 103 *
j3 80:83b0d879cc32 104 * On Exit:
j3 80:83b0d879cc32 105 * @param[out]
j3 80:83b0d879cc32 106 *
j3 80:83b0d879cc32 107 * @return CmdResult - result of operation
j3 80:83b0d879cc32 108 **************************************************************/
j3 80:83b0d879cc32 109 CmdResult writeScratchPad(uint8_t th, uint8_t tl);
j3 80:83b0d879cc32 110
j3 80:83b0d879cc32 111
j3 80:83b0d879cc32 112 /**********************************************************//**
j3 80:83b0d879cc32 113 * @brief Read Scratchpad Command
j3 80:83b0d879cc32 114 *
j3 80:83b0d879cc32 115 * @details This command reads the complete scratchpad.
j3 80:83b0d879cc32 116 *
j3 80:83b0d879cc32 117 * On Entry:
j3 80:83b0d879cc32 118 * @param[in] scratchPadBuff - array for receiving contents of
j3 80:83b0d879cc32 119 * scratchpad, this buffer will be over written
j3 80:83b0d879cc32 120 *
j3 80:83b0d879cc32 121 * On Exit:
j3 80:83b0d879cc32 122 * @param[out] scratchPadBuff - contents of scratchpad
j3 80:83b0d879cc32 123 *
j3 80:83b0d879cc32 124 * @return CmdResult - result of operation
j3 80:83b0d879cc32 125 **************************************************************/
j3 80:83b0d879cc32 126 CmdResult readScratchPad(uint8_t * scratchPadBuff);
j3 80:83b0d879cc32 127
j3 80:83b0d879cc32 128 /**********************************************************//**
j3 80:83b0d879cc32 129 * @brief Copy Scratchpad Command
j3 80:83b0d879cc32 130 *
j3 80:83b0d879cc32 131 * @details This command copies from the scratchpad into the
j3 80:83b0d879cc32 132 * EEPROM of the DS1920, storing the temperature trigger bytes
j3 80:83b0d879cc32 133 * in nonvolatile memory.
j3 80:83b0d879cc32 134 *
j3 80:83b0d879cc32 135 * On Entry:
j3 80:83b0d879cc32 136 * @param[in]
j3 80:83b0d879cc32 137 *
j3 80:83b0d879cc32 138 * On Exit:
j3 80:83b0d879cc32 139 * @param[out]
j3 80:83b0d879cc32 140 *
j3 80:83b0d879cc32 141 * @return CmdResult - result of operation
j3 80:83b0d879cc32 142 **************************************************************/
j3 80:83b0d879cc32 143 CmdResult copyScratchPad( void );
j3 80:83b0d879cc32 144
j3 80:83b0d879cc32 145 /**********************************************************//**
j3 80:83b0d879cc32 146 * @brief Convert Temperature Command
j3 80:83b0d879cc32 147 *
j3 80:83b0d879cc32 148 * @details This command begins a temperature conversion.
j3 80:83b0d879cc32 149 *
j3 80:83b0d879cc32 150 * On Entry:
j3 80:83b0d879cc32 151 * @param[in]
j3 80:83b0d879cc32 152 *
j3 80:83b0d879cc32 153 * On Exit:
j3 80:83b0d879cc32 154 * @param[out] temp - temperature conversion results
j3 80:83b0d879cc32 155 *
j3 80:83b0d879cc32 156 * @return CmdResult - result of operation
j3 80:83b0d879cc32 157 **************************************************************/
j3 81:e2a3ad98874e 158 CmdResult convertTemperature(float & temp);
j3 80:83b0d879cc32 159
j3 80:83b0d879cc32 160
j3 80:83b0d879cc32 161 /**********************************************************//**
j3 80:83b0d879cc32 162 * @brief Recall Command
j3 80:83b0d879cc32 163 *
j3 80:83b0d879cc32 164 * @details This command recalls the temperature trigger values
j3 80:83b0d879cc32 165 * stored in EEPROM to the scratchpad
j3 80:83b0d879cc32 166 *
j3 80:83b0d879cc32 167 * On Entry:
j3 80:83b0d879cc32 168 * @param[in]
j3 80:83b0d879cc32 169 *
j3 80:83b0d879cc32 170 * On Exit:
j3 80:83b0d879cc32 171 * @param[out]
j3 80:83b0d879cc32 172 *
j3 80:83b0d879cc32 173 * @return CmdResult - result of operation
j3 80:83b0d879cc32 174 **************************************************************/
j3 80:83b0d879cc32 175 CmdResult recallEEPROM( void );
j3 80:83b0d879cc32 176
j3 80:83b0d879cc32 177 private:
j3 80:83b0d879cc32 178
j3 80:83b0d879cc32 179 };
j3 80:83b0d879cc32 180 }
j3 80:83b0d879cc32 181
j3 80:83b0d879cc32 182 #endif /* OneWire_Temperature_DS1920 */