DS1820

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
stefbo
Normal user
Posts: 13
Joined: 24 Apr 2016, 15:35
Location: Germany

DS1820

#1 Post by stefbo » 02 May 2016, 00:34

Dear all,
I changed the Plugin_004_DS_readTemp function such that it gives also correct values for DS1820 or DS18s20 (both with family id 0x10). The code is based on the DallasTemperature-lib 3.7.3

Stefan

Code: Select all

boolean Plugin_004_DS_readTemp(uint8_t ROM[8], float *value)
{
  int16_t DSTemp;
  byte ScratchPad[12];
  
  Plugin_004_DS_reset();
  Plugin_004_DS_write(0x55);           // Choose ROM
  for (byte i = 0; i < 8; i++)
    Plugin_004_DS_write(ROM[i]);
  Plugin_004_DS_write(0x44);

  delay(800);

  Plugin_004_DS_reset();
  Plugin_004_DS_write(0x55);           // Choose ROM
  for (byte i = 0; i < 8; i++)
    Plugin_004_DS_write(ROM[i]);
  Plugin_004_DS_write(0xBE); // Read scratchpad

  for (byte i = 0; i < 9; i++)            // copy 8 bytes
    ScratchPad[i] = Plugin_004_DS_read();

  if (Plugin_004_DS_crc8(ScratchPad, 8) != ScratchPad[8])
    {
      *value=0;
      return false;
    }

  if(ROM[0] == 0x28 ) //DS18B20
    {
      DSTemp = (ScratchPad[1] << 8) + ScratchPad[0];
      *value = (float(DSTemp) * 0.0625);
    }
  else if(ROM[0] == 0x10 ) //DS1820 DS18S20
    {
      DSTemp = (ScratchPad[1] << 11) + ScratchPad[0] << 3;
      DSTemp = ((DSTemp & 0xfff0) << 3) - 16 + 
        (
          ((ScratchPad[7] - ScratchPad[6]) << 7) /
            ScratchPad[7]
        );
    *value = float(DSTemp) * 0.0078125;
  }

  return true;
}


bennybubble
Normal user
Posts: 43
Joined: 31 Jan 2016, 21:05

Re: DS1820

#2 Post by bennybubble » 04 May 2016, 11:37

Great job, I've been waiting for this for a long time !

Are you planning to incorporate this into GITHUB so everybody can benefit ?

-ben

tozett
Normal user
Posts: 733
Joined: 22 Dec 2015, 15:46
Location: Germany

Re: DS1820

#3 Post by tozett » 07 May 2016, 13:19

hello Developer,
could you inform us (here, and/or in the changelog), if you adopted this bugfix/ehancement?
(topic was on the wishlist...)
thankx ;) :D

Martinus

Re: DS1820

#4 Post by Martinus » 08 May 2016, 14:18

tozett wrote:hello Developer,
could you inform us (here, and/or in the changelog), if you adopted this bugfix/ehancement?
(topic was on the wishlist...)
thankx ;) :D
Will be added in R106

bennybubble
Normal user
Posts: 43
Joined: 31 Jan 2016, 21:05

Re: DS1820

#5 Post by bennybubble » 09 May 2016, 09:32

Thanks !

Post Reply

Who is online

Users browsing this forum: No registered users and 7 guests