Implementation of 1-Wire with added Alarm Search Functionality

Dependents:   Max32630_One_Wire_Interface

Committer:
IanBenzMaxim
Date:
Fri May 13 14:52:50 2016 -0500
Revision:
75:8b627804927c
Parent:
74:23be10c32fa3
Child:
76:84e6c4994e29
Code cleanup.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
j3 4:ca27db159b10 1 /******************************************************************//**
j3 4:ca27db159b10 2 * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved.
j3 4:ca27db159b10 3 *
j3 4:ca27db159b10 4 * Permission is hereby granted, free of charge, to any person obtaining a
j3 4:ca27db159b10 5 * copy of this software and associated documentation files (the "Software"),
j3 4:ca27db159b10 6 * to deal in the Software without restriction, including without limitation
j3 4:ca27db159b10 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
j3 4:ca27db159b10 8 * and/or sell copies of the Software, and to permit persons to whom the
j3 4:ca27db159b10 9 * Software is furnished to do so, subject to the following conditions:
j3 4:ca27db159b10 10 *
j3 4:ca27db159b10 11 * The above copyright notice and this permission notice shall be included
j3 4:ca27db159b10 12 * in all copies or substantial portions of the Software.
j3 4:ca27db159b10 13 *
j3 4:ca27db159b10 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
j3 4:ca27db159b10 15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
j3 4:ca27db159b10 16 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
j3 4:ca27db159b10 17 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
j3 4:ca27db159b10 18 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
j3 4:ca27db159b10 19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
j3 4:ca27db159b10 20 * OTHER DEALINGS IN THE SOFTWARE.
j3 4:ca27db159b10 21 *
j3 4:ca27db159b10 22 * Except as contained in this notice, the name of Maxim Integrated
j3 4:ca27db159b10 23 * Products, Inc. shall not be used except as stated in the Maxim Integrated
j3 4:ca27db159b10 24 * Products, Inc. Branding Policy.
j3 4:ca27db159b10 25 *
j3 4:ca27db159b10 26 * The mere transfer of this software does not imply any licenses
j3 4:ca27db159b10 27 * of trade secrets, proprietary technology, copyrights, patents,
j3 4:ca27db159b10 28 * trademarks, maskwork rights, or any other form of intellectual
j3 4:ca27db159b10 29 * property whatsoever. Maxim Integrated Products, Inc. retains all
j3 4:ca27db159b10 30 * ownership rights.
j3 4:ca27db159b10 31 **********************************************************************/
j3 4:ca27db159b10 32
IanBenzMaxim 73:2cecc1372acc 33 #ifndef OneWire_Bridge_DS28E17
IanBenzMaxim 73:2cecc1372acc 34 #define OneWire_Bridge_DS28E17
j3 4:ca27db159b10 35
IanBenzMaxim 73:2cecc1372acc 36 #include <stdint.h>
IanBenzMaxim 73:2cecc1372acc 37 #include <stddef.h>
IanBenzMaxim 73:2cecc1372acc 38 #include "OneWireSlave.h"
j3 4:ca27db159b10 39
IanBenzMaxim 73:2cecc1372acc 40 namespace OneWire
j3 4:ca27db159b10 41 {
IanBenzMaxim 73:2cecc1372acc 42 namespace Masters { class OneWireMaster; }
IanBenzMaxim 74:23be10c32fa3 43
IanBenzMaxim 73:2cecc1372acc 44 namespace Bridge
IanBenzMaxim 73:2cecc1372acc 45 {
IanBenzMaxim 73:2cecc1372acc 46 class DS28E17 : public OneWireSlave
IanBenzMaxim 73:2cecc1372acc 47 {
IanBenzMaxim 73:2cecc1372acc 48 public:
IanBenzMaxim 73:2cecc1372acc 49 enum CmdResult
IanBenzMaxim 73:2cecc1372acc 50 {
IanBenzMaxim 73:2cecc1372acc 51 Success,
IanBenzMaxim 73:2cecc1372acc 52 CommsReadBitError,
IanBenzMaxim 73:2cecc1372acc 53 CommsWriteBitError,
IanBenzMaxim 73:2cecc1372acc 54 CommsReadByteError,
IanBenzMaxim 73:2cecc1372acc 55 CommsWriteByteError,
IanBenzMaxim 73:2cecc1372acc 56 CommsReadBlockError,
IanBenzMaxim 73:2cecc1372acc 57 CommsWriteBlockError,
IanBenzMaxim 73:2cecc1372acc 58 TimeoutError,
IanBenzMaxim 73:2cecc1372acc 59 OperationFailure
IanBenzMaxim 73:2cecc1372acc 60 };
IanBenzMaxim 74:23be10c32fa3 61
IanBenzMaxim 73:2cecc1372acc 62 /**********************************************************//**
IanBenzMaxim 73:2cecc1372acc 63 * @brief DS28E17 constructor
IanBenzMaxim 74:23be10c32fa3 64 *
IanBenzMaxim 74:23be10c32fa3 65 * @details
IanBenzMaxim 73:2cecc1372acc 66 *
IanBenzMaxim 73:2cecc1372acc 67 * On Entry:
IanBenzMaxim 73:2cecc1372acc 68 * @param[in] p_owm - pointer to a 1-wire master of the following
IanBenzMaxim 73:2cecc1372acc 69 * types; Ds248x, Ds2480b, OwGpio which
IanBenzMaxim 73:2cecc1372acc 70 * inherit the base class 'OneWireInterface'
IanBenzMaxim 73:2cecc1372acc 71 *
IanBenzMaxim 73:2cecc1372acc 72 * On Exit:
IanBenzMaxim 74:23be10c32fa3 73 * @return
IanBenzMaxim 73:2cecc1372acc 74 **************************************************************/
IanBenzMaxim 73:2cecc1372acc 75 DS28E17(Masters::OneWireMaster &owm);
IanBenzMaxim 74:23be10c32fa3 76
IanBenzMaxim 73:2cecc1372acc 77 /**********************************************************//**
IanBenzMaxim 74:23be10c32fa3 78 * @brief Write to selected DS28E17's I2C with Stop.
IanBenzMaxim 73:2cecc1372acc 79 * Poll until I2C write complete and receive status info.
IanBenzMaxim 74:23be10c32fa3 80 *
IanBenzMaxim 73:2cecc1372acc 81 * @details Output on I2C: S, Address + Write, Write Data [1-255], P
IanBenzMaxim 73:2cecc1372acc 82 *
IanBenzMaxim 73:2cecc1372acc 83 * On Entry:
IanBenzMaxim 74:23be10c32fa3 84 * @param[in] I2C_addr -
IanBenzMaxim 74:23be10c32fa3 85 * Writes I2C address. The least significant bit of the I2C
IanBenzMaxim 73:2cecc1372acc 86 * address is automatically cleared by the command.
IanBenzMaxim 73:2cecc1372acc 87 *
IanBenzMaxim 73:2cecc1372acc 88 * @param[in] length
IanBenzMaxim 73:2cecc1372acc 89 * The number of data bytes to be written ranging from 01h to FFh.
IanBenzMaxim 73:2cecc1372acc 90 * A value of zero will assert the Error Detected pin (ED).
IanBenzMaxim 73:2cecc1372acc 91 *
IanBenzMaxim 73:2cecc1372acc 92 * @param[in] *data
IanBenzMaxim 73:2cecc1372acc 93 * User defines write data ranging from 1-255 bytes.
IanBenzMaxim 73:2cecc1372acc 94 *
IanBenzMaxim 73:2cecc1372acc 95 * On Exit:
IanBenzMaxim 73:2cecc1372acc 96 * @param[out] status
IanBenzMaxim 74:23be10c32fa3 97 * Detects the condition of the Start (bit3), N/A (bit2),
IanBenzMaxim 73:2cecc1372acc 98 * Address(bit1) and CRC16(bit0) bits.
IanBenzMaxim 74:23be10c32fa3 99 * b3;0=No Err|1=I2CStart prev-not issued,
IanBenzMaxim 73:2cecc1372acc 100 * b2;0=No Err|1=I2C N/A Err,
IanBenzMaxim 74:23be10c32fa3 101 * b1;0=No Err|1=Addr Err,
IanBenzMaxim 73:2cecc1372acc 102 * b0;0=Valid CRC16|1=Invalid CRC16
IanBenzMaxim 73:2cecc1372acc 103 *
IanBenzMaxim 73:2cecc1372acc 104 * @param[out] wr_status
IanBenzMaxim 74:23be10c32fa3 105 * Indicates which write byte NACK’d. A value of 00h indicates
IanBenzMaxim 73:2cecc1372acc 106 * all bytes were acknowledged by the slave.
IanBenzMaxim 73:2cecc1372acc 107 * A non-zero value indicates the byte number that NACK’d.
IanBenzMaxim 73:2cecc1372acc 108 *
IanBenzMaxim 74:23be10c32fa3 109 * @return
IanBenzMaxim 73:2cecc1372acc 110 * true if device selected and written @n
IanBenzMaxim 73:2cecc1372acc 111 * false if failed device select
IanBenzMaxim 73:2cecc1372acc 112 **************************************************************/
IanBenzMaxim 74:23be10c32fa3 113 CmdResult I2C_WriteDataWithStop(uint8_t I2C_addr, uint8_t length,
IanBenzMaxim 74:23be10c32fa3 114 uint8_t *data, uint8_t &status,
IanBenzMaxim 74:23be10c32fa3 115 uint8_t &wr_status);
IanBenzMaxim 74:23be10c32fa3 116
IanBenzMaxim 73:2cecc1372acc 117 /**********************************************************//**
IanBenzMaxim 74:23be10c32fa3 118 * @brief Write to selected DS28E17's I2C No Stop.
IanBenzMaxim 73:2cecc1372acc 119 * Poll until I2C write complete and receive status info.
IanBenzMaxim 74:23be10c32fa3 120 *
IanBenzMaxim 73:2cecc1372acc 121 * @details Output on I2C: S, Address + Write, Write Data [1-255]
IanBenzMaxim 73:2cecc1372acc 122 *
IanBenzMaxim 73:2cecc1372acc 123 * On Entry:
IanBenzMaxim 73:2cecc1372acc 124 * @param[in] I2C_addr
IanBenzMaxim 73:2cecc1372acc 125 * Writes I2C address. The least significant bit of the I2C address
IanBenzMaxim 73:2cecc1372acc 126 * is automatically cleared by the command.
IanBenzMaxim 73:2cecc1372acc 127 *
IanBenzMaxim 73:2cecc1372acc 128 * @param[in] length
IanBenzMaxim 73:2cecc1372acc 129 * The number of data bytes to be written ranging from 01h to FFh.
IanBenzMaxim 73:2cecc1372acc 130 * A value of zero will assert the Error Detected pin (ED).
IanBenzMaxim 73:2cecc1372acc 131 *
IanBenzMaxim 73:2cecc1372acc 132 * @param[in] *data
IanBenzMaxim 73:2cecc1372acc 133 * User defines write data ranging from 1-255 bytes.
IanBenzMaxim 73:2cecc1372acc 134 *
IanBenzMaxim 73:2cecc1372acc 135 * On Exit:
IanBenzMaxim 73:2cecc1372acc 136 * @param[out] status
IanBenzMaxim 74:23be10c32fa3 137 * Detects the condition of the Start (bit3), N/A (bit2),
IanBenzMaxim 73:2cecc1372acc 138 * Address(bit1) and CRC16(bit0) bits.
IanBenzMaxim 74:23be10c32fa3 139 * b3;0=No Err|1=I2CStart prev-not issued,
IanBenzMaxim 73:2cecc1372acc 140 * b2;0=No Err|1=I2C N/A Err,
IanBenzMaxim 74:23be10c32fa3 141 * b1;0=No Err|1=Addr Err,
IanBenzMaxim 73:2cecc1372acc 142 * b0;0=Valid CRC16|1=Invalid CRC16
IanBenzMaxim 73:2cecc1372acc 143 *
IanBenzMaxim 73:2cecc1372acc 144 * @param[out] wr_status
IanBenzMaxim 74:23be10c32fa3 145 * Indicates which write byte NACK’d. A value of 00h indicates
IanBenzMaxim 73:2cecc1372acc 146 * all bytes were acknowledged by the slave.
IanBenzMaxim 73:2cecc1372acc 147 * A non-zero value indicates the byte number that NACK’d.
IanBenzMaxim 73:2cecc1372acc 148 *
IanBenzMaxim 74:23be10c32fa3 149 * @return
IanBenzMaxim 73:2cecc1372acc 150 * true if device selected and written @n
IanBenzMaxim 73:2cecc1372acc 151 * false if failed device select
IanBenzMaxim 73:2cecc1372acc 152 **************************************************************/
IanBenzMaxim 74:23be10c32fa3 153 CmdResult I2C_WriteDataNoStop(uint8_t I2C_addr, uint8_t length,
IanBenzMaxim 74:23be10c32fa3 154 uint8_t *data, uint8_t &status,
IanBenzMaxim 74:23be10c32fa3 155 uint8_t &wr_status);
IanBenzMaxim 74:23be10c32fa3 156
IanBenzMaxim 74:23be10c32fa3 157
IanBenzMaxim 73:2cecc1372acc 158 /**********************************************************//**
IanBenzMaxim 74:23be10c32fa3 159 * @brief Write to selected DS28E17's I2C with Data only.
IanBenzMaxim 73:2cecc1372acc 160 * Poll until I2C write complete and receive status info.
IanBenzMaxim 74:23be10c32fa3 161 *
IanBenzMaxim 73:2cecc1372acc 162 * @details Output on I2C: Write Data [1-255]
IanBenzMaxim 73:2cecc1372acc 163 *
IanBenzMaxim 73:2cecc1372acc 164 * On Entry:
IanBenzMaxim 73:2cecc1372acc 165 * @param[in] length
IanBenzMaxim 73:2cecc1372acc 166 * The number of data bytes to be written ranging from 01h to FFh.
IanBenzMaxim 73:2cecc1372acc 167 * A value of zero will assert the Error Detected pin (ED).
IanBenzMaxim 73:2cecc1372acc 168 *
IanBenzMaxim 73:2cecc1372acc 169 * @param[in] *data
IanBenzMaxim 73:2cecc1372acc 170 * User defines write data ranging from 1-255 bytes.
IanBenzMaxim 73:2cecc1372acc 171 *
IanBenzMaxim 73:2cecc1372acc 172 * On Exit:
IanBenzMaxim 73:2cecc1372acc 173 * @param[out] status
IanBenzMaxim 74:23be10c32fa3 174 * Detects the condition of the Start (bit3), N/A (bit2),
IanBenzMaxim 73:2cecc1372acc 175 * Address(bit1) and CRC16(bit0) bits.
IanBenzMaxim 74:23be10c32fa3 176 * b3;0=No Err|1=I2CStart prev-not issued,
IanBenzMaxim 73:2cecc1372acc 177 * b2;0=No Err|1=I2C N/A Err,
IanBenzMaxim 74:23be10c32fa3 178 * b1;0=No Err|1=Addr Err,
IanBenzMaxim 73:2cecc1372acc 179 * b0;0=Valid CRC16|1=Invalid CRC16
IanBenzMaxim 73:2cecc1372acc 180 *
IanBenzMaxim 73:2cecc1372acc 181 * @param[out] wr_status
IanBenzMaxim 73:2cecc1372acc 182 * Indicates which write byte NACK’d. A value of 00h indicates all bytes were acknowledged by the slave.
IanBenzMaxim 73:2cecc1372acc 183 * A non-zero value indicates the byte number that NACK’d.
IanBenzMaxim 73:2cecc1372acc 184 *
IanBenzMaxim 74:23be10c32fa3 185 * @return
IanBenzMaxim 73:2cecc1372acc 186 * true if device selected and written @n
IanBenzMaxim 73:2cecc1372acc 187 * false if failed device select
IanBenzMaxim 73:2cecc1372acc 188 **************************************************************/
IanBenzMaxim 74:23be10c32fa3 189 CmdResult I2C_WriteDataOnly(uint8_t length, uint8_t *data,
IanBenzMaxim 74:23be10c32fa3 190 uint8_t &status, uint8_t &wr_status);
IanBenzMaxim 74:23be10c32fa3 191
IanBenzMaxim 74:23be10c32fa3 192
IanBenzMaxim 73:2cecc1372acc 193 /**********************************************************//**
IanBenzMaxim 74:23be10c32fa3 194 * @brief Write to selected DS28E17's I2C with Stop.
IanBenzMaxim 73:2cecc1372acc 195 * Poll until I2C write complete and receive status info.
IanBenzMaxim 74:23be10c32fa3 196 *
IanBenzMaxim 73:2cecc1372acc 197 * @details Output on I2C: Write Data [1-255], P
IanBenzMaxim 73:2cecc1372acc 198 *
IanBenzMaxim 73:2cecc1372acc 199 * On Entry:
IanBenzMaxim 73:2cecc1372acc 200 * @param[in] length
IanBenzMaxim 73:2cecc1372acc 201 * The number of data bytes to be written ranging from 01h to FFh.
IanBenzMaxim 73:2cecc1372acc 202 * A value of zero will assert the Error Detected pin (ED).
IanBenzMaxim 73:2cecc1372acc 203 *
IanBenzMaxim 73:2cecc1372acc 204 * @param[in] *data
IanBenzMaxim 73:2cecc1372acc 205 * User defines write data ranging from 1-255 bytes.
IanBenzMaxim 73:2cecc1372acc 206 *
IanBenzMaxim 73:2cecc1372acc 207 * On Exit:
IanBenzMaxim 73:2cecc1372acc 208 * @param[out] status
IanBenzMaxim 74:23be10c32fa3 209 * Detects the condition of the Start (bit3), N/A (bit2),
IanBenzMaxim 73:2cecc1372acc 210 * Address(bit1) and CRC16(bit0) bits.
IanBenzMaxim 74:23be10c32fa3 211 * b3;0=No Err|1=I2CStart prev-not issued,
IanBenzMaxim 73:2cecc1372acc 212 * b2;0=No Err|1=I2C N/A Err,
IanBenzMaxim 74:23be10c32fa3 213 * b1;0=No Err|1=Addr Err,
IanBenzMaxim 73:2cecc1372acc 214 * b0;0=Valid CRC16|1=Invalid CRC16
IanBenzMaxim 73:2cecc1372acc 215 *
IanBenzMaxim 73:2cecc1372acc 216 * @param[out] wr_status
IanBenzMaxim 73:2cecc1372acc 217 * Indicates which write byte NACK’d. A value of 00h indicates all bytes were acknowledged by the slave.
IanBenzMaxim 73:2cecc1372acc 218 * A non-zero value indicates the byte number that NACK’d.
IanBenzMaxim 73:2cecc1372acc 219 *
IanBenzMaxim 74:23be10c32fa3 220 * @return
IanBenzMaxim 73:2cecc1372acc 221 * true if device selected and written @n
IanBenzMaxim 73:2cecc1372acc 222 * false if failed device select
IanBenzMaxim 73:2cecc1372acc 223 **************************************************************/
IanBenzMaxim 74:23be10c32fa3 224 CmdResult I2C_WriteDataOnlyWithStop(uint8_t length, uint8_t *data,
IanBenzMaxim 74:23be10c32fa3 225 uint8_t &status, uint8_t &wr_status);
IanBenzMaxim 74:23be10c32fa3 226
IanBenzMaxim 74:23be10c32fa3 227
IanBenzMaxim 73:2cecc1372acc 228 /**********************************************************//**
IanBenzMaxim 73:2cecc1372acc 229 * @brief Write to selected DS28E17's I2C with Stop and poll until I2C write complete
IanBenzMaxim 73:2cecc1372acc 230 * receive status info, and read data with a stop at the end.
IanBenzMaxim 74:23be10c32fa3 231 *
IanBenzMaxim 73:2cecc1372acc 232 * @details Output on I2C:
IanBenzMaxim 73:2cecc1372acc 233 * S, Slave Address + Write, Write Data [1-255],
IanBenzMaxim 73:2cecc1372acc 234 * Sr, Address + Read, Read Data [1-255], P (NACK last read byte)
IanBenzMaxim 73:2cecc1372acc 235 *
IanBenzMaxim 73:2cecc1372acc 236 * On Entry:
IanBenzMaxim 73:2cecc1372acc 237 * @param[in] I2C_addr
IanBenzMaxim 73:2cecc1372acc 238 * Writes I2C address. The least significant bit of the I2C address
IanBenzMaxim 73:2cecc1372acc 239 * is automatically cleared by the command.
IanBenzMaxim 73:2cecc1372acc 240 *
IanBenzMaxim 73:2cecc1372acc 241 * @param[in] length
IanBenzMaxim 73:2cecc1372acc 242 * The number of data bytes to be written ranging from 01h to FFh.
IanBenzMaxim 73:2cecc1372acc 243 * A value of zero will assert the Error Detected pin (ED).
IanBenzMaxim 73:2cecc1372acc 244 *
IanBenzMaxim 73:2cecc1372acc 245 * @param[in] *data
IanBenzMaxim 73:2cecc1372acc 246 * User defines write data ranging from 1-255 bytes.
IanBenzMaxim 73:2cecc1372acc 247 *
IanBenzMaxim 73:2cecc1372acc 248 * @param[in] nu_bytes_read
IanBenzMaxim 73:2cecc1372acc 249 * Number of I2C bytes to read. A value of zero will assert the Error Detected pin (ED).
IanBenzMaxim 73:2cecc1372acc 250 *
IanBenzMaxim 73:2cecc1372acc 251 * On Exit:
IanBenzMaxim 73:2cecc1372acc 252 * @param[out] status
IanBenzMaxim 74:23be10c32fa3 253 * Detects the condition of the Start (bit3), N/A (bit2),
IanBenzMaxim 73:2cecc1372acc 254 * Address(bit1) and CRC16(bit0) bits.
IanBenzMaxim 74:23be10c32fa3 255 * b3;0=No Err|1=I2CStart prev-not issued,
IanBenzMaxim 73:2cecc1372acc 256 * b2;0=No Err|1=I2C N/A Err,
IanBenzMaxim 74:23be10c32fa3 257 * b1;0=No Err|1=Addr Err,
IanBenzMaxim 73:2cecc1372acc 258 * b0;0=Valid CRC16|1=Invalid CRC16
IanBenzMaxim 73:2cecc1372acc 259 *
IanBenzMaxim 73:2cecc1372acc 260 * @param[out] wr_status
IanBenzMaxim 73:2cecc1372acc 261 * Indicates which write byte NACK’d. A value of 00h indicates all bytes were acknowledged by the slave.
IanBenzMaxim 73:2cecc1372acc 262 * A non-zero value indicates the byte number that NACK’d.
IanBenzMaxim 73:2cecc1372acc 263 *
IanBenzMaxim 73:2cecc1372acc 264 * @param[out] *read_data
IanBenzMaxim 73:2cecc1372acc 265 * Array of read data received from I2C.
IanBenzMaxim 73:2cecc1372acc 266 *
IanBenzMaxim 74:23be10c32fa3 267 * @return
IanBenzMaxim 73:2cecc1372acc 268 * true if device selected, written and read @n
IanBenzMaxim 73:2cecc1372acc 269 * false if failed device select or timeout occurred or CRC16 error
IanBenzMaxim 73:2cecc1372acc 270 **************************************************************/
IanBenzMaxim 74:23be10c32fa3 271 CmdResult I2C_WriteReadDataWithStop(uint8_t I2C_addr, uint8_t length,
IanBenzMaxim 74:23be10c32fa3 272 uint8_t *data, uint8_t nu_bytes_read,
IanBenzMaxim 74:23be10c32fa3 273 uint8_t &status, uint8_t &wr_status,
IanBenzMaxim 74:23be10c32fa3 274 uint8_t *read_data);
IanBenzMaxim 74:23be10c32fa3 275
IanBenzMaxim 74:23be10c32fa3 276
IanBenzMaxim 73:2cecc1372acc 277 /**********************************************************//**
IanBenzMaxim 74:23be10c32fa3 278 * @brief Selected DS28E17's and send I2C address and poll until
IanBenzMaxim 74:23be10c32fa3 279 * I2C read address complete, receive status info, and read data
IanBenzMaxim 73:2cecc1372acc 280 * with a stop at the end.
IanBenzMaxim 74:23be10c32fa3 281 *
IanBenzMaxim 73:2cecc1372acc 282 * @details Output on I2C:
IanBenzMaxim 73:2cecc1372acc 283 * S, Slave Address + Read, Read Data [1-255], P (NACK last read byte)
IanBenzMaxim 73:2cecc1372acc 284 *
IanBenzMaxim 73:2cecc1372acc 285 * On Entry:
IanBenzMaxim 73:2cecc1372acc 286 * @param[in] I2C_addr
IanBenzMaxim 73:2cecc1372acc 287 * Writes I2C address. The least significant bit of the I2C address
IanBenzMaxim 73:2cecc1372acc 288 * is automatically cleared by the command.
IanBenzMaxim 73:2cecc1372acc 289 *
IanBenzMaxim 73:2cecc1372acc 290 * On Exit:
IanBenzMaxim 73:2cecc1372acc 291 * @param[out] nu_bytes_read
IanBenzMaxim 73:2cecc1372acc 292 * Number of I2C bytes to read. A value of zero will assert the Error Detected pin (ED).
IanBenzMaxim 73:2cecc1372acc 293 *
IanBenzMaxim 73:2cecc1372acc 294 * @param[out] status
IanBenzMaxim 74:23be10c32fa3 295 * Detects the condition of the Start (bit3), N/A (bit2),
IanBenzMaxim 73:2cecc1372acc 296 * Address(bit1) and CRC16(bit0) bits.
IanBenzMaxim 74:23be10c32fa3 297 * b3;0=No Err|1=I2CStart prev-not issued,
IanBenzMaxim 73:2cecc1372acc 298 * b2;0=No Err|1=I2C N/A Err,
IanBenzMaxim 74:23be10c32fa3 299 * b1;0=No Err|1=Addr Err,
IanBenzMaxim 73:2cecc1372acc 300 * b0;0=Valid CRC16|1=Invalid CRC16
IanBenzMaxim 73:2cecc1372acc 301 *
IanBenzMaxim 73:2cecc1372acc 302 * @param[out] *read_data
IanBenzMaxim 73:2cecc1372acc 303 * Array of read data received from I2C.
IanBenzMaxim 73:2cecc1372acc 304 *
IanBenzMaxim 74:23be10c32fa3 305 * @return
IanBenzMaxim 73:2cecc1372acc 306 * true if device selected, written and read @n
IanBenzMaxim 73:2cecc1372acc 307 * false if failed device select or timeout occurred or CRC16 error
IanBenzMaxim 73:2cecc1372acc 308 **************************************************************/
IanBenzMaxim 74:23be10c32fa3 309 CmdResult I2C_ReadDataWithStop(uint8_t I2C_addr, uint8_t nu_bytes_read,
IanBenzMaxim 74:23be10c32fa3 310 uint8_t &status, uint8_t *read_data);
IanBenzMaxim 74:23be10c32fa3 311
IanBenzMaxim 74:23be10c32fa3 312
IanBenzMaxim 73:2cecc1372acc 313 /**********************************************************//**
IanBenzMaxim 73:2cecc1372acc 314 * @brief Write to Configuration Register of DS28E17.
IanBenzMaxim 74:23be10c32fa3 315 *
IanBenzMaxim 74:23be10c32fa3 316 * @details
IanBenzMaxim 73:2cecc1372acc 317 *
IanBenzMaxim 73:2cecc1372acc 318 * On Entry:
IanBenzMaxim 73:2cecc1372acc 319 * @param[in] data
IanBenzMaxim 73:2cecc1372acc 320 * sent to configuration register
IanBenzMaxim 73:2cecc1372acc 321 *
IanBenzMaxim 73:2cecc1372acc 322 * On Exit:
IanBenzMaxim 73:2cecc1372acc 323 *
IanBenzMaxim 73:2cecc1372acc 324 * @return
IanBenzMaxim 73:2cecc1372acc 325 * true if device selected and written @n
IanBenzMaxim 73:2cecc1372acc 326 * false if failed device select
IanBenzMaxim 73:2cecc1372acc 327 **************************************************************/
IanBenzMaxim 73:2cecc1372acc 328 CmdResult WriteConfigReg(uint8_t data);
IanBenzMaxim 74:23be10c32fa3 329
IanBenzMaxim 74:23be10c32fa3 330
IanBenzMaxim 73:2cecc1372acc 331 /**********************************************************//**
IanBenzMaxim 73:2cecc1372acc 332 * @brief Read the Configuration Register of DS28E17.
IanBenzMaxim 74:23be10c32fa3 333 *
IanBenzMaxim 74:23be10c32fa3 334 * @details
IanBenzMaxim 73:2cecc1372acc 335 *
IanBenzMaxim 73:2cecc1372acc 336 * On Entry:
IanBenzMaxim 73:2cecc1372acc 337 *
IanBenzMaxim 73:2cecc1372acc 338 * On Exit:
IanBenzMaxim 73:2cecc1372acc 339 *
IanBenzMaxim 74:23be10c32fa3 340 * @return
IanBenzMaxim 73:2cecc1372acc 341 * true if device selected and read correctly @n
IanBenzMaxim 73:2cecc1372acc 342 * false if failed device select
IanBenzMaxim 73:2cecc1372acc 343 **************************************************************/
IanBenzMaxim 73:2cecc1372acc 344 CmdResult ReadConfigReg(uint8_t & config);
IanBenzMaxim 74:23be10c32fa3 345
IanBenzMaxim 74:23be10c32fa3 346
IanBenzMaxim 73:2cecc1372acc 347 /**********************************************************//**
IanBenzMaxim 73:2cecc1372acc 348 * @brief The Enable Sleep Mode command puts the device into a low current mode.
IanBenzMaxim 73:2cecc1372acc 349 * All 1-Wire communication is ignored until woken up. Immediately after
IanBenzMaxim 73:2cecc1372acc 350 * the command, the device monitors the WAKEUP input pin and
IanBenzMaxim 73:2cecc1372acc 351 * exits sleep mode on a rising edge.
IanBenzMaxim 74:23be10c32fa3 352 *
IanBenzMaxim 74:23be10c32fa3 353 * @details
IanBenzMaxim 73:2cecc1372acc 354 *
IanBenzMaxim 73:2cecc1372acc 355 * On Entry:
IanBenzMaxim 73:2cecc1372acc 356 *
IanBenzMaxim 73:2cecc1372acc 357 * On Exit:
IanBenzMaxim 73:2cecc1372acc 358 *
IanBenzMaxim 73:2cecc1372acc 359 * @return
IanBenzMaxim 73:2cecc1372acc 360 * true if device selected and written @n
IanBenzMaxim 74:23be10c32fa3 361 * false if failed device select*
IanBenzMaxim 73:2cecc1372acc 362 **************************************************************/
IanBenzMaxim 73:2cecc1372acc 363 CmdResult EnableSleepMode();
IanBenzMaxim 74:23be10c32fa3 364
IanBenzMaxim 74:23be10c32fa3 365
IanBenzMaxim 73:2cecc1372acc 366 /**********************************************************//**
IanBenzMaxim 74:23be10c32fa3 367 * @brief Read the Device Revision of DS28E17. The revision value
IanBenzMaxim 74:23be10c32fa3 368 * should never be zero. The upper nibble is the major revision
IanBenzMaxim 73:2cecc1372acc 369 * and the lower nibble is the minor revision.
IanBenzMaxim 74:23be10c32fa3 370 *
IanBenzMaxim 74:23be10c32fa3 371 * @details
IanBenzMaxim 73:2cecc1372acc 372 *
IanBenzMaxim 73:2cecc1372acc 373 * On Entry:
IanBenzMaxim 73:2cecc1372acc 374 *
IanBenzMaxim 73:2cecc1372acc 375 * On Exit:
IanBenzMaxim 73:2cecc1372acc 376 *
IanBenzMaxim 73:2cecc1372acc 377 * @return
IanBenzMaxim 73:2cecc1372acc 378 * revision value if device selected and read correctly @n
IanBenzMaxim 73:2cecc1372acc 379 * false if failed device select (i.e. 00h)
IanBenzMaxim 73:2cecc1372acc 380 **************************************************************/
IanBenzMaxim 73:2cecc1372acc 381 CmdResult ReadDeviceRevision(uint8_t & rev);
IanBenzMaxim 74:23be10c32fa3 382
IanBenzMaxim 73:2cecc1372acc 383 private:
IanBenzMaxim 74:23be10c32fa3 384
IanBenzMaxim 74:23be10c32fa3 385 CmdResult send_packet(const uint8_t * data, uint8_t data_length,
IanBenzMaxim 73:2cecc1372acc 386 uint8_t & status, uint8_t & wr_status);
IanBenzMaxim 74:23be10c32fa3 387
IanBenzMaxim 73:2cecc1372acc 388 //overloaded function for I2C read only command
IanBenzMaxim 74:23be10c32fa3 389 CmdResult send_packet(const uint8_t * data, uint8_t data_length,
IanBenzMaxim 73:2cecc1372acc 390 uint8_t & status);
IanBenzMaxim 74:23be10c32fa3 391
IanBenzMaxim 73:2cecc1372acc 392 Masters::OneWireMaster &_owm;
IanBenzMaxim 74:23be10c32fa3 393
IanBenzMaxim 73:2cecc1372acc 394 uint16_t _crc16;
IanBenzMaxim 73:2cecc1372acc 395 uint8_t _i2c_speed;
IanBenzMaxim 74:23be10c32fa3 396
IanBenzMaxim 75:8b627804927c 397 static const size_t pollLimit = 10000;
IanBenzMaxim 73:2cecc1372acc 398 static const uint16_t _oddparity[16];
IanBenzMaxim 74:23be10c32fa3 399
IanBenzMaxim 73:2cecc1372acc 400 uint16_t docrc16(uint16_t data);
IanBenzMaxim 73:2cecc1372acc 401 };
IanBenzMaxim 73:2cecc1372acc 402 }
IanBenzMaxim 73:2cecc1372acc 403 }
j3 4:ca27db159b10 404
IanBenzMaxim 74:23be10c32fa3 405 #endif
j3 17:b646b1e3970b 406