Implementation of 1-Wire with added Alarm Search Functionality
Dependents: Max32630_One_Wire_Interface
Bridge/DS28E17/DS28E17.cpp@75:8b627804927c, 2016-05-13 (annotated)
- 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?
User | Revision | Line number | New 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 | #include "DS28E17.h" |
IanBenzMaxim | 73:2cecc1372acc | 34 | #include "Masters/OneWireMaster.h" |
j3 | 4:ca27db159b10 | 35 | |
IanBenzMaxim | 73:2cecc1372acc | 36 | using OneWire::Bridge::DS28E17; |
IanBenzMaxim | 73:2cecc1372acc | 37 | using OneWire::Masters::OneWireMaster; |
j3 | 4:ca27db159b10 | 38 | |
IanBenzMaxim | 75:8b627804927c | 39 | |
IanBenzMaxim | 75:8b627804927c | 40 | enum Command |
IanBenzMaxim | 75:8b627804927c | 41 | { |
IanBenzMaxim | 75:8b627804927c | 42 | WriteDataWithStopCmd = 0x4B, |
IanBenzMaxim | 75:8b627804927c | 43 | WriteDataNoStopCmd = 0x5A, |
IanBenzMaxim | 75:8b627804927c | 44 | WriteDataOnlyCmd = 0x69, |
IanBenzMaxim | 75:8b627804927c | 45 | WriteDataOnlyWithStopCmd = 0x78, |
IanBenzMaxim | 75:8b627804927c | 46 | ReadDataWithStopCmd = 0x87, |
IanBenzMaxim | 75:8b627804927c | 47 | WriteReadDataWithStopCmd = 0x2D, |
IanBenzMaxim | 75:8b627804927c | 48 | WriteConfigurationCmd = 0xD2, |
IanBenzMaxim | 75:8b627804927c | 49 | ReadConfigurationCmd = 0xE1, |
IanBenzMaxim | 75:8b627804927c | 50 | EnableSleepModeCmd = 0x1E, |
IanBenzMaxim | 75:8b627804927c | 51 | ReadDeviceRevisionCmd = 0xC3 |
IanBenzMaxim | 75:8b627804927c | 52 | }; |
IanBenzMaxim | 75:8b627804927c | 53 | |
IanBenzMaxim | 75:8b627804927c | 54 | |
IanBenzMaxim | 73:2cecc1372acc | 55 | const uint16_t DS28E17::_oddparity[] = { 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0 }; |
j3 | 4:ca27db159b10 | 56 | |
j3 | 4:ca27db159b10 | 57 | |
j3 | 4:ca27db159b10 | 58 | //********************************************************************* |
IanBenzMaxim | 73:2cecc1372acc | 59 | DS28E17::DS28E17(OneWireMaster &owm) |
IanBenzMaxim | 74:23be10c32fa3 | 60 | : _owm(owm) |
j3 | 4:ca27db159b10 | 61 | { |
IanBenzMaxim | 74:23be10c32fa3 | 62 | |
j3 | 4:ca27db159b10 | 63 | } |
j3 | 4:ca27db159b10 | 64 | |
j3 | 4:ca27db159b10 | 65 | |
j3 | 4:ca27db159b10 | 66 | //********************************************************************* |
IanBenzMaxim | 74:23be10c32fa3 | 67 | DS28E17::CmdResult DS28E17::I2C_WriteDataWithStop(uint8_t I2C_addr, uint8_t length, |
IanBenzMaxim | 74:23be10c32fa3 | 68 | uint8_t *data, uint8_t &status, |
IanBenzMaxim | 74:23be10c32fa3 | 69 | uint8_t &wr_status) |
j3 | 4:ca27db159b10 | 70 | { |
IanBenzMaxim | 73:2cecc1372acc | 71 | DS28E17::CmdResult bridge_result = DS28E17::OperationFailure; |
IanBenzMaxim | 74:23be10c32fa3 | 72 | |
j3 | 7:78a8857b3810 | 73 | size_t send_cnt = 0; |
j3 | 7:78a8857b3810 | 74 | uint8_t send_block[0xff]; |
IanBenzMaxim | 74:23be10c32fa3 | 75 | |
IanBenzMaxim | 75:8b627804927c | 76 | OneWireMaster::CmdResult ow_result = _owm.OWMatchRom(romId); |
IanBenzMaxim | 74:23be10c32fa3 | 77 | |
IanBenzMaxim | 74:23be10c32fa3 | 78 | if (ow_result == OneWireMaster::Success) |
j3 | 7:78a8857b3810 | 79 | { |
j3 | 7:78a8857b3810 | 80 | //seed the crc |
j3 | 7:78a8857b3810 | 81 | _crc16 = 0; |
IanBenzMaxim | 74:23be10c32fa3 | 82 | |
j3 | 7:78a8857b3810 | 83 | // Form the 1-Wire Packet |
IanBenzMaxim | 74:23be10c32fa3 | 84 | |
j3 | 7:78a8857b3810 | 85 | // I2C Write Data with Stop command |
IanBenzMaxim | 75:8b627804927c | 86 | send_block[send_cnt] = WriteDataWithStopCmd; |
j3 | 7:78a8857b3810 | 87 | docrc16(send_block[send_cnt++]); |
IanBenzMaxim | 74:23be10c32fa3 | 88 | |
j3 | 7:78a8857b3810 | 89 | // I2C Address |
j3 | 7:78a8857b3810 | 90 | send_block[send_cnt] = I2C_addr; |
j3 | 7:78a8857b3810 | 91 | docrc16(send_block[send_cnt++]); |
IanBenzMaxim | 74:23be10c32fa3 | 92 | |
j3 | 7:78a8857b3810 | 93 | // Length field |
j3 | 7:78a8857b3810 | 94 | send_block[send_cnt] = length; |
j3 | 7:78a8857b3810 | 95 | docrc16(send_block[send_cnt++]); |
IanBenzMaxim | 74:23be10c32fa3 | 96 | |
j3 | 7:78a8857b3810 | 97 | // Form the write data |
IanBenzMaxim | 74:23be10c32fa3 | 98 | for (size_t idx = 0; idx < length; idx++) |
j3 | 7:78a8857b3810 | 99 | { |
j3 | 7:78a8857b3810 | 100 | send_block[send_cnt] = data[idx]; |
j3 | 7:78a8857b3810 | 101 | docrc16(send_block[send_cnt++]); |
j3 | 7:78a8857b3810 | 102 | } |
IanBenzMaxim | 74:23be10c32fa3 | 103 | |
j3 | 7:78a8857b3810 | 104 | // Form the CRC16 |
IanBenzMaxim | 74:23be10c32fa3 | 105 | _crc16 = _crc16 ^ 0xFFFF; |
j3 | 7:78a8857b3810 | 106 | send_block[send_cnt++] = ((uint8_t)(_crc16 & 0xFF)); |
j3 | 7:78a8857b3810 | 107 | send_block[send_cnt++] = ((uint8_t)((_crc16 >> 8) & 0xFF)); |
IanBenzMaxim | 74:23be10c32fa3 | 108 | |
j3 | 7:78a8857b3810 | 109 | // Send Packet |
j3 | 17:b646b1e3970b | 110 | bridge_result = send_packet(send_block, send_cnt, status, wr_status); |
j3 | 7:78a8857b3810 | 111 | } |
IanBenzMaxim | 74:23be10c32fa3 | 112 | |
j3 | 17:b646b1e3970b | 113 | return bridge_result; |
j3 | 4:ca27db159b10 | 114 | } |
j3 | 4:ca27db159b10 | 115 | |
j3 | 4:ca27db159b10 | 116 | |
j3 | 4:ca27db159b10 | 117 | //********************************************************************* |
IanBenzMaxim | 74:23be10c32fa3 | 118 | DS28E17::CmdResult DS28E17::I2C_WriteDataNoStop(uint8_t I2C_addr, uint8_t length, |
IanBenzMaxim | 74:23be10c32fa3 | 119 | uint8_t *data, uint8_t &status, |
IanBenzMaxim | 74:23be10c32fa3 | 120 | uint8_t &wr_status) |
j3 | 4:ca27db159b10 | 121 | { |
IanBenzMaxim | 73:2cecc1372acc | 122 | DS28E17::CmdResult bridge_result = DS28E17::OperationFailure; |
IanBenzMaxim | 74:23be10c32fa3 | 123 | |
j3 | 7:78a8857b3810 | 124 | size_t send_cnt = 0; |
j3 | 7:78a8857b3810 | 125 | uint8_t send_block[0xff]; |
IanBenzMaxim | 74:23be10c32fa3 | 126 | |
IanBenzMaxim | 75:8b627804927c | 127 | OneWireMaster::CmdResult ow_result = _owm.OWMatchRom(romId); |
IanBenzMaxim | 74:23be10c32fa3 | 128 | |
IanBenzMaxim | 74:23be10c32fa3 | 129 | if (ow_result == OneWireMaster::Success) |
j3 | 7:78a8857b3810 | 130 | { |
j3 | 7:78a8857b3810 | 131 | // seed the crc |
j3 | 7:78a8857b3810 | 132 | _crc16 = 0; |
IanBenzMaxim | 74:23be10c32fa3 | 133 | |
j3 | 7:78a8857b3810 | 134 | // I2C Write Data with Stop command |
IanBenzMaxim | 75:8b627804927c | 135 | send_block[send_cnt] = WriteDataNoStopCmd; |
j3 | 7:78a8857b3810 | 136 | docrc16(send_block[send_cnt++]); |
IanBenzMaxim | 74:23be10c32fa3 | 137 | |
j3 | 7:78a8857b3810 | 138 | // I2C Address |
j3 | 7:78a8857b3810 | 139 | send_block[send_cnt] = I2C_addr; |
j3 | 7:78a8857b3810 | 140 | docrc16(send_block[send_cnt++]); |
IanBenzMaxim | 74:23be10c32fa3 | 141 | |
j3 | 7:78a8857b3810 | 142 | // Length field |
j3 | 7:78a8857b3810 | 143 | send_block[send_cnt] = length; |
j3 | 7:78a8857b3810 | 144 | docrc16(send_block[send_cnt++]); |
IanBenzMaxim | 74:23be10c32fa3 | 145 | |
j3 | 7:78a8857b3810 | 146 | // Form the write data |
IanBenzMaxim | 74:23be10c32fa3 | 147 | for (size_t idx = 0; idx < length; idx++) |
j3 | 7:78a8857b3810 | 148 | { |
j3 | 7:78a8857b3810 | 149 | send_block[send_cnt] = data[idx]; |
j3 | 7:78a8857b3810 | 150 | docrc16(send_block[send_cnt++]); |
j3 | 7:78a8857b3810 | 151 | } |
IanBenzMaxim | 74:23be10c32fa3 | 152 | |
j3 | 7:78a8857b3810 | 153 | // Form the CRC16 |
IanBenzMaxim | 74:23be10c32fa3 | 154 | _crc16 = _crc16 ^ 0xFFFF; |
j3 | 7:78a8857b3810 | 155 | send_block[send_cnt++] = ((uint8_t)(_crc16 & 0xFF)); |
j3 | 7:78a8857b3810 | 156 | send_block[send_cnt++] = ((uint8_t)((_crc16 >> 8) & 0xFF)); |
IanBenzMaxim | 74:23be10c32fa3 | 157 | |
j3 | 7:78a8857b3810 | 158 | // Send Packet |
j3 | 17:b646b1e3970b | 159 | bridge_result = send_packet(send_block, send_cnt, status, wr_status); |
j3 | 7:78a8857b3810 | 160 | } |
IanBenzMaxim | 74:23be10c32fa3 | 161 | |
j3 | 17:b646b1e3970b | 162 | return bridge_result; |
j3 | 4:ca27db159b10 | 163 | } |
j3 | 4:ca27db159b10 | 164 | |
j3 | 4:ca27db159b10 | 165 | |
j3 | 4:ca27db159b10 | 166 | //********************************************************************* |
IanBenzMaxim | 74:23be10c32fa3 | 167 | DS28E17::CmdResult DS28E17::I2C_WriteDataOnly(uint8_t length, uint8_t *data, |
IanBenzMaxim | 74:23be10c32fa3 | 168 | uint8_t &status, uint8_t &wr_status) |
j3 | 4:ca27db159b10 | 169 | { |
IanBenzMaxim | 73:2cecc1372acc | 170 | DS28E17::CmdResult bridge_result = DS28E17::OperationFailure; |
IanBenzMaxim | 74:23be10c32fa3 | 171 | |
j3 | 7:78a8857b3810 | 172 | size_t send_cnt = 0; |
j3 | 7:78a8857b3810 | 173 | uint8_t send_block[0xff]; |
IanBenzMaxim | 74:23be10c32fa3 | 174 | |
IanBenzMaxim | 75:8b627804927c | 175 | OneWireMaster::CmdResult ow_result = _owm.OWMatchRom(romId); |
IanBenzMaxim | 74:23be10c32fa3 | 176 | |
IanBenzMaxim | 74:23be10c32fa3 | 177 | if (ow_result == OneWireMaster::Success) |
j3 | 7:78a8857b3810 | 178 | { |
j3 | 7:78a8857b3810 | 179 | // seed the crc |
j3 | 7:78a8857b3810 | 180 | _crc16 = 0; |
IanBenzMaxim | 74:23be10c32fa3 | 181 | |
j3 | 7:78a8857b3810 | 182 | // Form the 1-Wire Packet |
IanBenzMaxim | 74:23be10c32fa3 | 183 | |
j3 | 7:78a8857b3810 | 184 | // I2C Write Data with Stop command |
IanBenzMaxim | 75:8b627804927c | 185 | send_block[send_cnt] = WriteDataOnlyCmd; |
j3 | 7:78a8857b3810 | 186 | docrc16(send_block[send_cnt++]); |
IanBenzMaxim | 74:23be10c32fa3 | 187 | |
j3 | 7:78a8857b3810 | 188 | // Length field |
j3 | 7:78a8857b3810 | 189 | send_block[send_cnt] = length; |
j3 | 7:78a8857b3810 | 190 | docrc16(send_block[send_cnt++]); |
IanBenzMaxim | 74:23be10c32fa3 | 191 | |
j3 | 7:78a8857b3810 | 192 | // Form the write data |
IanBenzMaxim | 74:23be10c32fa3 | 193 | for (size_t idx = 0; idx < length; idx++) |
j3 | 7:78a8857b3810 | 194 | { |
j3 | 7:78a8857b3810 | 195 | send_block[send_cnt] = data[idx]; |
j3 | 7:78a8857b3810 | 196 | docrc16(send_block[send_cnt++]); |
j3 | 7:78a8857b3810 | 197 | } |
IanBenzMaxim | 74:23be10c32fa3 | 198 | |
j3 | 7:78a8857b3810 | 199 | // Form the CRC16\ |
j3 | 7:78a8857b3810 | 200 | _crc16 = _crc16^0xFFFF; |
j3 | 7:78a8857b3810 | 201 | send_block[send_cnt++] = (_crc16 & 0xFF); |
j3 | 7:78a8857b3810 | 202 | send_block[send_cnt++] = ((_crc16 >> 8) & 0xFF); |
IanBenzMaxim | 74:23be10c32fa3 | 203 | |
j3 | 7:78a8857b3810 | 204 | // Send Packet |
j3 | 17:b646b1e3970b | 205 | bridge_result = send_packet(send_block, send_cnt, status, wr_status); |
j3 | 7:78a8857b3810 | 206 | } |
IanBenzMaxim | 74:23be10c32fa3 | 207 | |
j3 | 17:b646b1e3970b | 208 | return bridge_result; |
j3 | 4:ca27db159b10 | 209 | } |
j3 | 4:ca27db159b10 | 210 | |
j3 | 4:ca27db159b10 | 211 | |
j3 | 4:ca27db159b10 | 212 | //********************************************************************* |
IanBenzMaxim | 74:23be10c32fa3 | 213 | DS28E17::CmdResult DS28E17::I2C_WriteDataOnlyWithStop(uint8_t length, uint8_t *data, |
IanBenzMaxim | 74:23be10c32fa3 | 214 | uint8_t &status, uint8_t &wr_status) |
j3 | 4:ca27db159b10 | 215 | { |
IanBenzMaxim | 73:2cecc1372acc | 216 | DS28E17::CmdResult bridge_result = DS28E17::OperationFailure; |
IanBenzMaxim | 74:23be10c32fa3 | 217 | |
j3 | 7:78a8857b3810 | 218 | size_t send_cnt = 0; |
j3 | 7:78a8857b3810 | 219 | uint8_t send_block[0xff]; |
IanBenzMaxim | 74:23be10c32fa3 | 220 | |
IanBenzMaxim | 75:8b627804927c | 221 | OneWireMaster::CmdResult ow_result = _owm.OWMatchRom(romId); |
IanBenzMaxim | 74:23be10c32fa3 | 222 | |
IanBenzMaxim | 74:23be10c32fa3 | 223 | if (ow_result == OneWireMaster::Success) |
j3 | 7:78a8857b3810 | 224 | { |
j3 | 7:78a8857b3810 | 225 | //seed the crc |
j3 | 7:78a8857b3810 | 226 | _crc16 = 0; |
IanBenzMaxim | 74:23be10c32fa3 | 227 | |
j3 | 7:78a8857b3810 | 228 | // Form the 1-Wire Packet |
IanBenzMaxim | 74:23be10c32fa3 | 229 | |
j3 | 7:78a8857b3810 | 230 | // I2C Write Data with Stop command |
IanBenzMaxim | 75:8b627804927c | 231 | send_block[send_cnt] = WriteDataOnlyWithStopCmd; |
j3 | 7:78a8857b3810 | 232 | docrc16(send_block[send_cnt++]); |
IanBenzMaxim | 74:23be10c32fa3 | 233 | |
j3 | 7:78a8857b3810 | 234 | // Length field |
j3 | 7:78a8857b3810 | 235 | send_block[send_cnt] = length; |
j3 | 7:78a8857b3810 | 236 | docrc16(send_block[send_cnt++]); |
IanBenzMaxim | 74:23be10c32fa3 | 237 | |
j3 | 7:78a8857b3810 | 238 | // Form the write data |
IanBenzMaxim | 74:23be10c32fa3 | 239 | for (size_t idx = 0; idx < length; idx++) |
j3 | 7:78a8857b3810 | 240 | { |
j3 | 7:78a8857b3810 | 241 | send_block[send_cnt] = data[idx]; |
j3 | 7:78a8857b3810 | 242 | docrc16(send_block[send_cnt++]); |
j3 | 7:78a8857b3810 | 243 | } |
IanBenzMaxim | 74:23be10c32fa3 | 244 | |
j3 | 7:78a8857b3810 | 245 | // Form the CRC16 |
IanBenzMaxim | 74:23be10c32fa3 | 246 | _crc16 = _crc16 ^ 0xFFFF; |
j3 | 7:78a8857b3810 | 247 | send_block[send_cnt++] = (_crc16 & 0xFF); |
j3 | 7:78a8857b3810 | 248 | send_block[send_cnt++] = ((_crc16 >> 8) & 0xFF); |
IanBenzMaxim | 74:23be10c32fa3 | 249 | |
j3 | 7:78a8857b3810 | 250 | // Send Packet |
j3 | 17:b646b1e3970b | 251 | bridge_result = send_packet(send_block, send_cnt, status, wr_status); |
IanBenzMaxim | 74:23be10c32fa3 | 252 | } |
IanBenzMaxim | 74:23be10c32fa3 | 253 | |
j3 | 17:b646b1e3970b | 254 | return bridge_result; |
j3 | 4:ca27db159b10 | 255 | } |
j3 | 4:ca27db159b10 | 256 | |
j3 | 4:ca27db159b10 | 257 | |
j3 | 4:ca27db159b10 | 258 | //********************************************************************* |
IanBenzMaxim | 74:23be10c32fa3 | 259 | DS28E17::CmdResult DS28E17::I2C_WriteReadDataWithStop(uint8_t I2C_addr, uint8_t length, |
IanBenzMaxim | 74:23be10c32fa3 | 260 | uint8_t *data, uint8_t nu_bytes_read, |
IanBenzMaxim | 74:23be10c32fa3 | 261 | uint8_t &status, uint8_t &wr_status, |
IanBenzMaxim | 74:23be10c32fa3 | 262 | uint8_t *read_data) |
j3 | 4:ca27db159b10 | 263 | { |
IanBenzMaxim | 73:2cecc1372acc | 264 | DS28E17::CmdResult bridge_result = DS28E17::OperationFailure; |
IanBenzMaxim | 74:23be10c32fa3 | 265 | |
j3 | 7:78a8857b3810 | 266 | size_t send_cnt = 0; |
j3 | 7:78a8857b3810 | 267 | size_t idx = 0; |
j3 | 7:78a8857b3810 | 268 | uint8_t send_block[0xff]; |
IanBenzMaxim | 74:23be10c32fa3 | 269 | |
IanBenzMaxim | 75:8b627804927c | 270 | OneWireMaster::CmdResult ow_result = _owm.OWMatchRom(romId); |
IanBenzMaxim | 74:23be10c32fa3 | 271 | |
IanBenzMaxim | 74:23be10c32fa3 | 272 | if (ow_result == OneWireMaster::Success) |
j3 | 7:78a8857b3810 | 273 | { |
j3 | 7:78a8857b3810 | 274 | //seed the crc |
j3 | 7:78a8857b3810 | 275 | _crc16 = 0; |
IanBenzMaxim | 74:23be10c32fa3 | 276 | |
j3 | 7:78a8857b3810 | 277 | // Form the 1-Wire Packet |
IanBenzMaxim | 74:23be10c32fa3 | 278 | |
j3 | 7:78a8857b3810 | 279 | // I2C Write Data with Stop command |
IanBenzMaxim | 75:8b627804927c | 280 | send_block[send_cnt] = WriteReadDataWithStopCmd; |
j3 | 7:78a8857b3810 | 281 | docrc16(send_block[send_cnt++]); |
IanBenzMaxim | 74:23be10c32fa3 | 282 | |
j3 | 7:78a8857b3810 | 283 | // I2C Address |
j3 | 7:78a8857b3810 | 284 | send_block[send_cnt] = I2C_addr; |
j3 | 7:78a8857b3810 | 285 | docrc16(send_block[send_cnt++]); |
IanBenzMaxim | 74:23be10c32fa3 | 286 | |
j3 | 7:78a8857b3810 | 287 | // Length field |
j3 | 7:78a8857b3810 | 288 | send_block[send_cnt] = length; |
j3 | 7:78a8857b3810 | 289 | docrc16(send_block[send_cnt++]); |
IanBenzMaxim | 74:23be10c32fa3 | 290 | |
j3 | 7:78a8857b3810 | 291 | // Form the write data |
IanBenzMaxim | 74:23be10c32fa3 | 292 | for (idx = 0; idx < length; idx++) |
j3 | 7:78a8857b3810 | 293 | { |
j3 | 7:78a8857b3810 | 294 | send_block[send_cnt] = data[idx]; |
j3 | 7:78a8857b3810 | 295 | docrc16(send_block[send_cnt++]); |
j3 | 7:78a8857b3810 | 296 | } |
IanBenzMaxim | 74:23be10c32fa3 | 297 | |
j3 | 7:78a8857b3810 | 298 | // # of bytes to Read field |
j3 | 7:78a8857b3810 | 299 | send_block[send_cnt] = nu_bytes_read; |
j3 | 7:78a8857b3810 | 300 | docrc16(send_block[send_cnt++]); |
IanBenzMaxim | 74:23be10c32fa3 | 301 | |
j3 | 7:78a8857b3810 | 302 | // Form the CRC16 |
IanBenzMaxim | 74:23be10c32fa3 | 303 | _crc16 = _crc16 ^ 0xFFFF; |
j3 | 7:78a8857b3810 | 304 | send_block[send_cnt++] = (_crc16 & 0xFF); |
j3 | 7:78a8857b3810 | 305 | send_block[send_cnt++] = ((_crc16 >> 8) & 0xFF); |
IanBenzMaxim | 74:23be10c32fa3 | 306 | |
j3 | 7:78a8857b3810 | 307 | // Send Packet |
j3 | 17:b646b1e3970b | 308 | bridge_result = send_packet(send_block, send_cnt, status, wr_status); |
IanBenzMaxim | 74:23be10c32fa3 | 309 | if (bridge_result == DS28E17::Success) |
j3 | 7:78a8857b3810 | 310 | { |
j3 | 17:b646b1e3970b | 311 | ow_result = _owm.OWReadBlock(read_data, nu_bytes_read); |
IanBenzMaxim | 74:23be10c32fa3 | 312 | if (ow_result == OneWireMaster::Success) |
j3 | 7:78a8857b3810 | 313 | { |
IanBenzMaxim | 73:2cecc1372acc | 314 | bridge_result = DS28E17::Success; |
j3 | 7:78a8857b3810 | 315 | } |
j3 | 17:b646b1e3970b | 316 | else |
j3 | 17:b646b1e3970b | 317 | { |
IanBenzMaxim | 73:2cecc1372acc | 318 | bridge_result = DS28E17::CommsReadBlockError; |
j3 | 17:b646b1e3970b | 319 | } |
j3 | 7:78a8857b3810 | 320 | } |
j3 | 7:78a8857b3810 | 321 | } |
IanBenzMaxim | 74:23be10c32fa3 | 322 | |
j3 | 17:b646b1e3970b | 323 | return bridge_result; |
j3 | 4:ca27db159b10 | 324 | } |
j3 | 4:ca27db159b10 | 325 | |
j3 | 4:ca27db159b10 | 326 | |
j3 | 4:ca27db159b10 | 327 | //********************************************************************* |
IanBenzMaxim | 74:23be10c32fa3 | 328 | DS28E17::CmdResult DS28E17::I2C_ReadDataWithStop(uint8_t I2C_addr, uint8_t nu_bytes_read, |
IanBenzMaxim | 74:23be10c32fa3 | 329 | uint8_t &status, uint8_t *read_data) |
j3 | 4:ca27db159b10 | 330 | { |
IanBenzMaxim | 73:2cecc1372acc | 331 | DS28E17::CmdResult bridge_result = DS28E17::OperationFailure; |
IanBenzMaxim | 74:23be10c32fa3 | 332 | |
j3 | 7:78a8857b3810 | 333 | size_t send_cnt = 0; |
j3 | 7:78a8857b3810 | 334 | uint8_t send_block[0xff]; |
IanBenzMaxim | 74:23be10c32fa3 | 335 | |
IanBenzMaxim | 75:8b627804927c | 336 | OneWireMaster::CmdResult ow_result = _owm.OWMatchRom(romId); |
IanBenzMaxim | 74:23be10c32fa3 | 337 | |
IanBenzMaxim | 74:23be10c32fa3 | 338 | if (ow_result == OneWireMaster::Success) |
j3 | 7:78a8857b3810 | 339 | { |
j3 | 7:78a8857b3810 | 340 | //seed the crc for transmit bytes |
j3 | 7:78a8857b3810 | 341 | _crc16 = 0; |
IanBenzMaxim | 74:23be10c32fa3 | 342 | |
j3 | 7:78a8857b3810 | 343 | // Form the 1-Wire Packet to send |
IanBenzMaxim | 74:23be10c32fa3 | 344 | |
j3 | 7:78a8857b3810 | 345 | // I2C Write Data with Stop command |
IanBenzMaxim | 75:8b627804927c | 346 | send_block[send_cnt] = ReadDataWithStopCmd; |
j3 | 7:78a8857b3810 | 347 | docrc16(send_block[send_cnt++]); |
IanBenzMaxim | 74:23be10c32fa3 | 348 | |
j3 | 7:78a8857b3810 | 349 | // I2C Address |
j3 | 7:78a8857b3810 | 350 | send_block[send_cnt] = I2C_addr; |
j3 | 7:78a8857b3810 | 351 | docrc16(send_block[send_cnt++]); |
IanBenzMaxim | 74:23be10c32fa3 | 352 | |
j3 | 7:78a8857b3810 | 353 | // # of bytes to Read field |
j3 | 7:78a8857b3810 | 354 | send_block[send_cnt] = nu_bytes_read; |
j3 | 7:78a8857b3810 | 355 | docrc16(send_block[send_cnt++]); |
IanBenzMaxim | 74:23be10c32fa3 | 356 | |
j3 | 7:78a8857b3810 | 357 | // Form the CRC16 |
IanBenzMaxim | 74:23be10c32fa3 | 358 | _crc16 = _crc16 ^ 0xFFFF; |
j3 | 7:78a8857b3810 | 359 | send_block[send_cnt++] = (_crc16 & 0xFF); |
j3 | 7:78a8857b3810 | 360 | send_block[send_cnt++] = ((_crc16 >> 8) & 0xFF); |
IanBenzMaxim | 74:23be10c32fa3 | 361 | |
j3 | 7:78a8857b3810 | 362 | // Send Packet |
j3 | 17:b646b1e3970b | 363 | bridge_result = send_packet(send_block, send_cnt, status); |
IanBenzMaxim | 74:23be10c32fa3 | 364 | if (bridge_result == DS28E17::Success) |
j3 | 7:78a8857b3810 | 365 | { |
j3 | 17:b646b1e3970b | 366 | ow_result = _owm.OWReadBlock(read_data, nu_bytes_read); |
IanBenzMaxim | 74:23be10c32fa3 | 367 | if (ow_result == OneWireMaster::Success) |
j3 | 7:78a8857b3810 | 368 | { |
IanBenzMaxim | 73:2cecc1372acc | 369 | bridge_result = DS28E17::Success; |
j3 | 7:78a8857b3810 | 370 | } |
j3 | 17:b646b1e3970b | 371 | else |
j3 | 17:b646b1e3970b | 372 | { |
IanBenzMaxim | 73:2cecc1372acc | 373 | bridge_result = DS28E17::CommsReadBlockError; |
j3 | 17:b646b1e3970b | 374 | } |
j3 | 7:78a8857b3810 | 375 | } |
j3 | 7:78a8857b3810 | 376 | } |
IanBenzMaxim | 74:23be10c32fa3 | 377 | |
j3 | 17:b646b1e3970b | 378 | return bridge_result; |
j3 | 4:ca27db159b10 | 379 | } |
j3 | 4:ca27db159b10 | 380 | |
j3 | 4:ca27db159b10 | 381 | |
j3 | 4:ca27db159b10 | 382 | //********************************************************************* |
IanBenzMaxim | 73:2cecc1372acc | 383 | DS28E17::CmdResult DS28E17::WriteConfigReg(uint8_t data) |
j3 | 7:78a8857b3810 | 384 | { |
IanBenzMaxim | 73:2cecc1372acc | 385 | DS28E17::CmdResult bridge_result = DS28E17::OperationFailure; |
IanBenzMaxim | 74:23be10c32fa3 | 386 | |
IanBenzMaxim | 75:8b627804927c | 387 | OneWireMaster::CmdResult ow_result = _owm.OWMatchRom(romId); |
IanBenzMaxim | 74:23be10c32fa3 | 388 | |
IanBenzMaxim | 74:23be10c32fa3 | 389 | if (ow_result == OneWireMaster::Success) |
j3 | 7:78a8857b3810 | 390 | { |
j3 | 7:78a8857b3810 | 391 | // Send CMD and Data |
IanBenzMaxim | 75:8b627804927c | 392 | uint8_t send_block[] = { WriteConfigurationCmd, data }; |
IanBenzMaxim | 74:23be10c32fa3 | 393 | |
j3 | 17:b646b1e3970b | 394 | ow_result = _owm.OWWriteBlock(send_block, 2); |
IanBenzMaxim | 74:23be10c32fa3 | 395 | if (ow_result == OneWireMaster::Success) |
j3 | 17:b646b1e3970b | 396 | { |
j3 | 17:b646b1e3970b | 397 | _i2c_speed = data & 0x03; // Save off _i2c_speed setting to be used by other functions |
IanBenzMaxim | 73:2cecc1372acc | 398 | bridge_result = DS28E17::Success; |
j3 | 17:b646b1e3970b | 399 | } |
j3 | 17:b646b1e3970b | 400 | else |
j3 | 17:b646b1e3970b | 401 | { |
IanBenzMaxim | 73:2cecc1372acc | 402 | bridge_result = DS28E17::CommsWriteBlockError; |
j3 | 17:b646b1e3970b | 403 | } |
j3 | 7:78a8857b3810 | 404 | } |
IanBenzMaxim | 74:23be10c32fa3 | 405 | |
j3 | 17:b646b1e3970b | 406 | return bridge_result; |
j3 | 7:78a8857b3810 | 407 | } |
j3 | 7:78a8857b3810 | 408 | |
j3 | 7:78a8857b3810 | 409 | |
j3 | 7:78a8857b3810 | 410 | //********************************************************************* |
IanBenzMaxim | 73:2cecc1372acc | 411 | DS28E17::CmdResult DS28E17::ReadConfigReg(uint8_t & config) |
j3 | 7:78a8857b3810 | 412 | { |
IanBenzMaxim | 73:2cecc1372acc | 413 | DS28E17::CmdResult bridge_result = DS28E17::OperationFailure; |
IanBenzMaxim | 74:23be10c32fa3 | 414 | |
IanBenzMaxim | 75:8b627804927c | 415 | OneWireMaster::CmdResult ow_result = _owm.OWMatchRom(romId); |
IanBenzMaxim | 74:23be10c32fa3 | 416 | |
IanBenzMaxim | 74:23be10c32fa3 | 417 | if (ow_result == OneWireMaster::Success) |
j3 | 7:78a8857b3810 | 418 | { |
j3 | 7:78a8857b3810 | 419 | // Send CMD and receive Data |
IanBenzMaxim | 75:8b627804927c | 420 | ow_result = _owm.OWWriteByte(ReadConfigurationCmd); |
IanBenzMaxim | 74:23be10c32fa3 | 421 | if (ow_result == OneWireMaster::Success) |
j3 | 17:b646b1e3970b | 422 | { |
j3 | 17:b646b1e3970b | 423 | ow_result = _owm.OWReadByte(config); |
IanBenzMaxim | 74:23be10c32fa3 | 424 | if (ow_result == OneWireMaster::Success) |
j3 | 17:b646b1e3970b | 425 | { |
IanBenzMaxim | 73:2cecc1372acc | 426 | bridge_result = DS28E17::Success; |
j3 | 17:b646b1e3970b | 427 | } |
j3 | 17:b646b1e3970b | 428 | else |
j3 | 17:b646b1e3970b | 429 | { |
IanBenzMaxim | 73:2cecc1372acc | 430 | bridge_result = DS28E17::CommsReadByteError; |
j3 | 17:b646b1e3970b | 431 | } |
j3 | 17:b646b1e3970b | 432 | } |
j3 | 17:b646b1e3970b | 433 | else |
j3 | 17:b646b1e3970b | 434 | { |
IanBenzMaxim | 73:2cecc1372acc | 435 | bridge_result = DS28E17::CommsWriteByteError; |
j3 | 17:b646b1e3970b | 436 | } |
j3 | 7:78a8857b3810 | 437 | } |
IanBenzMaxim | 74:23be10c32fa3 | 438 | |
j3 | 17:b646b1e3970b | 439 | return bridge_result; |
j3 | 7:78a8857b3810 | 440 | } |
j3 | 7:78a8857b3810 | 441 | |
j3 | 7:78a8857b3810 | 442 | |
j3 | 7:78a8857b3810 | 443 | //********************************************************************* |
IanBenzMaxim | 75:8b627804927c | 444 | DS28E17::CmdResult DS28E17::EnableSleepMode() |
j3 | 7:78a8857b3810 | 445 | { |
IanBenzMaxim | 73:2cecc1372acc | 446 | DS28E17::CmdResult bridge_result = DS28E17::OperationFailure; |
IanBenzMaxim | 74:23be10c32fa3 | 447 | |
IanBenzMaxim | 75:8b627804927c | 448 | OneWireMaster::CmdResult ow_result = _owm.OWMatchRom(romId); |
IanBenzMaxim | 74:23be10c32fa3 | 449 | |
IanBenzMaxim | 74:23be10c32fa3 | 450 | if (ow_result == OneWireMaster::Success) |
j3 | 7:78a8857b3810 | 451 | { |
j3 | 7:78a8857b3810 | 452 | // Send CMD |
IanBenzMaxim | 75:8b627804927c | 453 | ow_result = _owm.OWWriteByte(EnableSleepModeCmd); |
IanBenzMaxim | 74:23be10c32fa3 | 454 | if (ow_result == OneWireMaster::Success) |
j3 | 17:b646b1e3970b | 455 | { |
IanBenzMaxim | 73:2cecc1372acc | 456 | bridge_result = DS28E17::Success; |
j3 | 17:b646b1e3970b | 457 | } |
j3 | 17:b646b1e3970b | 458 | else |
j3 | 17:b646b1e3970b | 459 | { |
IanBenzMaxim | 73:2cecc1372acc | 460 | bridge_result = DS28E17::CommsWriteByteError; |
j3 | 17:b646b1e3970b | 461 | } |
j3 | 7:78a8857b3810 | 462 | } |
IanBenzMaxim | 74:23be10c32fa3 | 463 | |
j3 | 17:b646b1e3970b | 464 | return bridge_result; |
j3 | 7:78a8857b3810 | 465 | } |
j3 | 7:78a8857b3810 | 466 | |
j3 | 7:78a8857b3810 | 467 | |
j3 | 7:78a8857b3810 | 468 | //********************************************************************* |
IanBenzMaxim | 73:2cecc1372acc | 469 | DS28E17::CmdResult DS28E17::ReadDeviceRevision(uint8_t & rev) |
j3 | 7:78a8857b3810 | 470 | { |
IanBenzMaxim | 73:2cecc1372acc | 471 | DS28E17::CmdResult bridge_result = DS28E17::OperationFailure; |
IanBenzMaxim | 74:23be10c32fa3 | 472 | |
IanBenzMaxim | 75:8b627804927c | 473 | OneWireMaster::CmdResult ow_result = _owm.OWMatchRom(romId); |
IanBenzMaxim | 74:23be10c32fa3 | 474 | |
IanBenzMaxim | 74:23be10c32fa3 | 475 | if (ow_result == OneWireMaster::Success) |
j3 | 7:78a8857b3810 | 476 | { |
j3 | 7:78a8857b3810 | 477 | // Send CMD and receive Data |
IanBenzMaxim | 75:8b627804927c | 478 | ow_result = _owm.OWWriteByte(ReadDeviceRevisionCmd); |
IanBenzMaxim | 74:23be10c32fa3 | 479 | if (ow_result == OneWireMaster::Success) |
j3 | 17:b646b1e3970b | 480 | { |
j3 | 17:b646b1e3970b | 481 | ow_result = _owm.OWReadByte(rev); |
IanBenzMaxim | 74:23be10c32fa3 | 482 | if (ow_result == OneWireMaster::Success) |
j3 | 17:b646b1e3970b | 483 | { |
IanBenzMaxim | 73:2cecc1372acc | 484 | bridge_result = DS28E17::Success; |
j3 | 17:b646b1e3970b | 485 | } |
j3 | 17:b646b1e3970b | 486 | else |
j3 | 17:b646b1e3970b | 487 | { |
IanBenzMaxim | 73:2cecc1372acc | 488 | bridge_result = DS28E17::CommsReadByteError; |
j3 | 17:b646b1e3970b | 489 | } |
j3 | 17:b646b1e3970b | 490 | } |
j3 | 17:b646b1e3970b | 491 | else |
j3 | 17:b646b1e3970b | 492 | { |
IanBenzMaxim | 73:2cecc1372acc | 493 | bridge_result = DS28E17::CommsWriteByteError; |
j3 | 17:b646b1e3970b | 494 | } |
j3 | 7:78a8857b3810 | 495 | } |
IanBenzMaxim | 74:23be10c32fa3 | 496 | |
j3 | 17:b646b1e3970b | 497 | return bridge_result; |
j3 | 7:78a8857b3810 | 498 | } |
j3 | 7:78a8857b3810 | 499 | |
j3 | 7:78a8857b3810 | 500 | |
j3 | 7:78a8857b3810 | 501 | //********************************************************************* |
IanBenzMaxim | 73:2cecc1372acc | 502 | uint16_t DS28E17::docrc16(uint16_t data) |
j3 | 7:78a8857b3810 | 503 | { |
j3 | 7:78a8857b3810 | 504 | data = ((data ^ (_crc16 & 0xff)) & 0xff); |
j3 | 7:78a8857b3810 | 505 | _crc16 >>= 8; |
j3 | 7:78a8857b3810 | 506 | |
IanBenzMaxim | 73:2cecc1372acc | 507 | if (DS28E17::_oddparity[data & 0xf] ^ DS28E17::_oddparity[data >> 4]) |
j3 | 7:78a8857b3810 | 508 | { |
j3 | 7:78a8857b3810 | 509 | _crc16 ^= 0xc001; |
j3 | 7:78a8857b3810 | 510 | } |
j3 | 7:78a8857b3810 | 511 | |
j3 | 7:78a8857b3810 | 512 | data <<= 6; |
IanBenzMaxim | 74:23be10c32fa3 | 513 | _crc16 ^= data; |
j3 | 7:78a8857b3810 | 514 | data <<= 1; |
IanBenzMaxim | 74:23be10c32fa3 | 515 | _crc16 ^= data; |
j3 | 7:78a8857b3810 | 516 | |
j3 | 7:78a8857b3810 | 517 | return _crc16; |
j3 | 7:78a8857b3810 | 518 | } |
j3 | 7:78a8857b3810 | 519 | |
j3 | 7:78a8857b3810 | 520 | |
j3 | 17:b646b1e3970b | 521 | //********************************************************************* |
IanBenzMaxim | 73:2cecc1372acc | 522 | DS28E17::CmdResult DS28E17::send_packet(const uint8_t * data, uint8_t data_length, |
j3 | 17:b646b1e3970b | 523 | uint8_t & status, uint8_t & wr_status) |
j3 | 17:b646b1e3970b | 524 | { |
IanBenzMaxim | 73:2cecc1372acc | 525 | DS28E17::CmdResult bridge_result = DS28E17::CommsWriteBlockError; |
j3 | 17:b646b1e3970b | 526 | uint32_t poll_count = 0; |
IanBenzMaxim | 74:23be10c32fa3 | 527 | |
j3 | 23:e8e403d61359 | 528 | OneWireMaster::CmdResult ow_result = _owm.OWWriteBlock(data, data_length); |
IanBenzMaxim | 74:23be10c32fa3 | 529 | |
IanBenzMaxim | 74:23be10c32fa3 | 530 | if (ow_result == OneWireMaster::Success) |
j3 | 17:b646b1e3970b | 531 | { |
j3 | 17:b646b1e3970b | 532 | // Poll for Zero 1-Wire bit and return if an error occurs |
j3 | 17:b646b1e3970b | 533 | uint8_t recvbit = 0x01; |
IanBenzMaxim | 74:23be10c32fa3 | 534 | do |
j3 | 17:b646b1e3970b | 535 | { |
j3 | 17:b646b1e3970b | 536 | ow_result = _owm.OWReadBit(recvbit); |
IanBenzMaxim | 75:8b627804927c | 537 | } while (recvbit && (poll_count++ < pollLimit) && (ow_result == OneWireMaster::Success)); |
j3 | 17:b646b1e3970b | 538 | |
IanBenzMaxim | 74:23be10c32fa3 | 539 | if (ow_result == OneWireMaster::Success) |
j3 | 17:b646b1e3970b | 540 | { |
IanBenzMaxim | 75:8b627804927c | 541 | if (poll_count < pollLimit) |
j3 | 17:b646b1e3970b | 542 | { |
j3 | 17:b646b1e3970b | 543 | //Read Status and write status |
j3 | 17:b646b1e3970b | 544 | uint8_t read_block[2]; |
IanBenzMaxim | 74:23be10c32fa3 | 545 | |
j3 | 17:b646b1e3970b | 546 | ow_result = _owm.OWReadBlock(read_block, 2); |
IanBenzMaxim | 74:23be10c32fa3 | 547 | |
IanBenzMaxim | 74:23be10c32fa3 | 548 | if (ow_result == OneWireMaster::Success) |
j3 | 17:b646b1e3970b | 549 | { |
j3 | 17:b646b1e3970b | 550 | status = read_block[0]; |
j3 | 17:b646b1e3970b | 551 | wr_status = read_block[1]; |
IanBenzMaxim | 73:2cecc1372acc | 552 | bridge_result = DS28E17::Success; |
IanBenzMaxim | 74:23be10c32fa3 | 553 | } |
j3 | 17:b646b1e3970b | 554 | else |
j3 | 17:b646b1e3970b | 555 | { |
IanBenzMaxim | 74:23be10c32fa3 | 556 | bridge_result = DS28E17::CommsReadBlockError; |
j3 | 17:b646b1e3970b | 557 | } |
IanBenzMaxim | 74:23be10c32fa3 | 558 | } |
IanBenzMaxim | 74:23be10c32fa3 | 559 | else |
j3 | 17:b646b1e3970b | 560 | { |
IanBenzMaxim | 73:2cecc1372acc | 561 | bridge_result = DS28E17::TimeoutError; |
j3 | 17:b646b1e3970b | 562 | } |
IanBenzMaxim | 74:23be10c32fa3 | 563 | } |
IanBenzMaxim | 74:23be10c32fa3 | 564 | else |
j3 | 17:b646b1e3970b | 565 | { |
IanBenzMaxim | 73:2cecc1372acc | 566 | bridge_result = DS28E17::CommsReadBitError; |
j3 | 17:b646b1e3970b | 567 | } |
IanBenzMaxim | 74:23be10c32fa3 | 568 | } |
IanBenzMaxim | 74:23be10c32fa3 | 569 | |
j3 | 17:b646b1e3970b | 570 | return bridge_result; |
j3 | 17:b646b1e3970b | 571 | } |
j3 | 17:b646b1e3970b | 572 | |
j3 | 17:b646b1e3970b | 573 | |
j3 | 17:b646b1e3970b | 574 | //********************************************************************* |
IanBenzMaxim | 74:23be10c32fa3 | 575 | DS28E17::CmdResult DS28E17::send_packet(const uint8_t * data, uint8_t data_length, |
j3 | 17:b646b1e3970b | 576 | uint8_t & status) |
j3 | 17:b646b1e3970b | 577 | { |
IanBenzMaxim | 73:2cecc1372acc | 578 | DS28E17::CmdResult bridge_result = DS28E17::CommsWriteBlockError; |
j3 | 17:b646b1e3970b | 579 | uint32_t poll_count = 0; |
IanBenzMaxim | 74:23be10c32fa3 | 580 | |
j3 | 23:e8e403d61359 | 581 | OneWireMaster::CmdResult ow_result = _owm.OWWriteBlock(data, data_length); |
IanBenzMaxim | 74:23be10c32fa3 | 582 | |
IanBenzMaxim | 74:23be10c32fa3 | 583 | if (ow_result == OneWireMaster::Success) |
j3 | 17:b646b1e3970b | 584 | { |
j3 | 17:b646b1e3970b | 585 | // Poll for Zero 1-Wire bit and return if an error occurs |
j3 | 17:b646b1e3970b | 586 | uint8_t recvbit = 0x01; |
IanBenzMaxim | 74:23be10c32fa3 | 587 | do |
j3 | 17:b646b1e3970b | 588 | { |
j3 | 17:b646b1e3970b | 589 | ow_result = _owm.OWReadBit(recvbit); |
IanBenzMaxim | 75:8b627804927c | 590 | } while (recvbit && (poll_count++ < pollLimit) && (ow_result == OneWireMaster::Success)); |
j3 | 17:b646b1e3970b | 591 | |
IanBenzMaxim | 74:23be10c32fa3 | 592 | if (ow_result == OneWireMaster::Success) |
j3 | 17:b646b1e3970b | 593 | { |
IanBenzMaxim | 75:8b627804927c | 594 | if (poll_count < pollLimit) |
j3 | 17:b646b1e3970b | 595 | { |
j3 | 17:b646b1e3970b | 596 | //Read Status |
j3 | 17:b646b1e3970b | 597 | ow_result = _owm.OWReadByte(status); |
IanBenzMaxim | 74:23be10c32fa3 | 598 | if (ow_result == OneWireMaster::Success) |
j3 | 17:b646b1e3970b | 599 | { |
IanBenzMaxim | 73:2cecc1372acc | 600 | bridge_result = DS28E17::Success; |
IanBenzMaxim | 74:23be10c32fa3 | 601 | } |
j3 | 17:b646b1e3970b | 602 | else |
j3 | 17:b646b1e3970b | 603 | { |
IanBenzMaxim | 73:2cecc1372acc | 604 | bridge_result = DS28E17::CommsReadByteError; |
j3 | 17:b646b1e3970b | 605 | } |
IanBenzMaxim | 74:23be10c32fa3 | 606 | } |
IanBenzMaxim | 74:23be10c32fa3 | 607 | else |
j3 | 17:b646b1e3970b | 608 | { |
IanBenzMaxim | 73:2cecc1372acc | 609 | bridge_result = DS28E17::TimeoutError; |
j3 | 17:b646b1e3970b | 610 | } |
IanBenzMaxim | 74:23be10c32fa3 | 611 | } |
IanBenzMaxim | 74:23be10c32fa3 | 612 | else |
j3 | 17:b646b1e3970b | 613 | { |
IanBenzMaxim | 73:2cecc1372acc | 614 | bridge_result = DS28E17::CommsReadBitError; |
j3 | 17:b646b1e3970b | 615 | } |
IanBenzMaxim | 74:23be10c32fa3 | 616 | } |
IanBenzMaxim | 74:23be10c32fa3 | 617 | |
j3 | 17:b646b1e3970b | 618 | return bridge_result; |
j3 | 17:b646b1e3970b | 619 | } |
j3 | 17:b646b1e3970b | 620 |