1-Wire® library for mbed. Complete 1-Wire library that supports our silicon masters along with a bit-bang master on the MAX32600MBED platform with one common interface for mbed. Slave support has also been included and more slaves will be added as time permits.
Dependents: MAXREFDES131_Qt_Demo MAX32630FTHR_iButton_uSD_Logger MAX32630FTHR_DS18B20_uSD_Logger MAXREFDES130_131_Demo ... more
Superseded by MaximInterface.
Diff: OneWire_Masters/OneWireMaster.cpp
- Revision:
- 24:8942d8478d68
- Parent:
- 23:e8e403d61359
- Child:
- 26:a361e3f42ba5
--- a/OneWire_Masters/OneWireMaster.cpp Mon Mar 21 23:18:45 2016 +0000 +++ b/OneWire_Masters/OneWireMaster.cpp Tue Mar 22 14:24:53 2016 -0500 @@ -108,9 +108,7 @@ OneWireMaster::CmdResult OneWireMaster::OWVerify(const RomId & romId) { OneWireMaster::CmdResult result; - RomId romIdCopy(romId); - int ld_backup, ldf_backup, lfd_backup; // keep a backup copy of the current state @@ -178,13 +176,12 @@ OneWireMaster::CmdResult OneWireMaster::OWReadROM(RomId & romId) { OneWireMaster::CmdResult result; - uint8_t buf[2 + RomId::byteLen]; result = OWReset(); if (result == OneWireMaster::Success) { - result = OWWriteByte(0x33); // READ ROM + result = OWWriteByte(READ_ROM); } // read the ROM @@ -194,7 +191,7 @@ } // verify CRC8 - if ((result == OneWireMaster::Success) && romId.crc8Valid() && (buf[1] != 0)) + if ((result == OneWireMaster::Success) && (RomId::calculateCRC8(buf, RomId::byteLen) == 0)) { romId = RomId(reinterpret_cast<std::uint8_t (&)[RomId::byteLen]>(buf[0])); } @@ -211,7 +208,7 @@ result = OWReset(); if (result == OneWireMaster::Success) { - result = OWWriteByte(0xCC); + result = OWWriteByte(SKIP_ROM); } return result; @@ -229,7 +226,7 @@ result = OWReset(); if (result == OneWireMaster::Success) { - buf[0] = 0x55; + buf[0] = MATCH_ROM; std::memcpy(&buf[1], romId, RomId::byteLen); // send command and rom result = OWWriteBlock(buf, 1 + RomId::byteLen); @@ -251,7 +248,7 @@ if (result == OneWireMaster::Success) { - result = OWWriteByte(0x3C); + result = OWWriteByte(OVERDRIVE_SKIP_ROM); } if (result == OneWireMaster::Success) @@ -274,7 +271,7 @@ result = OWReset(); if (result == OneWireMaster::Success) { - result = OWWriteByte(0x69); + result = OWWriteByte(OVERDRIVE_MATCH_ROM); if (result == OneWireMaster::Success) { OWSpeed(SPEED_OVERDRIVE); @@ -294,7 +291,7 @@ result = OWReset(); if (result == OneWireMaster::Success) { - result = OWWriteByte(0xA5); + result = OWWriteByte(RESUME); } return result;