Dallas / Maxim DS1820 1-Wire library. For communication with multiple DS1820 on a single 1-Wire bus. Also supports DS18S20 and DS18B20.

Fork of DS1820 by Michael Hagberg

Files at this revision

API Documentation at this revision

Comitter:
qonico
Date:
Thu Nov 17 21:03:47 2016 +0000
Parent:
3:c8d0a2bb2987
Commit message:
Fix CRC case error

Changed in this revision

DS1820.cpp Show annotated file Show diff for this revision Revisions of this file
DS1820.h Show annotated file Show diff for this revision Revisions of this file
diff -r c8d0a2bb2987 -r f8128bb8bef1 DS1820.cpp
--- a/DS1820.cpp	Thu Nov 17 21:02:04 2016 +0000
+++ b/DS1820.cpp	Thu Nov 17 21:03:47 2016 +0000
@@ -196,54 +196,54 @@
 }
 
 bool DS1820::ROM_checksum_error() {
-    char CRC=0x00;
+    char crc=0x00;
     int i;
     for(i=0;i<7;i++) // Only going to shift the lower 7 bytes
-        CRC = CRC_byte(CRC, ROM[i]);
-    // After 7 bytes CRC should equal the 8th byte (ROM CRC)
-    return (CRC!=ROM[7]); // will return true if there is a CRC checksum error         
+        crc = crc_byte(crc, ROM[i]);
+    // After 7 bytes crc should equal the 8th byte (ROM crc)
+    return (crc!=ROM[7]); // will return true if there is a crc checksum error         
 }
 
 bool DS1820::RAM_checksum_error() {
-    char CRC=0x00;
+    char crc=0x00;
     int i;
     read_RAM();
     for(i=0;i<8;i++) // Only going to shift the lower 8 bytes
-        CRC = CRC_byte(CRC, RAM[i]);
-    // After 8 bytes CRC should equal the 9th byte (RAM CRC)
-    return (CRC!=RAM[8]); // will return true if there is a CRC checksum error         
+        crc = crc_byte(crc, RAM[i]);
+    // After 8 bytes crc should equal the 9th byte (RAM crc)
+    return (crc!=RAM[8]); // will return true if there is a crc checksum error         
 }
 
-char DS1820::CRC_byte (char CRC, char byte ) {
+char DS1820::crc_byte (char crc, char byte ) {
     int j;
     for(j=0;j<8;j++) {
-        if ((byte & 0x01 ) ^ (CRC & 0x01)) {
-            // DATA ^ LSB CRC = 1
-            CRC = CRC>>1;
+        if ((byte & 0x01 ) ^ (crc & 0x01)) {
+            // DATA ^ LSB crc = 1
+            crc = crc>>1;
             // Set the MSB to 1
-            CRC = CRC | 0x80;
+            crc = crc | 0x80;
             // Check bit 3
-            if (CRC & 0x04) {
-                CRC = CRC & 0xFB; // Bit 3 is set, so clear it
+            if (crc & 0x04) {
+                crc = crc & 0xFB; // Bit 3 is set, so clear it
             } else {
-                CRC = CRC | 0x04; // Bit 3 is clear, so set it
+                crc = crc | 0x04; // Bit 3 is clear, so set it
             }
             // Check bit 4
-            if (CRC & 0x08) {
-                CRC = CRC & 0xF7; // Bit 4 is set, so clear it
+            if (crc & 0x08) {
+                crc = crc & 0xF7; // Bit 4 is set, so clear it
             } else {
-                CRC = CRC | 0x08; // Bit 4 is clear, so set it
+                crc = crc | 0x08; // Bit 4 is clear, so set it
             }
         } else {
-            // DATA ^ LSB CRC = 0
-            CRC = CRC>>1;
+            // DATA ^ LSB crc = 0
+            crc = crc>>1;
             // clear MSB
-            CRC = CRC & 0x7F;
-            // No need to check bits, with DATA ^ LSB CRC = 0, they will remain unchanged
+            crc = crc & 0x7F;
+            // No need to check bits, with DATA ^ LSB crc = 0, they will remain unchanged
         }
         byte = byte>>1;
     }
-return CRC;
+return crc;
 }
 
 void DS1820::convert_temperature(devices device) {
diff -r c8d0a2bb2987 -r f8128bb8bef1 DS1820.h
--- a/DS1820.h	Thu Nov 17 21:02:04 2016 +0000
+++ b/DS1820.h	Thu Nov 17 21:03:47 2016 +0000
@@ -245,7 +245,7 @@
 
 private:
     bool _parasite_power;
-    char CRC_byte (char CRC, char byte );
+    char crc_byte (char crc, char byte );
     bool onewire_reset();
     void match_ROM();
     void skip_ROM();