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