Implementation of 1-Wire with added Alarm Search Functionality
Dependents: Max32630_One_Wire_Interface
Diff: Masters/DS2480B/DS2480B.cpp
- Revision:
- 96:9b7b63c0105e
- Parent:
- 84:708b7be59fb2
- Child:
- 104:3f48daed532b
--- a/Masters/DS2480B/DS2480B.cpp Fri Jun 24 21:24:02 2016 +0000 +++ b/Masters/DS2480B/DS2480B.cpp Wed Jun 29 16:13:33 2016 +0000 @@ -488,9 +488,55 @@ //********************************************************************* OneWireMaster::CmdResult DS2480B::OWSetSpeed(OWSpeed newSpeed) { - OneWireMaster::CmdResult result = OneWireMaster::OperationFailure; + OneWireMaster::CmdResult result = OneWireMaster::OperationFailure; //uchar rt = FALSE; + + uint8_t sendpacket[5]; + uint8_t sendlen = 0; - //TODO + // check if change from current mode + if (((newSpeed == OneWireMaster::OverdriveSpeed) && (_USpeed != OneWireMaster::OverdriveSpeed)) || + ((newSpeed == OneWireMaster::StandardSpeed) && (_USpeed != OneWireMaster::StandardSpeed))) + { + if (newSpeed == OneWireMaster::OverdriveSpeed) + { + result = DS2480B_ChangeBaud(Bps115200); + if (result == OneWireMaster::Success) + { + _USpeed = SPEEDSEL_OD; + } + } + else if (newSpeed == OneWireMaster::StandardSpeed) + { + result = DS2480B_ChangeBaud(Bps9600); + if (result == OneWireMaster::Success) + { + _USpeed = SPEEDSEL_STD; + } + } + + // if baud rate is set correctly then change DS2480 speed + if (result == OneWireMaster::Success) + { + // check if correct mode + if (_UMode != MODSEL_COMMAND) + { + _UMode = MODSEL_COMMAND; + sendpacket[sendlen++] = MODE_COMMAND; + } + + // proceed to set the DS2480 communication speed + sendpacket[sendlen++] = CMD_COMM | FUNCTSEL_SEARCHOFF | _USpeed; + + // send the packet + result = WriteCOM(sendlen,sendpacket); + if (result != OneWireMaster::Success) + { + // lost communication with DS2480 then reset + DS2480B_Detect(); + } + } + } + return result; }