DS18B20 ID saving To and Reading From EEPROM


Closed Thread
Results 1 to 15 of 15

Hybrid View

  1. #1
    Join Date
    Oct 2009
    Location
    Utah, USA
    Posts
    427


    Did you find this post helpful? Yes | No

    Default Re: DS18B20 ID saving To and Reading From EEPROM

    snuff28,

    Sorry for my short reply... I tossed it out while at work.

    Code:
    '=============================================================
    '           Read Temp Sensor and convert to deg F
    '=============================================================
    GetTemp:
        OWOUT  Comm_Pin, 1, [$CC, $4E, 0, 0, DS18B20_9bit]  'set resolution of sensor
    Start_Convert:
        OWOUT  Comm_Pin, 1, [$CC, $44]' Skip ROM search & do temp conversion
    
    Wait_Up:
        OWIN   Comm_Pin, 4, [Busy]    ' Read busy-bit
        IF     Busy = 0 THEN Wait_Up  ' Still busy..?, Wait_Up..!
        OWOUT  Comm_Pin, 1, [$CC, $BE]' Skip ROM search & read scratchpad memory
        OWIN   Comm_Pin, 2, [Raw.byte0, Raw.byte1]' Read two bytes / end comms
    
        '--------------  Convert_Temp: -----------------------
        Sign="+"
        IF Cold_Bit = 1 THEN    'it's below zero Celsius
          C=(ABS Raw>>4)*-10      'so shift the ABS value right and mult X -10
          ELSE
          C=(Raw>>4)*10           'else shift value right and mult X 10
        ENDIF
    
    @ CtoF _C, _F             ; Convert Celsius to Fahrenheit
            'converted value will be X 10, ie. 756=75.6 deg F
            'so devide by 10 to get whole degrees
    
        IF f.15=1 THEN Sign="-" 'if converted value is below zero F then sign is "-"
        TempF = (ABS f)/10      'take tha ABS value and /10
        IF f//10 >4 THEN TempF=TempF+1 'check remainder, if >4 then round up
    return      'with TempF containing current temperature
    here is a snippet of code that I use in a little project. It's been a while since I wrote it (mostly borrowed from Bruce at Rentron and some help I think from Darrell) and I havent studied it lately either.

    But it is agnostic of the device (DS18b20) serial number.
    It works with any sensor I install.
    I'm guessing that I am able to do that because I am only reading one sensor.

    I suspect that if you are trying to read multiple sensors then you have to use the device serial number to address the specific sensor.

    Unless you attach only one sensor to a given PIC pin. Then I think you could ignore the device ID.
    Dwight
    These PIC's are like intricate puzzles just waiting for one to discover their secrets and MASTER their capabilities.

  2. #2
    Join Date
    Dec 2010
    Posts
    409


    Did you find this post helpful? Yes | No

    Default Re: DS18B20 ID saving To and Reading From EEPROM

    If you simply want to be able to swap devices in case of failure (talk to one device at a time only) then don't bother with the serial number at all. You can distinguish the temperature sensor from other types of one wire devices by the family code (if you are building a weather station or something). If you need to talk to a few devices, separate one wire busses on different pins will work for a small number of devices.

  3. #3
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,161


    Did you find this post helpful? Yes | No

    Default Re: DS18B20 ID saving To and Reading From EEPROM

    Maxim has an application note for searching serial numbers of unknown devices. Please see the attached pdf file. It includes the algo and C code (sorry no PBP code yet).

    Hope this helps,
    Ioannis
    Attached Images Attached Images

  4. #4
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,166


    Did you find this post helpful? Yes | No

    Default Re: DS18B20 ID saving To and Reading From EEPROM

    Ioannis, Attached is a routine I wrote some time ago that searches for any 1 Wire device and displays them no mater how many are on the bus. Enjoy....
    Attached Files Attached Files
    Dave Purola,
    N8NTA
    EN82fn

  5. #5
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,161


    Did you find this post helpful? Yes | No

    Default Re: DS18B20 ID saving To and Reading From EEPROM

    Hi Dave,

    nice job and thanks for posting. Snuff28 and others, I am sure will be happy!

    Ioannis

  6. #6
    Join Date
    Dec 2011
    Posts
    14


    Did you find this post helpful? Yes | No

    Default Re: DS18B20 ID saving To and Reading From EEPROM

    Thanks Dave! The routine is awesome! Hopefully I will have some time this weekend to play with it.

    Ioannis: thanks for pointing out the AN187 Search Serial number.pdf, it‎ made Daves routine make sense.

  7. #7
    Join Date
    Dec 2010
    Posts
    409


    Did you find this post helpful? Yes | No

    Default Re: DS18B20 ID saving To and Reading From EEPROM

    So suppose I want to make indoor/ outdoor thermometers for all my family and friends as gifts. I'll have 2 DS18B20's on a bus in the design. How do I resolve which is the indoor one and which is the outdoor one?

Similar Threads

  1. Reading temperature using multi DS18B20
    By KVLV in forum Code Examples
    Replies: 16
    Last Post: - 3rd November 2017, 19:48
  2. Reading DS18S20 and DS18B20 In Same Program
    By Larryd in forum General
    Replies: 4
    Last Post: - 27th January 2013, 05:57
  3. ds18b20 not reading on 16f676
    By revelator in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 2nd April 2009, 00:20
  4. DS18B20 error reading
    By Gaetano in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 29th August 2007, 16:21
  5. Reading 5 DS18B20 Problem
    By CocaColaKid in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 30th August 2005, 20:51

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts