DS18B20 ID saving To and Reading From EEPROM


Results 1 to 15 of 15

Threaded View

  1. #1
    Join Date
    Dec 2011
    Posts
    14

    Default DS18B20 ID saving To and Reading From EEPROM

    I need a push in the right direction, the answer is probably very simple.

    What I want to do is read the DS18B20 ID, save it to the EEPROM, read it back from the EEPROM into a variable to use in the program.

    I will have up to 5 DS18B20's that I want to save the address to the eeprom incase one fails I can change on the fly with out reprogramming.

    I know I'm going about this all wrong, BUT...

    the typical read DS18B20 ID:
    Code:
    Start_Convert:
    owout dq, 1, [$33] ' issue read rom command
    ID_Loop:
    owin dq, 0, [str id\8] ' Read 64-bit device data into the 8-byte array "ID"
    From there I save it to the EEPROM:
    Code:
            write 106, ID[0]
            write 107, ID[1]
            write 108, ID[2]
            write 109, ID[3]
            write 110, ID[4]
            write 111, ID[5]
            write 112, ID[6]
            write 113, ID[7]
    Then I can read it from the EEPROM at program start

    Code:
            READ 98, Tempsensor1[0]
            READ 99, Tempsensor1[1]
            READ 100, Tempsensor1[2]
            READ 101, Tempsensor1[3]
            READ 102, Tempsensor1[4]
            READ 103, Tempsensor1[5]
            READ 104, Tempsensor1[6]
            READ 105, Tempsensor1[7]
            READ 106, Tempsensor2[0]
            READ 107, Tempsensor2[1]
            READ 108, Tempsensor2[2]
            READ 109, Tempsensor2[3]
            READ 110, Tempsensor2[4]
            READ 111, Tempsensor2[5]
            READ 112, Tempsensor2[6]
            READ 113, Tempsensor2[7]
            READ 114, Tempsensor3[0]
            READ 115, Tempsensor3[1]
            READ 116, Tempsensor3[2]
            READ 117, Tempsensor3[3]
            READ 118, Tempsensor3[4]
            READ 119, Tempsensor3[5]
            READ 120, Tempsensor3[6]
            READ 121, Tempsensor3[7]
    and so on...
    And then I get totaly confused as to how I can select the right sensor and insert the corresponding ID

    Right now I am trying with a select case lookup, but clearly thats not working...
    Code:
     Begin:
        sensor= TEMPSENSOR      'I am reading 5 DS18b20 sensors...
    
        FOR hexbyte=0 TO 7  'each sensor address is 8 bytes
            GOSUB GetID     'go look up each sensors address
            ID[hexbyte]=col 'load the ID array with the retrieved address byte
        NEXT hexbyte        'go get the rest of the address bytes
        OWOUT DQ, 1, [$55,STR ID\8,$44] 'instructs sensors to match[$55] this[ID] rom code and
                                        'initiates[$44] temperature conversion on matching sensor
        CkAgn:
        OWIN DQ, 4, [Busy]      ' Check for still busy converting
        IF Busy = 0 THEN CkAgn  ' Still busy?, then loop
        OWOUT DQ,1,[$55,STR ID\8,$BE]   'instructs sensors to match[$55] this[ID] and start sending back scratchpad[$BE]
        OWIN DQ, 2, [Raw.LOWBYTE,Raw.HIGHBYTE]' Read two temperature bytes, then end communications
        Dummy = 1125 * Raw
        TempF = DIV32 100
        TempF = TempF + 3200
    
        GetID:
        SELECT CASE sensor
    CASE 1 :LOOKUP hexbyte,[HEX Tempsensor1[0],HEX Tempsensor1[1],HEX Tempsensor1[2],HEX Tempsensor1[3],HEX Tempsensor1[4],_HEX Tempsensor1[5],HEX Tempsensor1 [6],HEX Tempsensor1[7]], col      
    CASE 2 :LOOKUP hexbyte,[Tempsensor2[0],[Tempsensor2[1],[Tempsensor2[2],[Tempsensor2[3],_
        [Tempsensor2[4],[Tempsensor2[5],[Tempsensor2 [6],[Tempsensor2[7]], col  
    CASE 3 :LOOKUP hexbyte,[Tempsensor3[0],Tempsensor3[1],Tempsensor3[2],Tempsensor3[3],_
        Tempsensor3[4],Tempsensor3[5],Tempsensor3[6],Tempsensor3[7],], col
    Code:
    ;*** Temp Sensor 1**********************************************************
        ReadTemp1:
        TEMPSENSOR = 1
        GOSUB Begin
            RETURN
     ;*** Temp Sensor 2  *********************************************************
        ReadTemp2:
        TEMPSENSOR = 2
        GOSUB Begin
            RETURN
     ;*** Temp Sensor3 *********************************************************
        ReadTemp3:
        TEMPSENSOR = 3
        GOSUB Begin
           RETURN
    and so on..
    I think the array thing is confusing me for some reason.
    Last edited by snuff28; - 26th November 2013 at 23:52.

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