// Demo on how to identify and read multiple DS18B20 connected to the same bus. // Parasitic power is not used in this example. // This program is based on the sample code from Maxim/Dallas application // note 162 (http://www.maxim-ic.com/app-notes/index.mvp/id/162). Program output should look like this: *** Test with multiple DS18B20 *** Memory allocated for 20 devices. Scanning for devices... ROM CODE =62:00:00:01:CB:25:CA:28 1 ROM CODE =B6:00:00:01:CB:1B:9E:28 2 ROM CODE =66:00:00:01:CB:28:59:28 3 3 devices found. Scanning completed. Temp: 022.6875 Device: 000001CB25CA 001 Temp: 022.6875 Device: 000001CB1B9E 002 Temp: 027.6250 Device: 000001CB2859 003 Temp: 022.6250 Device: 000001CB25CA 001 Temp: 022.6875 Device: 000001CB1B9E 002 Temp: 025.3125 Device: 000001CB2859 003 Temp: 022.8125 Device: 000001CB25CA 001 Temp: 024.1875 Device: 000001CB1B9E 002 Temp: 023.7500 Device: 000001CB2859 003

Dependencies:   mbed

Revision:
1:0777f93ef466
Parent:
0:770734d973b0
Child:
4:6ade7fcb2925
--- a/main.cpp	Tue Jan 10 12:36:08 2012 +0000
+++ b/main.cpp	Mon Jan 23 10:18:02 2012 +0000
@@ -247,7 +247,12 @@
 
 //////////////////////////////////////////////////////////////////////////////
 float Get_Temp(unsigned char device) {
-    float temperature = (float)ReadRawTemp(device) / 16.0;
+    int Raw = ReadRawTemp(device);
+    if((Raw>>8) & 0x80) { // Check if temperature is negative.
+        Raw = (Raw ^ 0xFFFF) + 1;
+        Raw *= -1;
+    }
+    float temperature = (float)Raw / 16.0;
     return temperature;
 }