Detection of 1 wire device


Closed Thread
Results 1 to 10 of 10

Hybrid View

  1. #1
    Join Date
    Oct 2009
    Posts
    583

    Default Detection of 1 wire device

    I have a single 18B20 temp sensor and read the device using the code below

    Code:
    'Get and display the temperature
    GIE = 0
    OWOUT DQ, 1, [$CC, $44]                 ' Start temperature conversion
    OWOUT DQ, 1, [$CC, $BE]                 ' Read the temperature
    OWIN DQ, 0, [temperature.LOWBYTE, temperature.HIGHBYTE]
    GIE = 1
    temperature = temperature */ 1600 
    
    lcdout $FE,$D4+0,"TEMP ",dec(temperature / 100),$DF,"C"
    What I would like to do is detect if the sensor is connected or not, and if it's not present to simply display "N/C" in place of the temperature

    Any suggestions

  2. #2
    Join Date
    Feb 2013
    Location
    Quebec, Canada
    Posts
    67


    Did you find this post helpful? Yes | No

    Default Re: Detection of 1 wire device

    Each device has it's unique serial number, you could try read it or write something in the scratch pad (just once) and try read it back.

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


    Did you find this post helpful? Yes | No

    Default Re: Detection of 1 wire device

    From the manual, the OWIN command...
    If a device is not present, OWIN can jump to an optional Label.
    You should be able to just use the Label function of the OWIN command to have your program jump to a routine that displays "N/C"

    Code:
    'Get and display the temperature
    GIE = 0
    OWOUT DQ, 1, [$CC, $44]                 ' Start temperature conversion
    OWOUT DQ, 1, [$CC, $BE]                 ' Read the temperature
    OWIN DQ, 0, [temperature.LOWBYTE, temperature.HIGHBYTE], NoDevice
    GIE = 1
    temperature = temperature */ 1600 
    
    lcdout $FE,$D4+0,"TEMP ",dec(temperature / 100),$DF,"C"
    
    NoDevice:
    lcdout $FE,$D4+0,"No One Wire Device Detected"
    GOTO main
    Last edited by Heckler; - 28th January 2015 at 18:02.
    Dwight
    These PIC's are like intricate puzzles just waiting for one to discover their secrets and MASTER their capabilities.

  4. #4
    Join Date
    Oct 2009
    Posts
    583


    Did you find this post helpful? Yes | No

    Default Re: Detection of 1 wire device

    Thanks for the replies.

    Dwight, I tried your example, but all that happened was a mixture of the text on line 4 of the LCD. I'll keep experimenting maybe taking the NoDevice a gosub rather than goto... But thanks for putting me on the right track

  5. #5
    Join Date
    May 2013
    Location
    australia
    Posts
    2,631


    Did you find this post helpful? Yes | No

    Default Re: Detection of 1 wire device

    I'm sure you would get a better result if you actually waited for the ds18b20 to perform the measurement

    Code:
    'Get and display the temperature
    GIE = 0
    OWOUT DQ, 1, [$CC, $44]                 ' Start temperature conversion
    pause 800
    
    OWOUT DQ, 1, [$CC, $BE]                 ' Read the temperature
    OWIN DQ, 0, [temperature.LOWBYTE, temperature.HIGHBYTE]
    GIE = 1
    temperature = temperature */ 1600 
    
    lcdout $FE,$D4+0,"TEMP ",dec(temperature / 100),$DF,"C"

  6. #6
    Join Date
    Oct 2009
    Posts
    583


    Did you find this post helpful? Yes | No

    Default Re: Detection of 1 wire device

    Cheers Richard,

    I stumbled across a PDF on one wire devices from Microchip, and it suggested the following

    Code:
    OW_reset_pulse
    Describes 1-Wire protocol to generate Reset pulse to detect the presence of the 1-Wire slave device.
    Syntax
    unsigned char OW_reset_pulse(void)
    Parameters
    None
    Return Values
    Return ‘
    0
    ’ if the slave device presence pulse is detected, return ‘
    1
    ’ otherwise.
    Precondition
    None
    Side Effects
    None
    Example
    // OW_reset_pulse function return the presence pulse from the slave device
    if (!OW_reset_pulse())
    return HIGH; // Slave Device is detected
    else
    return LOW; // Slave Device is not detected
    But this uses ASM, so I'll do some further reading on PBP to see if this can be done in basic rather than ASM

Similar Threads

  1. Replies: 1
    Last Post: - 5th October 2011, 08:59
  2. Target Device does not match selected device
    By queenidog in forum FAQ - Frequently Asked Questions
    Replies: 3
    Last Post: - 25th June 2011, 00:24
  3. Target device <> Selected Device????
    By deepgfishing in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 20th June 2007, 21:18
  4. mass storage device 1 MB Flash device
    By Pedro Santos in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 31st August 2006, 03:11
  5. Emulate a 1-wire device
    By johnyman34 in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 22nd February 2005, 20:05

Members who have read this thread : 0

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