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