one wire driver

Dependents:   09_PT1000 10_PT1000 11_PT1000

Files at this revision

API Documentation at this revision

Comitter:
rs27
Date:
Sat May 04 10:11:42 2013 +0000
Parent:
0:c57706d25cf0
Child:
2:e9048135901b
Commit message:
test

Changed in this revision

DS2482.cpp Show annotated file Show diff for this revision Revisions of this file
DS2482.h Show annotated file Show diff for this revision Revisions of this file
--- a/DS2482.cpp	Sat Apr 27 18:56:53 2013 +0000
+++ b/DS2482.cpp	Sat May 04 10:11:42 2013 +0000
@@ -3,6 +3,8 @@
 #include "mbed.h"
 #include "DS2482.h"
 
+extern Serial pc;
+
 //-----------------------------------------------------------------------------
 // CRC = X^8 + X^5 + X^4 + 1
 
@@ -49,6 +51,20 @@
   return crc_value;
 }
 
+uint8_t DS2482::crc_calc_buffer(uint8_t *pbuffer, uint8_t count)
+{
+  uint8_t n;
+
+  crc_value = 0;
+
+  for (n = 0; n < count; n++)
+  {
+    crc_value = crc_table[crc_value ^ *pbuffer++];
+  }
+
+  return crc_value;
+}
+
 //==========================================================================
 // I2C DS2482
 //
@@ -70,7 +86,8 @@
     if (!reset())    // reset the DS2482 ON selected address
     {
         #if OW_MASTER_START
-            printf("\r\n--- DS2482 bus0 reset not executed");
+            pc.printf("\r\n--- DS2482 bus0 reset not executed \n");
+            wait(0.1);
         #endif
 
         return false;
@@ -86,14 +103,16 @@
     if (!write_config(c1WS | cSPU | cPPM | cAPU))
     {
         #if OW_MASTER_START
-            printf("\r\n--- DS2482 configuration failure");
+            pc.printf("\r\n--- DS2482 configuration failure \n");
+            wait(0.1);
         #endif
 
         return false;
     }
 
     #if OW_MASTER_START
-        printf("\r\n*** DS2482 detect OK");
+        pc.printf("\r\n*** DS2482 detect OK \n");
+        wait(0.1);
     #endif
     
     return true;
@@ -110,9 +129,12 @@
     char cmd[2];
       
     cmd[0] = DS2482_CMD_DRST;
+    // pc.printf("\nreset write");
     i2c.write(addr, cmd, 1);
+    // pc.printf("\nreset read");
     i2c.read(addr, cmd, 1);
-    printf("\ncmd = %02x",cmd[0]);
+    // pc.printf("  cmd = %02x \n",cmd[0]);
+    wait(0.1);
     return ((cmd[0] & 0xF7) == 0x10);
 }
 
@@ -141,7 +163,7 @@
         // handle error
         // ...
         #if OW_MASTER_START
-            printf("\r\n---check for failure due to incorrect config read back");
+            pc.printf("\r\n---check for failure due to incorrect config read back");
         #endif
 
         reset();
@@ -164,41 +186,41 @@
 //
 uint8_t DS2482::OWReset(void)
 {
-    uint8_t status;
     uint8_t poll_count = 0;
-    char cmd(2);
+    char cmd[2];
     
     cmd[0] = DS2482_CMD_1WRS;
     i2c.write(addr,cmd,1);
 
     #if OW_MASTER_DEBUG
-        printf_P(PSTR("\r\n*** Reset all devices on the 1-Wire Net\r\n"));
+        pc.printf("\r\n*** Reset all devices on the 1-Wire Net\r\n");
     #endif
-
+    
     do
     {
-        i2c.read(addr,cmd,1);
+       i2c.read(addr,cmd,1);
+       // pc.printf("\n read %04x",cmd[0]);
     }
     while ((cmd[0] & DS2482_STATUS_1WB) && (poll_count++ < POLL_LIMIT));
-
+    
     // check for failure due to poll limit reached
     if (poll_count >= POLL_LIMIT)
     {
         // handle error
         // ...
         #if OW_MASTER_DEBUG
-            printf("\r\n---poll limit reached");
+            pc.printf("\r\n---poll limit reached");
         #endif
 
         reset();
-        return FALSE;
+        return false;
     }
 
     // check for short condition
     if (cmd[0] & DS2482_STATUS_SD)
     {
         #if OW_MASTER_DEBUG     
-            printf("\r\n---1-Wire Net short detected");
+            pc.printf("\r\n---1-Wire Net short detected %04x",cmd[0]);
         #endif
 
         short_detected = true;
@@ -206,16 +228,17 @@
     else
     {
         #if OW_MASTER_DEBUG
-            printf("\r\n*** 1-Wire electrical net is OK");
+            pc.printf("\r\n*** 1-Wire electrical net is OK");
         #endif
 
         short_detected = false;
     }
+    
     // check for presence detect
     if (cmd[0] & DS2482_STATUS_PPD)
     {
         #if OW_MASTER_DEBUG         
-            printf("\r\n*** 1-Wire Device detected");
+            pc.printf("\r\n*** 1-Wire Device detected");
         #endif
                 
         return true;
@@ -223,7 +246,7 @@
     else
     {
         #if OW_MASTER_DEBUG     
-            printf("\r\n---No Device detected");
+            pc.printf("\r\n---No Device detected");
         #endif
                 
         return false;
@@ -282,7 +305,7 @@
     while ((cmd[0] & DS2482_STATUS_1WB) && (poll_count++ < POLL_LIMIT));
 
     #if OW_MASTER_DEBUG
-        printf("\r\n*** Send 1 bit to the 1-Wire Net");
+        pc.printf("\r\n*** Send 1 bit to the 1-Wire Net");
     #endif
 
     // check for failure due to poll limit reached
@@ -291,7 +314,7 @@
         // handle error
         // ...
         #if OW_MASTER_DEBUG
-            printf("\r\n---handle error OW Write Bit");
+            pc.printf("\r\n---handle error OW Write Bit");
         #endif
 
         reset();
@@ -325,7 +348,7 @@
     uint8_t poll_count = 0;
 
     #if OW_MASTER_DEBUG
-        printf("\r\n*** Send 8 bits of WRITE to the 1-Wire Net");
+        pc.printf("\r\n*** Send 8 bits of WRITE to the 1-Wire Net");
     #endif
 
     cmd[0] = DS2482_CMD_1WWB;
@@ -348,11 +371,15 @@
         // handle error
         // ...
         #if OW_MASTER_DEBUG
-            printf("\r\n---handle error OW Write Byte");
+            pc.printf("\r\n---handle error OW Write Byte");
         #endif
 
         reset();
     }
+    
+    #if OW_MASTER_DEBUG
+        pc.printf(" done");
+    #endif
 }
 
 //--------------------------------------------------------------------------
@@ -363,12 +390,11 @@
 //
 uint8_t DS2482::OWReadByte(void)
 {
-    uint8_t data, status;
     uint8_t poll_count = 0;
     char cmd[2];
     
     #if OW_MASTER_DEBUG
-        printf("\r\n*** Read 8 bits from the 1-Wire Net");
+        pc.printf("\r\n*** Read 8 bits from the 1-Wire Net");
     #endif
 
     cmd[0] = DS2482_CMD_1WRB;                       // DS2482 1-Wire Read Byte
@@ -379,7 +405,7 @@
 
     do
     {
-        i2c.read(adr, cmd, 1);
+        i2c.read(addr, cmd, 1);
     }
     while ((cmd[0] & DS2482_STATUS_1WB) && (poll_count++ < POLL_LIMIT));
 
@@ -389,7 +415,7 @@
         // handle error
         // ...
         #if OW_MASTER_DEBUG
-            printf("\r\n---handle error OW Read Byte");
+            pc.printf("\r\n---handle error OW Read Byte");
         #endif
 
         reset();
@@ -398,9 +424,9 @@
   
     cmd[0] = DS2482_CMD_SRP;                // DS2482 Set Read Pointer
     cmd[1] = DS2482_READPTR_RDR;            // DS2482 Read Data Register
-    i2c.write[addr, cmd, 2);
+    i2c.write(addr, cmd, 2);
     
-    i2c.read(addr, cmd, 1));
+    i2c.read(addr, cmd, 1);
 
     return cmd[0];
 }
@@ -462,7 +488,7 @@
     LastFamilyDiscrepancy = 0;
 
     #if OW_MASTER_DEBUG
-        printf("\r\n*** Find the 'first' device on the 1-Wire network");
+        pc.printf("\r\n*** Find the 'first' device on the 1-Wire network");
     #endif
 
     return OWSearch();
@@ -476,7 +502,7 @@
 uint8_t DS2482::OWNext(void)
 {
     #if OW_MASTER_DEBUG
-        printf("\r\n*** Find the 'next' device on the 1-Wire network");
+        pc.printf("\r\n*** Find the 'next' device on the 1-Wire network");
     #endif
 
     // leave the search state alone
@@ -537,7 +563,7 @@
 
     // return the result of the verify
     #if OW_MASTER_DEBUG 
-        printf("\r\n*** 1-Wire Verify device with the ROM number in ROM_NO");
+        pc.printf("\r\n*** 1-Wire Verify device with the ROM number in ROM_NO");
     #endif
 
     return status;
@@ -614,6 +640,10 @@
     search_result = FALSE;
     crc_value = 0;
 
+    #if OW_MASTER_DEBUG
+        pc.printf("\r\n*** one wire search");
+    #endif
+    
     if (!LastDeviceFlag)    // if the last call was not the last one
     {
         // 1-Wire reset
@@ -651,8 +681,10 @@
             }
 
             // Perform a triple operation on the DS2482 which will perform 2 read bits and 1 write bit
+            //pc.printf("\n *** preform triplet operation ");
             status = search_triplet(search_direction);
-
+            //pc.printf("%04x",status);
+            
             // check bit results in status byte
             id_bit = ((status & DS2482_STATUS_SBR) == DS2482_STATUS_SBR);
             cmp_id_bit = ((status & DS2482_STATUS_TSB) == DS2482_STATUS_TSB);
@@ -728,6 +760,10 @@
         search_result = FALSE;
     }
 
+    #if OW_MASTER_DEBUG
+        pc.printf(" pass ");
+    #endif
+    
     return search_result;
 }
 
@@ -742,30 +778,20 @@
 //
 uint8_t DS2482::search_triplet(uint8_t search_direction)
 {
-    uint8_t status;
-    uint8_t poll_count = 0;
-
-    i2c.start();
-    i2c.write(OW_I2C_DEVICE + I2C_WRITE);      // set device address & write mode
-    i2c.write(DS2482_CMD_1WT);
-    i2c.write(search_direction ? 0x80 : 0x00);
+    char cmd[2];
+    uint8_t status, poll_count = 0;
 
-    i2c.start();
-    i2c.write(OW_I2C_DEVICE + I2C_READ);
-
-    // loop checking 1WB bit for completion of 1-Wire operation
-    // abort if poll limit reached
-    status = i2c.read(ACK);
-
+    cmd[0] = DS2482_CMD_1WT;
+    cmd[1] = (search_direction ? 0x80 : 0x00);
+    i2c.write(addr,cmd,2);
+    
     do
     {
-        status = i2c.read(ACK);
+        i2c.read(addr,cmd,1);
+        status = cmd[0];
     }
     while ((status & DS2482_STATUS_1WB) && (poll_count++ < POLL_LIMIT));
 
-    status = i2c.read(NAK);
-    i2c.stop();
-
     // check for failure due to poll limit reached
     if (poll_count >= POLL_LIMIT)
     {
@@ -894,7 +920,7 @@
     if (!write_config(c1WS | cSPU | cPPM | cAPU))
     {
         #if OW_MASTER_DEBUG
-            printf("\r\nSPU off");
+            pc.printf("\r\nSPU off");
         #endif
 
         return FALSE;
@@ -910,3 +936,445 @@
 // end I2C DS2482
 //======================================================================
 
+//---------------------------------------------------------------------------
+//-------------------------DS18XX OPERATIONS---------------------------------
+//---------------------------------------------------------------------------
+// find ALL devices on bus 1
+//
+void DS2482::DS18XX_Read_Address(void)
+{
+    uint8_t status, i, j;  
+    
+    //--------------------------------------------------------------
+    // Device Tabele für bus 1 und bus 2 löschen
+
+    for (i = 0; i < OW_MAX_DEVICES; i++)
+    {
+        for (j = 0; j < 8; j++)
+        {
+            ow.device_table[i].rom[j] = 0;
+        }
+    }
+    
+    // pc.printf("\n --- DS18xx_Read_Address --- ");
+    // wait(0.1); 
+    
+    ow.devices = 0;
+    
+    //--------------------------------------------------------------
+    // die Bausteine am Bus suchen
+
+    ow.bus = 0;     
+    //pc.printf("\n -- detect -- \n");
+    //wait(0.5);    
+    detect();    // reset and init the 1-wire master
+    
+    //pc.printf("\n -- OWFirst --\n");
+    //wait(0.1);
+    status = OWFirst();
+
+    if(status == 0)
+    {
+        #if OW_MASTER_START
+            pc.printf("\r\nno 1-Wire slaves found");
+        #endif
+    }
+
+    while(status)
+    {
+        // TODO hier ins eeprom schreiben
+        #if OW_MASTER_START
+            pc.printf("\n*** #%02d ROM_NO= ",ow.devices);
+            wait(0.1);
+        #endif
+
+        for (uint8_t i = 0; i < 8; i++)
+        {
+            ow.device_table[ow.devices].rom[i] = ROM_NO[i]; 
+            
+            #if OW_MASTER_START
+                pc.printf(" 0x%02x",ROM_NO[i]);
+                wait (0.1);          
+            #endif
+        }
+        ow.device_table[ow.devices].status = 0x01; // Wandler gefunden
+
+        status = OWNext();
+        ow.devices++;      // Zeiger auf den nächsten freien Baustein
+
+        // maximal 16 Bausteine
+        if (ow.devices >= OW_MAX_DEVICES) 
+        {
+            ow.devices--; // zeiget auf den letzten gültigen Baustein
+            return;
+        }
+    }
+        
+    #if OW_MASTER_START
+        pc.printf("\r\n");
+    #endif
+                
+    return;
+}
+
+//---------------------------------------------------------------------------
+//
+void DS2482::start_conversion(void)
+{
+    //--------------------------------------------------------------
+    // alle Bausteine an bus 0 starten
+
+    ow.bus = 0;
+
+    // find a DS18S20
+    OWFirst();
+    OWReset();
+
+    // address all devices
+    OWWriteByte(OW_SKIP_ROM);
+
+    //  Start Conversion and Config Strong Pull-Up
+    if (!OWWriteBytePower(OW_CONVERT_TEMP))
+    {
+        #if OW_MASTER_DEBUG
+            pc.printf("Fail convert command\r\n");
+        #endif
+    }
+    
+    //--------------------------------------------------------------
+    // alle Bausteine an bus 1 starten
+    
+    ow.bus = 1;
+    
+    // find a DS18S20
+    OWFirst();
+    OWReset();
+
+    // address all devices
+    OWWriteByte(OW_SKIP_ROM);
+
+    //  Start Conversion and Config Strong Pull-Up
+    if (!OWWriteBytePower(OW_CONVERT_TEMP))
+    {
+        #if OW_MASTER_DEBUG
+            pc.printf("Fail convert command\r\n");
+        #endif
+    }
+
+}
+
+//-----------------------------------------------------------------------------
+
+bool DS2482::ow_read_rom(void)
+{
+  uint8_t n;
+   
+  if ((ow.device_table[ow.device_table_index].status & 0x80) == 0) 
+    ow.bus = 0;
+  else                       
+    ow.bus = 1;
+
+  // Write Read ROM Code command
+  OWWriteByte(OW_CMD_READ_ROM);
+
+  // Read 8 bytes of ROM code
+  for (n = 0; n < 8; n++)
+  {
+    ow_rom_code[n] = OWReadByte();
+  }
+
+  // Do Cyclic Redundancy Check
+  if (crc_calc_buffer(&ow_rom_code[0],7) != ow_rom_code[7])
+  {
+    ow_flags |= OW_CRC_ERROR;
+
+    return false;
+  }
+
+  return true;
+}
+
+//-----------------------------------------------------------------------------
+
+bool DS2482::ow_read_scratchpad(void)
+{
+    uint8_t i, crc;
+
+    ow_flags = 0;
+
+    if ((ow.device_table[ow.device_table_index].status & 0x80) == 0) 
+        ow.bus = 0;
+    else                         
+        ow.bus = 1;
+
+    if (!OWReset()) return false;
+
+    // select the device
+    // den Baustein wird über den ROM Code adressiert
+    OWWriteByte(OW_CMD_MATCH_ROM); // 0x55 match command
+
+    for (i = 0; i < 8; i++)
+    {
+        OWWriteByte(ow.device_table[ow.device_table_index].rom[i]);
+    }
+ 
+    OWWriteByte(OW_CMD_READ_SCRATCHPAD);    // Read Scratch pad 0xBE
+
+    // Read 9 bytes of scratchpad memory
+    for (i = 0; i < OW_SCRATCHPAD_BYTES; i++)
+    {
+        crc = OWReadByte();
+        ow_scratchpad[i] = crc;
+    }
+
+    #if OW_MASTER_DEBUG
+
+        pc.printf("\n*** Scratch_Val ");
+
+        for (i = 1; i < OW_SCRATCHPAD_BYTES; i++)
+        {
+            pc.printf(":0x%02x",ow_scratchpad[i]);
+        }
+
+        pc.printf("\r\n");
+
+    #endif  
+
+    
+    return true;
+}
+
+//-----------------------------------------------------------------------------
+
+bool DS2482::ow_read_scratchpad_ds2438(uint8_t page)
+{
+    uint8_t n, crc;
+
+    ow_flags = 0;
+    
+    if ((ow.device_table[ow.device_table_index].status & 0x80) == 0) 
+        ow.bus = 0;
+    else                         
+        ow.bus = 1;
+
+    if (!OWReset()) return false;
+
+    // select the device
+    // den Baustein wird über den ROM Code adressiert
+    OWWriteByte(OW_CMD_MATCH_ROM); // 0x55 match command
+
+    for (n = 0; n < 8; n++)
+    {
+        OWWriteByte(ow.device_table[ow.device_table_index].rom[n]);
+    }
+  
+    // Write command to read scratchpad memory
+    OWWriteByte(0xbe);                      // 0xBE
+    OWWriteByte(page);                      // 0x03
+
+    // Read 9 bytes of scratchpad memory
+    for (n = 0; n < OW_SCRATCHPAD_BYTES; n++)
+    {
+        crc = OWReadByte();
+        ow_scratchpad[n] = crc;
+        // printf_P(PSTR("%02x "),crc);
+    }
+
+    crc = crc_calc_buffer(ow_scratchpad,8);
+  
+    // Calculate CRC
+    if (crc != ow_scratchpad[8])
+    {
+        ow_flags |= OW_CRC_ERROR;
+        // Read 9 bytes of scratchpad memory
+        pc.printf("\now_read_scratchpad: ");
+        for (n = 0; n < OW_SCRATCHPAD_BYTES; n++)
+        {
+            pc.printf("%02x ",ow_scratchpad[n]);
+        }       
+        pc.printf(": CRC error %02x",crc);
+        return false;
+    }   
+    return true;
+}
+
+//----------------------------------------------------------------------------
+
+bool DS2482::ow_write_scratchpad_ds18x20 (uint8_t th, uint8_t tl)
+{
+    uint8_t i;
+
+    if ((ow.device_table[ow.device_table_index].status & 0x80) == 0) 
+        ow.bus = 0;
+    else                         
+        ow.bus = 1;
+            
+    // Do bus reset
+    if (!OWReset()) return false;
+
+    // select the device
+    // den Baustein wird über den ROM Code adressiert
+    OWWriteByte(OW_CMD_MATCH_ROM); // 0x55 match command
+
+    for (i = 0; i < 8; i++)
+    {
+        OWWriteByte(ow.device_table[ow.device_table_index].rom[i]);
+    }
+
+
+    // Write command to read scratchpad memory
+    OWWriteByte(OW_CMD_WRITE_SCRATCHPAD);
+
+    // Write 1 byte at scratchpad memory
+    OWWriteByte(th);    // Th
+    wait_us(8);         // ist für das Timing der 8 MHZ CPU notwendig
+
+    // Write 1 byte at scratchpad memory
+    OWWriteByte(tl);    // Th
+    wait_us(8);       // ist für das Timing der 8 MHZ CPU notwendig
+
+    // Write 1 byte at scratchpad memory
+    OWWriteByte(0x7F);  // 12 Bit Auflösung
+    wait_us(8);       // ist für das Timing der 8 MHZ CPU notwendig
+
+    return true;
+}
+
+//----------------------------------------------------------------------------
+bool DS2482::ow_write_scratchpad_ds2438 (uint8_t th, uint8_t tl)
+{
+
+    uint8_t i;
+
+    if ((ow.device_table[ow.device_table_index].status & 0x80) == 0) 
+        ow.bus = 0;
+    else                         
+        ow.bus = 1;
+            
+    // Do bus reset
+    if (!OWReset()) return false;
+
+    // select the device
+    // den Baustein wird über den ROM Code adressiert
+    OWWriteByte(OW_CMD_MATCH_ROM); // 0x55 match command
+
+    for (i = 0; i < 8; i++)
+    {
+        OWWriteByte(ow.device_table[ow.device_table_index].rom[i]);
+    }
+
+    // Write command to read scratchpad memory
+    OWWriteByte(0x4E);
+    OWWriteByte(0x03);
+
+    // Write 3 bytes to scratchpad memory
+    OWWriteByte(th); // Th
+    wait_us(8);  
+
+    OWWriteByte(tl); // Tl
+    wait_us(8);  
+
+    return true;
+}
+
+//----------------------------------------------------------------------------
+bool DS2482::ow_write_eeprom_ds18x20 (void)
+{
+
+    uint8_t i;
+
+    if ((ow.device_table[ow.device_table_index].status & 0x80) == 0) 
+        ow.bus = 0;
+    else                         
+        ow.bus = 1;                 
+                              
+    // Do bus reset
+    if (!OWReset()) return false;
+
+    // select the device
+    // den Baustein wird über den ROM Code adressiert
+    OWWriteByte(OW_CMD_MATCH_ROM); // 0x55 match command
+
+    for (i = 0; i < 8; i++)
+    {
+        OWWriteByte(ow.device_table[ow.device_table_index].rom[i]);
+    }
+
+    // Write command to write eeprom
+    OWWriteByte(0x48);
+
+    return true;
+
+}
+
+//----------------------------------------------------------------------------
+bool DS2482::ow_write_eeprom_ds2438 (void)
+{
+    uint8_t i;
+    
+    if ((ow.device_table[ow.device_table_index].status & 0x80) == 0) 
+        ow.bus = 0;
+    else                         
+        ow.bus = 1;
+    
+    // Do bus reset
+    if (!OWReset()) return false;
+
+    // select the device
+    // den Baustein wird über den ROM Code adressiert
+    OWWriteByte(OW_CMD_MATCH_ROM); // 0x55 match command
+
+    for (i = 0; i < 8; i++)
+    {
+        OWWriteByte(ow.device_table[ow.device_table_index].rom[i]);
+    }
+
+    // Write command to read scratchpad memory
+    OWWriteByte(0x48);
+    OWWriteByte(0x03);  
+
+    return true;
+}
+
+
+//----------------------------------------------------------------------------
+
+void DS2482::ow_read_address (void)
+{
+    uint8_t n;
+
+    // ow Adressen aus den Bausteinen lesen
+    for (n = 0; n < OW_MAX_DEVICES; n++)
+    {           
+        if ((ow.device_table[n].status & 0x0f) == 1)
+        {   
+            // printf_P(PSTR("\n device table %d"),n);
+            ow.device_table_index = n; 
+
+            if ((ow.device_table[ow.device_table_index].status & 0x80) == 0) 
+                ow.bus = 0;
+             else                        
+                ow.bus = 1;
+
+            if ((ow.device_table[n].rom[0] == 0x10) || (ow.device_table[n].rom[0] == 0x28))
+            {
+                if (ow_read_scratchpad())
+                {
+                    if(ow_scratchpad[2] == ow_scratchpad[3]) ow.device_table[n].adr = ow_scratchpad[3];
+                }
+            }
+            
+            if ((ow.device_table[n].rom[0] == 0xa6) || (ow.device_table[n].rom[0] == 0x26))
+            {
+                if (ow_read_scratchpad_ds2438(0x03))
+                {
+                    if(ow_scratchpad[0] == ow_scratchpad[1]) ow.device_table[n].adr = ow_scratchpad[0];
+
+                }
+            }
+            
+        }
+
+    } // end for(...
+}
+
--- a/DS2482.h	Sat Apr 27 18:56:53 2013 +0000
+++ b/DS2482.h	Sat May 04 10:11:42 2013 +0000
@@ -9,7 +9,8 @@
 
     #include "mbed.h"
 
-    #define OW_MASTER_START 1
+    #define OW_MASTER_START 0
+    #define OW_MASTER_DEBUG 0
     
     // constants/macros/typdefs
     #define OW_I2C_DEVICE      0x30    // < Change this to the address of your 1-Wire master  
@@ -23,7 +24,7 @@
     #define I2C_READ 1
     #define I2C_WRITE 0
     
-    #define POLL_LIMIT 200
+    #define POLL_LIMIT 100
 
     // Maximale Anzahl der Bausteine am Bus
     #define OW_MAX_DEVICES 16
@@ -52,8 +53,8 @@
     #define OW_CMD_READ_POWER_SUPPLY 0xB4 // Command Signal power supply mode
 
     // Error codes
-    #define OW_RESET_ERROR BIT0
-    #define OW_CRC_ERROR BIT1
+    #define OW_RESET_ERROR      0x01
+    #define OW_CRC_ERROR        0x02
     
     // DS2482 command defines
     #define DS2482_CMD_DRST     0xF0    //< DS2482 Device Reset
@@ -139,7 +140,10 @@
     {
 
       public:
-      
+        
+        // global vars
+        tOW ow;
+         
         /** Create an instance of the PCF8574 connected to specfied I2C pins, with the specified address.
         *
         * @param sda The I2C data pin
@@ -149,9 +153,12 @@
         
         DS2482(PinName sda, PinName scl, int address);
         
-        uint8_t crc_calc(uint8_t x);
         //-----------------------------------------------------------------------------
         // functions
+      
+        // crc buffer
+        uint8_t crc_calc(uint8_t x);
+        uint8_t crc_calc_buffer(uint8_t* pbuffer,uint8_t count);
     
         uint8_t detect(void);
         int reset(void);
@@ -177,24 +184,20 @@
         uint8_t OWLevel(uint8_t new_level);
         uint8_t OWReadBitPower(uint8_t applyPowerResponse);
         uint8_t OWWriteBytePower(uint8_t sendbyte);
-    
-/*    
+       
         void DS18XX_Read_Address(void);
-        void DS2482_start_conversion(void);
+        void start_conversion(void);
  
-
-*/       
       protected:
-/*      
-        BOOL ow_read_rom(void);
-        BOOL ow_read_scratchpad(void);
-        BOOL ow_read_scratchpad_ds2438(uint8_t page);
-        BOOL ow_write_scratchpad_ds18x20 (uint8_t th, uint8_t tl);
-        BOOL ow_write_scratchpad_ds2438 (uint8_t th, uint8_t tl);
-        BOOL ow_write_eeprom_ds18x20 (void);
-        BOOL ow_write_eeprom_ds2438 (void);
+ 
+        bool ow_read_rom(void);
+        bool ow_read_scratchpad(void);
+        bool ow_read_scratchpad_ds2438(uint8_t page);
+        bool ow_write_scratchpad_ds18x20 (uint8_t th, uint8_t tl);
+        bool ow_write_scratchpad_ds2438 (uint8_t th, uint8_t tl);
+        bool ow_write_eeprom_ds18x20 (void);
+        bool ow_write_eeprom_ds2438 (void);
         void ow_read_address (void);
-*/
         //-----------------------------------------------------------------------------
         // vars
         
@@ -203,7 +206,7 @@
         uint8_t crc_value;
                
         // Search state
-        tOW ow;                                         // Variablen in einem Block ablegen
+                                        // Variablen in einem Block ablegen
         uint8_t ow_scratchpad[OW_SCRATCHPAD_BYTES];     // Scratchpad memory
         uint8_t ow_rom_code[OW_ROM_CODE_BYTES];         // Temporary ROM code
         uint8_t ow_flags;
@@ -216,6 +219,8 @@
         uint8_t c1WS, cSPU, cPPM, cAPU;
         uint8_t short_detected;
         
+
+        
 }; // end class
 
 #endif