Help with 18b20 Stuck with busy bit


Closed Thread
Results 1 to 5 of 5

Hybrid View

  1. #1
    Join Date
    Apr 2012
    Location
    Ptolemaida
    Posts
    50

    Unhappy Help with 18b20 Stuck with busy bit

    Hello there, im kind new with pics but i have some knowledge about basic schematics and programming.
    - I use pic6F88
    - Oscilator 20Mhz
    -And for testing reasons because i dont have an lcd screen i use TX/RX pseudo-RS232

    I have started a project that i need to read 18b20's temp and do something else... but i stuck in busy bit 1 month now, and can't find any solution :'(.

    Im kinda desperate because i dont know what else to check....

    Here is my code :

    include "modedefs.bas"
    '---------------------------------------------------------------
    ' DEFINES
    '---------------------------------------------------------------
    TRISA=%00000010
    TRISB=%00000100
    CMCON=0
    ANSEL=0
    ADCON0=0
    DEFINE OSC 20
    '---------------------------------------------------------------
    ' Variables
    '---------------------------------------------------------------

    present var bit
    count_remain var byte
    count_per_c var byte
    sign1 var byte
    tempout var byte
    temp var byte
    t05 var byte
    t05out var byte
    tempb20 VAR WORD
    DQ VAR PORTA.1
    RX VAR PORTB.2
    TX VAR PORTB.5

    '--------------------------------------------------------------
    ' Initialisation
    '--------------------------------------------------------------
    CLEAR
    serout tx,n9600,["TEST OK",13,10]
    pause 1500
    '-------------------------------------------------------------
    ' Main prog
    '-------------------------------------------------------------
    main:
    while 1
    gosub sensor_ch1
    IF present=1 then
    gosub mainloop1
    tempout=temp
    t05out=t05
    else
    tempout=99
    t05out=9
    endif
    Serout2 tx,16468,["T=",dec2 tempout,",",t05out,"C",13,10]
    pause 250

    wend
    '================================================= =
    ' Subroutines
    '================================================= =

    '------------------------------------------------------------------------------------------
    ' Presence
    '------------------------------------------------------------------------------------------

    sensor_ch1:
    Low DQ 'Set the data pin low to initialize
    PauseUs 500 'Wait for more than 480us
    TRISA.1=1 'Release the data pin (set to input for high)
    PauseUs 100 'Wait for more than 60us
    IF DQ=1 Then 'Is there a DS1820 detected Present=1
    present=0 'If not, then clear DS_VALID flag Presebt=0
    Else
    present=1
    EndIF
    Return 'And return with DS_Valid holding 0
    '---------------------------------------------------------------------------------------------------
    ' Read 18B20 Sensor
    '---------------------------------------------------------------------------------------------------
    mainloop1:
    TRISA.1=0 'read temp ch0 connect it to RA.1
    OWOut DQ, 1, [$CC, $44] 'Start temperature conversion
    waitloop1:
    pauseus 200
    OWOut DQ, 1, [$CC, $BE] 'Read the temperature
    TRISA.1=1
    OWIn DQ, 0, [tempb20.LOWBYTE, tempb20.HIGHBYTE, Skip 4, count_remain, count_per_c]
    IF tempb20.15=1 Then
    sign1=1
    if tempb20.3=1 and tempb20.2=0 and tempb20.1=0 and tempb20.0=0 then
    t05="5"
    else
    t05="0"
    endif
    tempb20=tempb20 >> 4
    tempb20=tempb20.lowbyte ^ 255'Reverse the bits of the lowbyte of TEMP because negative
    temp=tempb20.lowbyte
    Else
    sign1=0
    if tempb20.3=1 then t05="5"
    if tempb20.3=0 then t05="0"
    tempb20=tempb20 >> 4
    temp=tempb20.lowbyte
    EndIF
    Return
    eND

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


    Did you find this post helpful? Yes | No

    Default Re: Help with 18b20 Stuck with busy bit

    you might take a look at this example... (located in the wiki section under projects/temperature)

    http://www.picbasic.co.uk/forum/cont...r-nine-of-them

    you can also search on "ds18b20" for other examples.
    I would suggest you go through your code and add lots of comments to help you trouble shoot and for others to follow what you are trying to do.
    Dwight
    These PIC's are like intricate puzzles just waiting for one to discover their secrets and MASTER their capabilities.

  3. #3
    Join Date
    Apr 2012
    Location
    Ptolemaida
    Posts
    50


    Did you find this post helpful? Yes | No

    Default Re: Help with 18b20 Stuck with busy bit

    Ty Heckler for the reply, but the link that you gave me my friend doesn't work. Stuck in loading... I deleted comments for posting on site i have done them properly :P :P

    My problem is the presence pulse, i can't understand how it works even i have read the datasheet hundrend of times.

    I do low for initialise, i do get a low and going for the converting procedure. But i never get the busy bit back, even i did it with 2 diffrent ways.

    I suspect that the problem is the presence pulse but i dont know how to check it and that's why i came with a post (i also have read a couple of other threads but still no luck) .

  4. #4
    Join Date
    Dec 2008
    Location
    Ploiesti, ROMANIA
    Posts
    582


    Did you find this post helpful? Yes | No

    Default Re: Help with 18b20 Stuck with busy bit

    Take a look here, for a verry good example : http://www.rentron.com/PicBasic/one-wire3.htm

  5. #5
    Join Date
    Apr 2012
    Location
    Ptolemaida
    Posts
    50


    Did you find this post helpful? Yes | No

    Default Re: Help with 18b20 Stuck with busy bit

    I think i found out the problem.... I haven't disabled the A/D inputs nor the Comparators and OPTION_REG . I'll try it out when i have time and ill let you know !!!

Similar Threads

  1. Bit order for HSEROUT[A]
    By BrianT in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 2nd October 2012, 03:47
  2. ds 18b20 circuit.
    By johnyp in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 6th March 2010, 17:40
  3. 18B20 temperature sensor and PIC
    By boban in forum Schematics
    Replies: 2
    Last Post: - 4th June 2007, 13:51
  4. BUSY line technique
    By Demon in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 3rd December 2005, 12:33

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