@@ -94,10 +94,15 @@ uint8_t DSFamily_Class::ScanForDevices() { //
9494boolean DSFamily_Class::Read1WireScratchpad (const uint8_t deviceNumber, // //
9595 uint8_t buffer[9 ]) { // //
9696 _LastCommandWasConvert = false ; // Set switch to false //
97- SelectDevice (deviceNumber); // Reset the 1-wire, address device //
98- write_byte (DS_READ_SCRATCHPAD); // Request device send Scratchpad //
99- for (uint8_t i=0 ;i<9 ;i++) buffer[i] = read_byte (); // read all 9 bytes sent by DS //
100- return (crc8 (buffer,8 ) == buffer[8 ] ); // Return false if bad CRC checksum //
97+ bool CRCStatus = false ; // default to a bad reading //
98+ uint8_t ErrorCounter = 0 ; // Count number of bad readings //
99+ while (!CRCStatus && ErrorCounter++ < 10 ) { // Loop until good read or overflow //
100+ SelectDevice (deviceNumber); // Reset the 1-wire, address device //
101+ write_byte (DS_READ_SCRATCHPAD); // Request device send Scratchpad //
102+ for (uint8_t i=0 ;i<9 ;i++) buffer[i] = read_byte (); // read all 9 bytes sent by DS //
103+ CRCStatus = crc8 (buffer,8 ) == buffer[8 ]; // Check to see if result is valid //
104+ } // of loop until good read or number of errors exceeded // //
105+ return (CRCStatus); // Return false if bad CRC checksum //
101106} // of method Read1WireScratchpad() //----------------------------------//
102107
103108/* ******************************************************************************************************************
@@ -118,7 +123,7 @@ int16_t DSFamily_Class::ReadDeviceTemp(const uint8_t deviceNumber, //
118123 } else if (_LastCommandWasConvert) while (read_bit ()==0 ); // bit high when conversion finished//
119124 if ( deviceNumber < ThermometersFound && // on a successful read from the //
120125 Read1WireScratchpad (deviceNumber,dsBuffer)) { // device scratchpad //
121- if (dsBuffer [0 ]==DS1822_FAMILY) { // The results returned by DS18S20 //
126+ if (ROM_NO [0 ]==DS1822_FAMILY) { // If DS1822 then temp is different //
122127 temperature = ((dsBuffer[1 ] << 8 ) | dsBuffer[0 ])<<3 ; // get the raw reading and apply //
123128 temperature = (temperature & 0xFFF0 ) + 12 - dsBuffer[6 ]; // value from "count remain" byte //
124129 } else temperature = (dsBuffer[1 ]<<8 )|dsBuffer[0 ]; // Results come in 2s complement //
@@ -227,12 +232,11 @@ int8_t DSFamily_Class::GetDeviceCalibration(const uint8_t deviceNumber) { //
227232** Method SelectDevice will reset the 1-Wire microLAN and select the device number specified **
228233*******************************************************************************************************************/
229234void DSFamily_Class::SelectDevice (const uint8_t deviceNumber) { // //
230- uint8_t ROMBuffer[8 ]; // Array to hold unique DS ID //
231235 ParasiticWait (); // Wait for conversion if necessary //
232236 for (uint8_t i=0 ;i<8 ;i++) // //
233- ROMBuffer [i]=EEPROM.read (i+E2END-((deviceNumber+1 )*8 )); // Read the EEPROM byte //
237+ ROM_NO [i]=EEPROM.read (i+E2END-((deviceNumber+1 )*8 )); // Read the EEPROM byte //
234238 reset (); // Reset 1-wire communications //
235- select (ROMBuffer); // Select only current device //
239+ select (ROM_NO); // Select only current device //
236240} // of method SelectDevice() //----------------------------------//
237241
238242/* ******************************************************************************************************************
0 commit comments