Implementation of 1-Wire with added Alarm Search Functionality

Dependents:   Max32630_One_Wire_Interface

Committer:
j3
Date:
Fri Feb 12 22:56:13 2016 +0000
Revision:
7:78a8857b3810
Parent:
4:ca27db159b10
Child:
13:d1bdb03703de
Finished porting DS28E17 code, haven't tested yet.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
j3 4:ca27db159b10 1 /******************************************************************//**
j3 4:ca27db159b10 2 * @file ds28e17.cpp
j3 4:ca27db159b10 3 *
j3 4:ca27db159b10 4 * @author Justin Jordan
j3 4:ca27db159b10 5 *
j3 4:ca27db159b10 6 * @version 0.0.0
j3 4:ca27db159b10 7 *
j3 4:ca27db159b10 8 * Started: 31JAN16
j3 4:ca27db159b10 9 *
j3 4:ca27db159b10 10 * Updated:
j3 4:ca27db159b10 11 *
j3 4:ca27db159b10 12 * @brief Source file for DS28E17 1-wire to I2C bridge
j3 4:ca27db159b10 13 ***********************************************************************
j3 4:ca27db159b10 14 * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved.
j3 4:ca27db159b10 15 *
j3 4:ca27db159b10 16 * Permission is hereby granted, free of charge, to any person obtaining a
j3 4:ca27db159b10 17 * copy of this software and associated documentation files (the "Software"),
j3 4:ca27db159b10 18 * to deal in the Software without restriction, including without limitation
j3 4:ca27db159b10 19 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
j3 4:ca27db159b10 20 * and/or sell copies of the Software, and to permit persons to whom the
j3 4:ca27db159b10 21 * Software is furnished to do so, subject to the following conditions:
j3 4:ca27db159b10 22 *
j3 4:ca27db159b10 23 * The above copyright notice and this permission notice shall be included
j3 4:ca27db159b10 24 * in all copies or substantial portions of the Software.
j3 4:ca27db159b10 25 *
j3 4:ca27db159b10 26 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
j3 4:ca27db159b10 27 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
j3 4:ca27db159b10 28 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
j3 4:ca27db159b10 29 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
j3 4:ca27db159b10 30 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
j3 4:ca27db159b10 31 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
j3 4:ca27db159b10 32 * OTHER DEALINGS IN THE SOFTWARE.
j3 4:ca27db159b10 33 *
j3 4:ca27db159b10 34 * Except as contained in this notice, the name of Maxim Integrated
j3 4:ca27db159b10 35 * Products, Inc. shall not be used except as stated in the Maxim Integrated
j3 4:ca27db159b10 36 * Products, Inc. Branding Policy.
j3 4:ca27db159b10 37 *
j3 4:ca27db159b10 38 * The mere transfer of this software does not imply any licenses
j3 4:ca27db159b10 39 * of trade secrets, proprietary technology, copyrights, patents,
j3 4:ca27db159b10 40 * trademarks, maskwork rights, or any other form of intellectual
j3 4:ca27db159b10 41 * property whatsoever. Maxim Integrated Products, Inc. retains all
j3 4:ca27db159b10 42 * ownership rights.
j3 4:ca27db159b10 43 **********************************************************************/
j3 4:ca27db159b10 44
j3 4:ca27db159b10 45
j3 7:78a8857b3810 46 #include "ds28e17.h"
j3 4:ca27db159b10 47
j3 7:78a8857b3810 48 const uint16_t Ds28e17::_oddparity[] = { 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0 };
j3 4:ca27db159b10 49
j3 4:ca27db159b10 50
j3 4:ca27db159b10 51 //*********************************************************************
j3 7:78a8857b3810 52 Ds28e17::Ds28e17(OneWireInterface &owm)
j3 7:78a8857b3810 53 :_p_owm(&owm), _owm_owner(false)
j3 4:ca27db159b10 54 {
j3 7:78a8857b3810 55
j3 4:ca27db159b10 56 }
j3 4:ca27db159b10 57
j3 4:ca27db159b10 58
j3 4:ca27db159b10 59 //*********************************************************************
j3 4:ca27db159b10 60 Ds28e17::~Ds28e17()
j3 4:ca27db159b10 61 {
j3 4:ca27db159b10 62 if(_owm_owner)
j3 4:ca27db159b10 63 {
j3 4:ca27db159b10 64 delete _p_owm;
j3 4:ca27db159b10 65 }
j3 4:ca27db159b10 66 }
j3 4:ca27db159b10 67
j3 4:ca27db159b10 68
j3 4:ca27db159b10 69 //*********************************************************************
j3 4:ca27db159b10 70 bool Ds28e17::I2C_WriteDataWithStop(uint8_t I2C_addr, uint8_t length,
j3 7:78a8857b3810 71 uint8_t *data, uint8_t &status,
j3 7:78a8857b3810 72 uint8_t &wr_status)
j3 4:ca27db159b10 73 {
j3 4:ca27db159b10 74 bool rtn_val = false;
j3 4:ca27db159b10 75
j3 7:78a8857b3810 76 size_t send_cnt = 0;
j3 7:78a8857b3810 77 size_t idx = 0;
j3 7:78a8857b3810 78 uint32_t poll_count = 0;
j3 7:78a8857b3810 79 uint8_t send_block[0xff];
j3 7:78a8857b3810 80
j3 7:78a8857b3810 81 if(_p_owm->OWMatchROM())
j3 7:78a8857b3810 82 {
j3 7:78a8857b3810 83 //seed the crc
j3 7:78a8857b3810 84 _crc16 = 0;
j3 7:78a8857b3810 85
j3 7:78a8857b3810 86 // Form the 1-Wire Packet
j3 7:78a8857b3810 87
j3 7:78a8857b3810 88 // I2C Write Data with Stop command
j3 7:78a8857b3810 89 send_block[send_cnt] = CMD_I2C_WRITE_W_STOP;
j3 7:78a8857b3810 90 docrc16(send_block[send_cnt++]);
j3 7:78a8857b3810 91
j3 7:78a8857b3810 92 // I2C Address
j3 7:78a8857b3810 93 send_block[send_cnt] = I2C_addr;
j3 7:78a8857b3810 94 docrc16(send_block[send_cnt++]);
j3 7:78a8857b3810 95
j3 7:78a8857b3810 96 // Length field
j3 7:78a8857b3810 97 send_block[send_cnt] = length;
j3 7:78a8857b3810 98 docrc16(send_block[send_cnt++]);
j3 7:78a8857b3810 99
j3 7:78a8857b3810 100 // Form the write data
j3 7:78a8857b3810 101 for (idx = 0; idx < length; idx++)
j3 7:78a8857b3810 102 {
j3 7:78a8857b3810 103 send_block[send_cnt] = data[idx];
j3 7:78a8857b3810 104 docrc16(send_block[send_cnt++]);
j3 7:78a8857b3810 105 }
j3 7:78a8857b3810 106
j3 7:78a8857b3810 107 // Form the CRC16
j3 7:78a8857b3810 108 _crc16 = _crc16^0xFFFF;
j3 7:78a8857b3810 109 send_block[send_cnt++] = ((uint8_t)(_crc16 & 0xFF));
j3 7:78a8857b3810 110 send_block[send_cnt++] = ((uint8_t)((_crc16 >> 8) & 0xFF));
j3 7:78a8857b3810 111
j3 7:78a8857b3810 112 // Send Packet
j3 7:78a8857b3810 113 _p_owm->OWWriteBlock(send_block, send_cnt);
j3 7:78a8857b3810 114
j3 7:78a8857b3810 115 // Poll for Zero 1-Wire bit and return if an error occurs
j3 7:78a8857b3810 116 while(_p_owm->OWReadBit() && (poll_count++ < POLL_LIMIT));
j3 7:78a8857b3810 117
j3 7:78a8857b3810 118 if(poll_count < POLL_LIMIT)
j3 7:78a8857b3810 119 {
j3 7:78a8857b3810 120 //Read Status
j3 7:78a8857b3810 121 status = _p_owm->OWReadByte();
j3 7:78a8857b3810 122
j3 7:78a8857b3810 123 //Read Write Status
j3 7:78a8857b3810 124 wr_status = _p_owm->OWReadByte();
j3 7:78a8857b3810 125
j3 7:78a8857b3810 126 rtn_val = true;
j3 7:78a8857b3810 127 }
j3 7:78a8857b3810 128 else
j3 7:78a8857b3810 129 {
j3 7:78a8857b3810 130 rtn_val = false;
j3 7:78a8857b3810 131 }
j3 7:78a8857b3810 132
j3 7:78a8857b3810 133 }
j3 7:78a8857b3810 134 else
j3 7:78a8857b3810 135 {
j3 7:78a8857b3810 136 rtn_val = false;
j3 7:78a8857b3810 137 }
j3 4:ca27db159b10 138
j3 4:ca27db159b10 139 return(rtn_val);
j3 4:ca27db159b10 140 }
j3 4:ca27db159b10 141
j3 4:ca27db159b10 142
j3 4:ca27db159b10 143 //*********************************************************************
j3 4:ca27db159b10 144 bool Ds28e17::I2C_WriteDataNoStop(uint8_t I2C_addr, uint8_t length,
j3 7:78a8857b3810 145 uint8_t *data, uint8_t &status,
j3 7:78a8857b3810 146 uint8_t &wr_status)
j3 4:ca27db159b10 147 {
j3 4:ca27db159b10 148 bool rtn_val = false;
j3 4:ca27db159b10 149
j3 7:78a8857b3810 150 size_t send_cnt = 0;
j3 7:78a8857b3810 151 size_t idx = 0;
j3 7:78a8857b3810 152 uint32_t poll_count = 0;
j3 7:78a8857b3810 153 uint8_t send_block[0xff];
j3 7:78a8857b3810 154
j3 7:78a8857b3810 155 if(_p_owm->OWMatchROM())
j3 7:78a8857b3810 156 {
j3 7:78a8857b3810 157 // seed the crc
j3 7:78a8857b3810 158 _crc16 = 0;
j3 7:78a8857b3810 159
j3 7:78a8857b3810 160 // I2C Write Data with Stop command
j3 7:78a8857b3810 161 send_block[send_cnt] = CMD_I2C_WRITE_NO_STOP;
j3 7:78a8857b3810 162 docrc16(send_block[send_cnt++]);
j3 7:78a8857b3810 163
j3 7:78a8857b3810 164 // I2C Address
j3 7:78a8857b3810 165 send_block[send_cnt] = I2C_addr;
j3 7:78a8857b3810 166 docrc16(send_block[send_cnt++]);
j3 7:78a8857b3810 167
j3 7:78a8857b3810 168 // Length field
j3 7:78a8857b3810 169 send_block[send_cnt] = length;
j3 7:78a8857b3810 170 docrc16(send_block[send_cnt++]);
j3 7:78a8857b3810 171
j3 7:78a8857b3810 172 // Form the write data
j3 7:78a8857b3810 173 for(idx = 0; idx < length; idx++)
j3 7:78a8857b3810 174 {
j3 7:78a8857b3810 175 send_block[send_cnt] = data[idx];
j3 7:78a8857b3810 176 docrc16(send_block[send_cnt++]);
j3 7:78a8857b3810 177 }
j3 7:78a8857b3810 178
j3 7:78a8857b3810 179 // Form the CRC16
j3 7:78a8857b3810 180 _crc16 = _crc16^0xFFFF;
j3 7:78a8857b3810 181 send_block[send_cnt++] = ((uint8_t)(_crc16 & 0xFF));
j3 7:78a8857b3810 182 send_block[send_cnt++] = ((uint8_t)((_crc16 >> 8) & 0xFF));
j3 7:78a8857b3810 183
j3 7:78a8857b3810 184 // Send Packet
j3 7:78a8857b3810 185 _p_owm->OWBlock(send_block, send_cnt);
j3 7:78a8857b3810 186
j3 7:78a8857b3810 187 // Poll for Zero 1-Wire bit and return if an error occurs
j3 7:78a8857b3810 188 while(_p_owm->OWReadBit() && (poll_count++ < POLL_LIMIT));
j3 7:78a8857b3810 189
j3 7:78a8857b3810 190 if(poll_count < POLL_LIMIT)
j3 7:78a8857b3810 191 {
j3 7:78a8857b3810 192 //Read Status
j3 7:78a8857b3810 193 status = _p_owm->OWReadByte();
j3 7:78a8857b3810 194
j3 7:78a8857b3810 195 //Read Write Status
j3 7:78a8857b3810 196 wr_status = _p_owm->OWReadByte();
j3 7:78a8857b3810 197
j3 7:78a8857b3810 198 rtn_val = true;
j3 7:78a8857b3810 199 }
j3 7:78a8857b3810 200 else
j3 7:78a8857b3810 201 {
j3 7:78a8857b3810 202 rtn_val = false;
j3 7:78a8857b3810 203 }
j3 7:78a8857b3810 204 }
j3 7:78a8857b3810 205 else
j3 7:78a8857b3810 206 {
j3 7:78a8857b3810 207 rtn_val = false;
j3 7:78a8857b3810 208 }
j3 7:78a8857b3810 209
j3 4:ca27db159b10 210 return(rtn_val);
j3 4:ca27db159b10 211 }
j3 4:ca27db159b10 212
j3 4:ca27db159b10 213
j3 4:ca27db159b10 214 //*********************************************************************
j3 4:ca27db159b10 215 bool Ds28e17::I2C_WriteDataOnly(uint8_t length, uint8_t *data,
j3 7:78a8857b3810 216 uint8_t &status, uint8_t &wr_status)
j3 4:ca27db159b10 217 {
j3 4:ca27db159b10 218 bool rtn_val = false;
j3 4:ca27db159b10 219
j3 7:78a8857b3810 220 size_t send_cnt = 0;
j3 7:78a8857b3810 221 size_t idx = 0;
j3 7:78a8857b3810 222 uint32_t poll_count = 0;
j3 7:78a8857b3810 223 uint8_t send_block[0xff];
j3 7:78a8857b3810 224
j3 7:78a8857b3810 225 if(_p_owm->OWMatchROM())
j3 7:78a8857b3810 226 {
j3 7:78a8857b3810 227 // seed the crc
j3 7:78a8857b3810 228 _crc16 = 0;
j3 7:78a8857b3810 229
j3 7:78a8857b3810 230 // Form the 1-Wire Packet
j3 7:78a8857b3810 231
j3 7:78a8857b3810 232 // I2C Write Data with Stop command
j3 7:78a8857b3810 233 send_block[send_cnt] = CMD_I2C_WRITE_ONLY;
j3 7:78a8857b3810 234 docrc16(send_block[send_cnt++]);
j3 7:78a8857b3810 235
j3 7:78a8857b3810 236 // Length field
j3 7:78a8857b3810 237 send_block[send_cnt] = length;
j3 7:78a8857b3810 238 docrc16(send_block[send_cnt++]);
j3 7:78a8857b3810 239
j3 7:78a8857b3810 240 // Form the write data
j3 7:78a8857b3810 241 for (idx = 0; idx < length; idx++)
j3 7:78a8857b3810 242 {
j3 7:78a8857b3810 243 send_block[send_cnt] = data[idx];
j3 7:78a8857b3810 244 docrc16(send_block[send_cnt++]);
j3 7:78a8857b3810 245 }
j3 7:78a8857b3810 246
j3 7:78a8857b3810 247 // Form the CRC16\
j3 7:78a8857b3810 248 _crc16 = _crc16^0xFFFF;
j3 7:78a8857b3810 249 send_block[send_cnt++] = (_crc16 & 0xFF);
j3 7:78a8857b3810 250 send_block[send_cnt++] = ((_crc16 >> 8) & 0xFF);
j3 7:78a8857b3810 251
j3 7:78a8857b3810 252 // Send Packet
j3 7:78a8857b3810 253 _p_owm->OWBlock(send_block, send_cnt);
j3 7:78a8857b3810 254
j3 7:78a8857b3810 255 // Poll for Zero 1-Wire bit and return if an error occurs
j3 7:78a8857b3810 256 while(_p_owm->OWReadBit() && (poll_count++ < POLL_LIMIT));
j3 7:78a8857b3810 257
j3 7:78a8857b3810 258
j3 7:78a8857b3810 259 if(poll_count < POLL_LIMIT)
j3 7:78a8857b3810 260 {
j3 7:78a8857b3810 261 // Read Status
j3 7:78a8857b3810 262 status = _p_owm->OWReadByte();
j3 7:78a8857b3810 263
j3 7:78a8857b3810 264 // Read Write Status
j3 7:78a8857b3810 265 wr_status = _p_owm->OWReadByte();
j3 7:78a8857b3810 266
j3 7:78a8857b3810 267 rtn_val = true;
j3 7:78a8857b3810 268 }
j3 7:78a8857b3810 269 else
j3 7:78a8857b3810 270 {
j3 7:78a8857b3810 271 rtn_val = false;
j3 7:78a8857b3810 272 }
j3 7:78a8857b3810 273 }
j3 7:78a8857b3810 274 else
j3 7:78a8857b3810 275 {
j3 7:78a8857b3810 276 rtn_val = false;
j3 7:78a8857b3810 277 }
j3 7:78a8857b3810 278
j3 7:78a8857b3810 279
j3 4:ca27db159b10 280 return(rtn_val);
j3 4:ca27db159b10 281 }
j3 4:ca27db159b10 282
j3 4:ca27db159b10 283
j3 4:ca27db159b10 284 //*********************************************************************
j3 4:ca27db159b10 285 bool Ds28e17::I2C_WriteDataOnlyWithStop(uint8_t length, uint8_t *data,
j3 7:78a8857b3810 286 uint8_t &status, uint8_t &wr_status)
j3 4:ca27db159b10 287 {
j3 4:ca27db159b10 288 bool rtn_val = false;
j3 4:ca27db159b10 289
j3 7:78a8857b3810 290 size_t send_cnt = 0;
j3 7:78a8857b3810 291 size_t idx = 0;
j3 7:78a8857b3810 292 uint32_t poll_count = 0;
j3 7:78a8857b3810 293 uint8_t send_block[0xff];
j3 7:78a8857b3810 294
j3 7:78a8857b3810 295 if(_p_owm->OWMatchROM())
j3 7:78a8857b3810 296 {
j3 7:78a8857b3810 297 //seed the crc
j3 7:78a8857b3810 298 _crc16 = 0;
j3 7:78a8857b3810 299
j3 7:78a8857b3810 300 // Form the 1-Wire Packet
j3 7:78a8857b3810 301
j3 7:78a8857b3810 302 // I2C Write Data with Stop command
j3 7:78a8857b3810 303 send_block[send_cnt] = CMD_I2C_WRITE_ONLY_W_STOP;
j3 7:78a8857b3810 304 docrc16(send_block[send_cnt++]);
j3 7:78a8857b3810 305
j3 7:78a8857b3810 306 // Length field
j3 7:78a8857b3810 307 send_block[send_cnt] = length;
j3 7:78a8857b3810 308 docrc16(send_block[send_cnt++]);
j3 7:78a8857b3810 309
j3 7:78a8857b3810 310 // Form the write data
j3 7:78a8857b3810 311 for (idx = 0; idx < length; idx++)
j3 7:78a8857b3810 312 {
j3 7:78a8857b3810 313 send_block[send_cnt] = data[idx];
j3 7:78a8857b3810 314 docrc16(send_block[send_cnt++]);
j3 7:78a8857b3810 315 }
j3 7:78a8857b3810 316
j3 7:78a8857b3810 317 // Form the CRC16
j3 7:78a8857b3810 318 _crc16 = _crc16^0xFFFF;
j3 7:78a8857b3810 319 send_block[send_cnt++] = (_crc16 & 0xFF);
j3 7:78a8857b3810 320 send_block[send_cnt++] = ((_crc16 >> 8) & 0xFF);
j3 7:78a8857b3810 321
j3 7:78a8857b3810 322 // Send Packet
j3 7:78a8857b3810 323 _p_owm->OWBlock(send_block, send_cnt);
j3 7:78a8857b3810 324
j3 7:78a8857b3810 325 // Poll for Zero 1-Wire bit and return if an error occurs
j3 7:78a8857b3810 326 while(_p_owm->OWReadBit() && (poll_count++ < POLL_LIMIT));
j3 7:78a8857b3810 327
j3 7:78a8857b3810 328 if(poll_count < POLL_LIMIT)
j3 7:78a8857b3810 329 {
j3 7:78a8857b3810 330 // Read Status
j3 7:78a8857b3810 331 status = _p_owm->OWReadByte();
j3 7:78a8857b3810 332
j3 7:78a8857b3810 333 // Read Write Status
j3 7:78a8857b3810 334 wr_status = _p_owm->OWReadByte();
j3 7:78a8857b3810 335
j3 7:78a8857b3810 336 rtn_val = true;
j3 7:78a8857b3810 337 }
j3 7:78a8857b3810 338 else
j3 7:78a8857b3810 339 {
j3 7:78a8857b3810 340 rtn_val = false;
j3 7:78a8857b3810 341 }
j3 7:78a8857b3810 342 }
j3 7:78a8857b3810 343 else
j3 7:78a8857b3810 344 {
j3 7:78a8857b3810 345 rtn_val = false;
j3 7:78a8857b3810 346 }
j3 7:78a8857b3810 347
j3 4:ca27db159b10 348 return(rtn_val);
j3 4:ca27db159b10 349 }
j3 4:ca27db159b10 350
j3 4:ca27db159b10 351
j3 4:ca27db159b10 352 //*********************************************************************
j3 4:ca27db159b10 353 bool Ds28e17::I2C_WriteReadDataWithStop(uint8_t I2C_addr, uint8_t length,
j3 4:ca27db159b10 354 uint8_t *data, uint8_t nu_bytes_read,
j3 7:78a8857b3810 355 uint8_t &status, uint8_t &wr_status,
j3 4:ca27db159b10 356 uint8_t *read_data)
j3 4:ca27db159b10 357 {
j3 4:ca27db159b10 358 bool rtn_val = false;
j3 4:ca27db159b10 359
j3 7:78a8857b3810 360 size_t send_cnt = 0;
j3 7:78a8857b3810 361 size_t idx = 0;
j3 7:78a8857b3810 362 uint32_t poll_count = 0;
j3 7:78a8857b3810 363 uint8_t send_block[0xff];
j3 7:78a8857b3810 364
j3 7:78a8857b3810 365 if(_p_owm->OWMatchROM())
j3 7:78a8857b3810 366 {
j3 7:78a8857b3810 367 //seed the crc
j3 7:78a8857b3810 368 _crc16 = 0;
j3 7:78a8857b3810 369
j3 7:78a8857b3810 370 // Form the 1-Wire Packet
j3 7:78a8857b3810 371
j3 7:78a8857b3810 372 // I2C Write Data with Stop command
j3 7:78a8857b3810 373 send_block[send_cnt] = CMD_I2C_WRITE_READ_W_STOP;
j3 7:78a8857b3810 374 docrc16(send_block[send_cnt++]);
j3 7:78a8857b3810 375
j3 7:78a8857b3810 376 // I2C Address
j3 7:78a8857b3810 377 send_block[send_cnt] = I2C_addr;
j3 7:78a8857b3810 378 docrc16(send_block[send_cnt++]);
j3 7:78a8857b3810 379
j3 7:78a8857b3810 380 // Length field
j3 7:78a8857b3810 381 send_block[send_cnt] = length;
j3 7:78a8857b3810 382 docrc16(send_block[send_cnt++]);
j3 7:78a8857b3810 383
j3 7:78a8857b3810 384 // Form the write data
j3 7:78a8857b3810 385 for (idx = 0; idx < length; idx++)
j3 7:78a8857b3810 386 {
j3 7:78a8857b3810 387 send_block[send_cnt] = data[idx];
j3 7:78a8857b3810 388 docrc16(send_block[send_cnt++]);
j3 7:78a8857b3810 389 }
j3 7:78a8857b3810 390
j3 7:78a8857b3810 391 // # of bytes to Read field
j3 7:78a8857b3810 392 send_block[send_cnt] = nu_bytes_read;
j3 7:78a8857b3810 393 docrc16(send_block[send_cnt++]);
j3 7:78a8857b3810 394
j3 7:78a8857b3810 395 // Form the CRC16
j3 7:78a8857b3810 396 _crc16 = _crc16^0xFFFF;
j3 7:78a8857b3810 397 send_block[send_cnt++] = (_crc16 & 0xFF);
j3 7:78a8857b3810 398 send_block[send_cnt++] = ((_crc16 >> 8) & 0xFF);
j3 7:78a8857b3810 399
j3 7:78a8857b3810 400 // Send Packet
j3 7:78a8857b3810 401 _p_owm->OWBlock(send_block, send_cnt);
j3 7:78a8857b3810 402
j3 7:78a8857b3810 403 // Poll for Zero 1-Wire bit and return if an error occurs
j3 7:78a8857b3810 404 while(_p_owm->OWReadBit() && (poll_count++ < POLL_LIMIT));
j3 7:78a8857b3810 405
j3 7:78a8857b3810 406 if(poll_count < POLL_LIMIT)
j3 7:78a8857b3810 407 {
j3 7:78a8857b3810 408 // Read Status
j3 7:78a8857b3810 409 status = _p_owm->OWReadByte();
j3 7:78a8857b3810 410
j3 7:78a8857b3810 411 // Read Write Status
j3 7:78a8857b3810 412 wr_status = _p_owm->OWReadByte();
j3 7:78a8857b3810 413
j3 7:78a8857b3810 414 //seed the crc for read bytes
j3 7:78a8857b3810 415 _crc16 = 0;
j3 7:78a8857b3810 416
j3 7:78a8857b3810 417 // Read Data
j3 7:78a8857b3810 418 for(idx = 0; idx < nu_bytes_read; idx++)
j3 7:78a8857b3810 419 {
j3 7:78a8857b3810 420 read_data[idx] = _p_owm->OWReadByte();
j3 7:78a8857b3810 421 docrc16(read_data[idx]);
j3 7:78a8857b3810 422 }
j3 7:78a8857b3810 423
j3 7:78a8857b3810 424 /********** TODO **********/
j3 7:78a8857b3810 425 // need to check datasheet, below was left commented for a reason.
j3 7:78a8857b3810 426 // need to see why
j3 7:78a8857b3810 427
j3 7:78a8857b3810 428 // Read the CRC16
j3 7:78a8857b3810 429 //docrc16(OWReadByte()); //Receive first crc16 byte
j3 7:78a8857b3810 430 //docrc16(OWReadByte()); //Receive second crc16 byte
j3 7:78a8857b3810 431
j3 7:78a8857b3810 432 // check CRC16
j3 7:78a8857b3810 433 //if (CRC16 != 0xB001)
j3 7:78a8857b3810 434 // return false;
j3 7:78a8857b3810 435
j3 7:78a8857b3810 436 rtn_val = true;
j3 7:78a8857b3810 437 }
j3 7:78a8857b3810 438 else
j3 7:78a8857b3810 439 {
j3 7:78a8857b3810 440 rtn_val = false;
j3 7:78a8857b3810 441 }
j3 7:78a8857b3810 442 }
j3 7:78a8857b3810 443 else
j3 7:78a8857b3810 444 {
j3 7:78a8857b3810 445 rtn_val = false;
j3 7:78a8857b3810 446 }
j3 7:78a8857b3810 447
j3 4:ca27db159b10 448 return(rtn_val);
j3 4:ca27db159b10 449 }
j3 4:ca27db159b10 450
j3 4:ca27db159b10 451
j3 4:ca27db159b10 452 //*********************************************************************
j3 4:ca27db159b10 453 bool Ds28e17::I2C_ReadDataWithStop(uint8_t I2C_addr, uint8_t nu_bytes_read,
j3 7:78a8857b3810 454 uint8_t &status, uint8_t *read_data)
j3 4:ca27db159b10 455 {
j3 4:ca27db159b10 456 bool rtn_val = false;
j3 4:ca27db159b10 457
j3 7:78a8857b3810 458 size_t send_cnt = 0;
j3 7:78a8857b3810 459 size_t idx = 0;
j3 7:78a8857b3810 460 uint32_t poll_count = 0;
j3 7:78a8857b3810 461 uint8_t send_block[0xff];
j3 7:78a8857b3810 462
j3 7:78a8857b3810 463 if(_p_owm->OWMatchROM())
j3 7:78a8857b3810 464 {
j3 7:78a8857b3810 465 //seed the crc for transmit bytes
j3 7:78a8857b3810 466 _crc16 = 0;
j3 7:78a8857b3810 467
j3 7:78a8857b3810 468 // Form the 1-Wire Packet to send
j3 7:78a8857b3810 469
j3 7:78a8857b3810 470 // I2C Write Data with Stop command
j3 7:78a8857b3810 471 send_block[send_cnt] = CMD_I2C_READ_W_STOP;
j3 7:78a8857b3810 472 docrc16(send_block[send_cnt++]);
j3 7:78a8857b3810 473
j3 7:78a8857b3810 474 // I2C Address
j3 7:78a8857b3810 475 send_block[send_cnt] = I2C_addr;
j3 7:78a8857b3810 476 docrc16(send_block[send_cnt++]);
j3 7:78a8857b3810 477
j3 7:78a8857b3810 478 // # of bytes to Read field
j3 7:78a8857b3810 479 send_block[send_cnt] = nu_bytes_read;
j3 7:78a8857b3810 480 docrc16(send_block[send_cnt++]);
j3 7:78a8857b3810 481
j3 7:78a8857b3810 482 // Form the CRC16
j3 7:78a8857b3810 483 _crc16 = _crc16^0xFFFF;
j3 7:78a8857b3810 484 send_block[send_cnt++] = (_crc16 & 0xFF);
j3 7:78a8857b3810 485 send_block[send_cnt++] = ((_crc16 >> 8) & 0xFF);
j3 7:78a8857b3810 486
j3 7:78a8857b3810 487 // Send Packet
j3 7:78a8857b3810 488 _p_owm->OWBlock(send_block, send_cnt);
j3 7:78a8857b3810 489
j3 7:78a8857b3810 490 // Poll for Zero 1-Wire bit and return if an error occurs
j3 7:78a8857b3810 491 while(_p_owm->OWReadBit() && (poll_count++ < POLL_LIMIT));
j3 7:78a8857b3810 492
j3 7:78a8857b3810 493 if(poll_count < POLL_LIMIT)
j3 7:78a8857b3810 494 {
j3 7:78a8857b3810 495 // Read Status
j3 7:78a8857b3810 496 status = _p_owm->OWReadByte();
j3 7:78a8857b3810 497
j3 7:78a8857b3810 498 //seed the crc for read bytes
j3 7:78a8857b3810 499 _crc16 = 0;
j3 7:78a8857b3810 500
j3 7:78a8857b3810 501 // Read Data
j3 7:78a8857b3810 502 for(idx = 0; idx < nu_bytes_read; idx++)
j3 7:78a8857b3810 503 {
j3 7:78a8857b3810 504 read_data[idx] = _p_owm->OWReadByte();
j3 7:78a8857b3810 505 docrc16(read_data[idx]);
j3 7:78a8857b3810 506 }
j3 7:78a8857b3810 507
j3 7:78a8857b3810 508 /********** TODO **********/
j3 7:78a8857b3810 509 // need to check datasheet, below was left commented for a reason.
j3 7:78a8857b3810 510 // need to see why
j3 7:78a8857b3810 511
j3 7:78a8857b3810 512 // Read the CRC16
j3 7:78a8857b3810 513 //docrc16(OWReadByte()); //Receive first crc16 byte
j3 7:78a8857b3810 514 //docrc16(OWReadByte()); //Receive second crc16 byte
j3 7:78a8857b3810 515
j3 7:78a8857b3810 516 // check CRC16
j3 7:78a8857b3810 517 //if (CRC16 != 0xB001)
j3 7:78a8857b3810 518 // return false;
j3 7:78a8857b3810 519
j3 7:78a8857b3810 520 rtn_val = true;
j3 7:78a8857b3810 521 }
j3 7:78a8857b3810 522 else
j3 7:78a8857b3810 523 {
j3 7:78a8857b3810 524 rtn_val = false;
j3 7:78a8857b3810 525 }
j3 7:78a8857b3810 526 }
j3 7:78a8857b3810 527 else
j3 7:78a8857b3810 528 {
j3 7:78a8857b3810 529 rtn_val = false;
j3 7:78a8857b3810 530 }
j3 7:78a8857b3810 531
j3 4:ca27db159b10 532 return(rtn_val);
j3 4:ca27db159b10 533 }
j3 4:ca27db159b10 534
j3 4:ca27db159b10 535
j3 4:ca27db159b10 536 //*********************************************************************
j3 7:78a8857b3810 537 bool Ds28e17::WriteConfigReg(uint8_t data)
j3 7:78a8857b3810 538 {
j3 7:78a8857b3810 539 bool rtn_val = false;
j3 7:78a8857b3810 540
j3 7:78a8857b3810 541 if(_p_owm->OWMatchROM())
j3 7:78a8857b3810 542 {
j3 7:78a8857b3810 543 // Send CMD and Data
j3 7:78a8857b3810 544 _p_owm->OWWriteByte(CMD_WRITE_CONFIG_REG);
j3 7:78a8857b3810 545 _p_owm->OWWriteByte(data);
j3 7:78a8857b3810 546 _i2c_speed = data & 0x03; // Save off _i2c_speed setting to be used by other functions
j3 7:78a8857b3810 547 rtn_val = true;
j3 7:78a8857b3810 548 }
j3 7:78a8857b3810 549 else
j3 7:78a8857b3810 550 {
j3 7:78a8857b3810 551 rtn_val = false;
j3 7:78a8857b3810 552 }
j3 7:78a8857b3810 553
j3 7:78a8857b3810 554 return(rtn_val);
j3 7:78a8857b3810 555 }
j3 7:78a8857b3810 556
j3 7:78a8857b3810 557
j3 7:78a8857b3810 558 //*********************************************************************
j3 7:78a8857b3810 559 uint8_t Ds28e17::ReadConfigReg(void)
j3 7:78a8857b3810 560 {
j3 7:78a8857b3810 561 uint8_t rtn_val = false;
j3 7:78a8857b3810 562
j3 7:78a8857b3810 563 if(_p_owm->OWMatchROM())
j3 7:78a8857b3810 564 {
j3 7:78a8857b3810 565 // Send CMD and receive Data
j3 7:78a8857b3810 566 _p_owm->OWWriteByte(CMD_READ_CONFIG_REG);
j3 7:78a8857b3810 567 rtn_val = _p_owm->OWReadByte();
j3 7:78a8857b3810 568 }
j3 7:78a8857b3810 569 else
j3 7:78a8857b3810 570 {
j3 7:78a8857b3810 571 rtn_val = false;
j3 7:78a8857b3810 572 }
j3 7:78a8857b3810 573
j3 7:78a8857b3810 574 return(rtn_val);
j3 7:78a8857b3810 575 }
j3 7:78a8857b3810 576
j3 7:78a8857b3810 577
j3 7:78a8857b3810 578 //*********************************************************************
j3 7:78a8857b3810 579 bool Ds28e17::DisableOWMode()
j3 7:78a8857b3810 580 {
j3 7:78a8857b3810 581 bool rtn_val = false;
j3 7:78a8857b3810 582
j3 7:78a8857b3810 583 if(_p_owm->OWMatchROM())
j3 7:78a8857b3810 584 {
j3 7:78a8857b3810 585 // Send CMD
j3 7:78a8857b3810 586 _p_owm->OWWriteByte(CMD_DISABLE_OW_MODE);
j3 7:78a8857b3810 587 rtn_val = true;
j3 7:78a8857b3810 588 }
j3 7:78a8857b3810 589 else
j3 7:78a8857b3810 590 {
j3 7:78a8857b3810 591 rtn_val = false;
j3 7:78a8857b3810 592 }
j3 7:78a8857b3810 593
j3 7:78a8857b3810 594 return(rtn_val);
j3 7:78a8857b3810 595 }
j3 7:78a8857b3810 596
j3 7:78a8857b3810 597
j3 7:78a8857b3810 598 //*********************************************************************
j3 7:78a8857b3810 599 bool Ds28e17::EnableSleepMode()
j3 7:78a8857b3810 600 {
j3 7:78a8857b3810 601 bool rtn_val = false;
j3 7:78a8857b3810 602
j3 7:78a8857b3810 603 if(_p_owm->OWMatchROM())
j3 7:78a8857b3810 604 {
j3 7:78a8857b3810 605 // Send CMD
j3 7:78a8857b3810 606 _p_owm->OWWriteByte(CMD_ENABLE_SLEEP_MODE);
j3 7:78a8857b3810 607 rtn_val = true;
j3 7:78a8857b3810 608 }
j3 7:78a8857b3810 609 else
j3 7:78a8857b3810 610 {
j3 7:78a8857b3810 611 rtn_val = false;
j3 7:78a8857b3810 612 }
j3 7:78a8857b3810 613
j3 7:78a8857b3810 614 return(rtn_val);
j3 7:78a8857b3810 615 }
j3 7:78a8857b3810 616
j3 7:78a8857b3810 617
j3 7:78a8857b3810 618 //*********************************************************************
j3 7:78a8857b3810 619 uint8_t Ds28e17::ReadDeviceRevision(void)
j3 7:78a8857b3810 620 {
j3 7:78a8857b3810 621 uint8_t rtn_val;
j3 7:78a8857b3810 622
j3 7:78a8857b3810 623 if(_p_owm->OWMatchROM())
j3 7:78a8857b3810 624 {
j3 7:78a8857b3810 625 // Send CMD and receive Data
j3 7:78a8857b3810 626 _p_owm->OWWriteByte(CMD_READ_DEVICE_REV);
j3 7:78a8857b3810 627 rtn_val = _p_owm->OWReadByte();
j3 7:78a8857b3810 628 }
j3 7:78a8857b3810 629 else
j3 7:78a8857b3810 630 {
j3 7:78a8857b3810 631 rtn_val = false;
j3 7:78a8857b3810 632 }
j3 7:78a8857b3810 633
j3 7:78a8857b3810 634 return(rtn_val);
j3 7:78a8857b3810 635 }
j3 7:78a8857b3810 636
j3 7:78a8857b3810 637
j3 7:78a8857b3810 638 //*********************************************************************
j3 7:78a8857b3810 639 uint16_t Ds28e17::docrc16(uint16_t data)
j3 7:78a8857b3810 640 {
j3 7:78a8857b3810 641 data = ((data ^ (_crc16 & 0xff)) & 0xff);
j3 7:78a8857b3810 642 _crc16 >>= 8;
j3 7:78a8857b3810 643
j3 7:78a8857b3810 644 if (Ds28e17::_oddparity[data & 0xf] ^ Ds28e17::_oddparity[data >> 4])
j3 7:78a8857b3810 645 {
j3 7:78a8857b3810 646 _crc16 ^= 0xc001;
j3 7:78a8857b3810 647 }
j3 7:78a8857b3810 648
j3 7:78a8857b3810 649 data <<= 6;
j3 7:78a8857b3810 650 _crc16 ^= data;
j3 7:78a8857b3810 651 data <<= 1;
j3 7:78a8857b3810 652 _crc16 ^= data;
j3 7:78a8857b3810 653
j3 7:78a8857b3810 654 return _crc16;
j3 7:78a8857b3810 655 }
j3 7:78a8857b3810 656
j3 7:78a8857b3810 657