Shop OBEX P1 Docs P2 Docs Learn Events
URGENT -- Having problem, Please Help. — Parallax Forums

URGENT -- Having problem, Please Help.

ArchiverArchiver Posts: 46,084
edited 2002-09-16 14:05 in General Discussion
I am trying to write some code to read the iButton and also
interface to a GPS receiver.

I have have major problems with 'Returning from a Subroutine'.

It seems as if the Stamp resets itself when it gets to the end of
the subroutine and tries to return.

I have taken this cose from the BS2P Plus pack and am running it on
a 24 pin BS2P.

I will be very grateful for any help on this.

I have connected a 4K7 pull-up resistor on the iButton. The data
from the iButton is displayed successfull, but it them resets when
returning from the 'DisplayRom' Subroutine.

I will also try and upload the code on this site for your reference.

The code is shown below:


'
[noparse][[/noparse] Title ]

'
' File...... 1WIRE-ID=startagain for GPS.BSP
' Purpose... Reads ROM data from 1-Wire device
' Author.... Ashfaq Juna
' E-mail.... ashfaqjuna@h...
' Started...
' Updated...

' {$STAMP BS2p}

'
[noparse][[/noparse] Program Description ]

'
' Reads 1-Wire device ROM pattern. Data is displayed in DEBUG window

'
[noparse][[/noparse] I/O Definitions ]

'
OWpin CON 15 ' 1-wire
device pin

'
[noparse][[/noparse] Constants ]

'
OW_FERst CON %0001 ' Front-End
Reset
OW_BERst CON %0010 ' Back-End
Reset
OW_BitMode CON %0100
OW_HighSpd CON %1000
ReadROM CON $33 ' read ID, serial
num, CRC
SearchROM CON $F0 ' search

NoDevice CON %11 ' no device
present

'
[noparse][[/noparse] Variables ]

'
idx VAR Byte ' loop
counter
romData VAR Byte(8) ' ROM data from DS1820
devCheck VAR Nib ' device
check return ocde

'
[noparse][[/noparse] Initialization ]

'
Initialize:
PAUSE 1000 ' let DEBUG
window open

'
[noparse][[/noparse] Main Code ]

'
Main:
DEBUG CR
DEBUG "Start of Code"

GOSUB DeviceCheck ' look for
device
IF (devCheck <> NoDevice) THEN DisplayROM

'********************************************************************
*****
'
IT SEEMS AS IF THE CODE NEVER GETS TO THIS STAGE
'
WHEN IT ATTEMPS TO RETURN FROM THE SUBROUTINE "
Display Rom"
'
the Stamp seems to reset it self.
'
It goes to the DisplayRom Subroutine successfull,
but resets when it returns from it
'
'********************************************************************
*****


DEBUG " It returns OK"

END



'===============================================================
NoDeviceFound:
DEBUG "No 1-Wire device(s) present."
END

DisplayROM:
DEBUG "Dallas 1-Wire ID : "
OWOUT OWpin,OW_FERst,[noparse][[/noparse]ReadROM] ' send Read
ROM command
OWIN OWpin,OW_BERst,[noparse][[/noparse]STR romData\8] ' read serial number
& CRC

FOR idx = 0 TO 7
DEBUG HEX2 romData(idx)," " ' show ID, serial
num, CRC
NEXT

DEBUG "Returning" '********** THis is the last instruction before
the 'Return'
'********** THE STAMP THEN RESETS IT SELF
RETURN



'
[noparse][[/noparse] Subroutines ]

'
' This subroutine checks to see if any 1-Wire devices are present on
the
' bus. It does NOT search for ROM codes
'
DeviceCheck:
devCheck = 0
OWOUT OWpin,OW_FERst,[noparse][[/noparse]SearchROM] ' reset and start
search
OWIN OWpin,OW_BitMode,[noparse][[/noparse]devCheck.Bit1,devCheck.Bit0]
RETURN




'===============================================================
NoDeviceFound:
DEBUG "No 1-Wire device(s) present."
END

DisplayROM:
DEBUG "Dallas 1-Wire ID : "
OWOUT OWpin,OW_FERst,[noparse][[/noparse]ReadROM] ' send Read
ROM command
OWIN OWpin,OW_BERst,[noparse][[/noparse]STR romData\8] ' read serial number
& CRC

FOR idx = 0 TO 7
DEBUG HEX2 romData(idx)," " ' show ID, serial
num, CRC
NEXT

DEBUG "Returning" '********** THis is the last instruction before
the 'Return'
'********** THE STAMP THEN RESETS IT SELF
RETURN



'
[noparse][[/noparse] Subroutines ]

'
' This subroutine checks to see if any 1-Wire devices are present on
the
' bus. It does NOT search for ROM codes
'
DeviceCheck:
devCheck = 0
OWOUT OWpin,OW_FERst,[noparse][[/noparse]SearchROM] ' reset and start
search
OWIN OWpin,OW_BitMode,[noparse][[/noparse]devCheck.Bit1,devCheck.Bit0]
RETURN

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2002-09-16 12:58
    Hi

    the problem lies in the fact you are calling the 'DisplayRom'
    subroutine from an "IF-THEN" statement. An "IF-THEN" is effectively a
    GOTO not a GOSUB command. This means at the end of 'DisplayRom' you
    need a GOTO statement for the code to know where to go back to. Using
    return does not provide the Stamp a point to return to.

    Cheers
    Col

    --- In basicstamps@y..., "ashfaqjuna" <ashfaqjuna@y...> wrote:
    > I am trying to write some code to read the iButton and also
    > interface to a GPS receiver.
    >
    > I have have major problems with 'Returning from a Subroutine'.
    >
    > It seems as if the Stamp resets itself when it gets to the end of
    > the subroutine and tries to return.
    >
    > I have taken this cose from the BS2P Plus pack and am running it on
    > a 24 pin BS2P.
    >
    > I will be very grateful for any help on this.
    >
    > I have connected a 4K7 pull-up resistor on the iButton. The data
    > from the iButton is displayed successfull, but it them resets when
    > returning from the 'DisplayRom' Subroutine.
    >
    > I will also try and upload the code on this site for your reference.
    >
    > The code is shown below:
    >
    >
    -
    >
    > '
    [noparse][[/noparse] Title ]
    -
    >
    > '
    > ' File...... 1WIRE-ID=startagain for GPS.BSP
    > ' Purpose... Reads ROM data from 1-Wire device
    > ' Author.... Ashfaq Juna
    > ' E-mail.... ashfaqjuna@h...
    > ' Started...
    > ' Updated...
    >
    > ' {$STAMP BS2p}
    >
    > '
    [noparse][[/noparse] Program Description ]
    -
    >
    > '
    > ' Reads 1-Wire device ROM pattern. Data is displayed in DEBUG
    window
    >
    > '
    [noparse][[/noparse] I/O Definitions ]
    -
    >
    > '
    > OWpin CON 15 ' 1-wire
    > device pin
    >
    > '
    [noparse][[/noparse] Constants ]
    -
    >
    > '
    > OW_FERst CON %0001 ' Front-End
    > Reset
    > OW_BERst CON %0010 ' Back-End
    > Reset
    > OW_BitMode CON %0100
    > OW_HighSpd CON %1000
    > ReadROM CON $33 ' read ID,
    serial
    > num, CRC
    > SearchROM CON $F0 ' search
    >
    > NoDevice CON %11 ' no device
    > present
    >
    > '
    [noparse][[/noparse] Variables ]
    -
    >
    > '
    > idx VAR Byte ' loop
    > counter
    > romData VAR Byte(8) ' ROM data from DS1820
    > devCheck VAR Nib ' device
    > check return ocde
    >
    > '
    [noparse][[/noparse] Initialization ]
    -
    >
    > '
    > Initialize:
    > PAUSE 1000 ' let DEBUG
    > window open
    >
    > '
    [noparse][[/noparse] Main Code ]
    -
    >
    > '
    > Main:
    > DEBUG CR
    > DEBUG "Start of Code"
    >
    > GOSUB DeviceCheck ' look for
    > device
    > IF (devCheck <> NoDevice) THEN DisplayROM
    >
    > '*******************************************************************
    *
    > *****
    > '
    IT SEEMS AS IF THE CODE NEVER GETS TO THIS STAGE
    > '
    WHEN IT ATTEMPS TO RETURN FROM THE SUBROUTINE "
    > Display Rom"
    > '
    the Stamp seems to reset it self.
    > '
    It goes to the DisplayRom Subroutine successfull,
    > but resets when it returns from it
    > '
    > '*******************************************************************
    *
    > *****
    >
    >
    > DEBUG " It returns OK"
    >
    > END
    >
    >
    >
    > '===============================================================
    > NoDeviceFound:
    > DEBUG "No 1-Wire device(s) present."
    > END
    >
    > DisplayROM:
    > DEBUG "Dallas 1-Wire ID : "
    > OWOUT OWpin,OW_FERst,[noparse][[/noparse]ReadROM] ' send Read
    > ROM command
    > OWIN OWpin,OW_BERst,[noparse][[/noparse]STR romData\8] ' read serial
    number
    > & CRC
    >
    > FOR idx = 0 TO 7
    > DEBUG HEX2 romData(idx)," " ' show ID,
    serial
    > num, CRC
    > NEXT
    >
    > DEBUG "Returning" '********** THis is the last instruction before
    > the 'Return'
    > '********** THE STAMP THEN RESETS IT SELF
    > RETURN
    >
    >
    >
    > '
    [noparse][[/noparse] Subroutines ]
    -
    >
    > '
    > ' This subroutine checks to see if any 1-Wire devices are present
    on
    > the
    > ' bus. It does NOT search for ROM codes
    > '
    > DeviceCheck:
    > devCheck = 0
    > OWOUT OWpin,OW_FERst,[noparse][[/noparse]SearchROM] ' reset and start
    > search
    > OWIN OWpin,OW_BitMode,[noparse][[/noparse]devCheck.Bit1,devCheck.Bit0]
    > RETURN
    >
    >
    >
    >
    > '===============================================================
    > NoDeviceFound:
    > DEBUG "No 1-Wire device(s) present."
    > END
    >
    > DisplayROM:
    > DEBUG "Dallas 1-Wire ID : "
    > OWOUT OWpin,OW_FERst,[noparse][[/noparse]ReadROM] ' send Read
    > ROM command
    > OWIN OWpin,OW_BERst,[noparse][[/noparse]STR romData\8] ' read serial
    number
    > & CRC
    >
    > FOR idx = 0 TO 7
    > DEBUG HEX2 romData(idx)," " ' show ID,
    serial
    > num, CRC
    > NEXT
    >
    > DEBUG "Returning" '********** THis is the last instruction before
    > the 'Return'
    > '********** THE STAMP THEN RESETS IT SELF
    > RETURN
    >
    >
    >
    > '
    [noparse][[/noparse] Subroutines ]
    -
    >
    > '
    > ' This subroutine checks to see if any 1-Wire devices are present
    on
    > the
    > ' bus. It does NOT search for ROM codes
    > '
    > DeviceCheck:
    > devCheck = 0
    > OWOUT OWpin,OW_FERst,[noparse][[/noparse]SearchROM] ' reset and start
    > search
    > OWIN OWpin,OW_BitMode,[noparse][[/noparse]devCheck.Bit1,devCheck.Bit0]
    > RETURN
  • ArchiverArchiver Posts: 46,084
    edited 2002-09-16 14:05
    Hello Col

    Thank you very much for your help.

    I will ammend the code accordingly.

    Just goes to show how good I am with the Basic Stamp! *S*

    Best Regards

    Ashfaq

    --- In basicstamps@y..., "aussiecol39" <aussiecol39@y...> wrote:
    > Hi
    >
    > the problem lies in the fact you are calling the 'DisplayRom'
    > subroutine from an "IF-THEN" statement. An "IF-THEN" is
    effectively a
    > GOTO not a GOSUB command. This means at the end of 'DisplayRom'
    you
    > need a GOTO statement for the code to know where to go back to.
    Using
    > return does not provide the Stamp a point to return to.
    >
    > Cheers
    > Col
    >
    > --- In basicstamps@y..., "ashfaqjuna" <ashfaqjuna@y...> wrote:
    > > I am trying to write some code to read the iButton and also
    > > interface to a GPS receiver.
    > >
    > > I have have major problems with 'Returning from a Subroutine'.
    > >
    > > It seems as if the Stamp resets itself when it gets to the end
    of
    > > the subroutine and tries to return.
    > >
    > > I have taken this cose from the BS2P Plus pack and am running it
    on
    > > a 24 pin BS2P.
    > >
    > > I will be very grateful for any help on this.
    > >
    > > I have connected a 4K7 pull-up resistor on the iButton. The
    data
    > > from the iButton is displayed successfull, but it them resets
    when
    > > returning from the 'DisplayRom' Subroutine.
    > >
    > > I will also try and upload the code on this site for your
    reference.
    > >
    > > The code is shown below:
    > >
    > >
    ---
    > -
    > >
    > > '
    [noparse][[/noparse] Title ]
    ---
    > -
    > >
    > > '
    > > ' File...... 1WIRE-ID=startagain for GPS.BSP
    > > ' Purpose... Reads ROM data from 1-Wire device
    > > ' Author.... Ashfaq Juna
    > > ' E-mail.... ashfaqjuna@h...
    > > ' Started...
    > > ' Updated...
    > >
    > > ' {$STAMP BS2p}
    > >
    > > '
    [noparse][[/noparse] Program Description ]
    ---
    > -
    > >
    > > '
    > > ' Reads 1-Wire device ROM pattern. Data is displayed in DEBUG
    > window
    > >
    > > '
    [noparse][[/noparse] I/O Definitions ]
    ---
    > -
    > >
    > > '
    > > OWpin CON 15 ' 1-
    wire
    > > device pin
    > >
    > > '
    [noparse][[/noparse] Constants ]
    ---
    > -
    > >
    > > '
    > > OW_FERst CON %0001 ' Front-End
    > > Reset
    > > OW_BERst CON %0010 ' Back-End
    > > Reset
    > > OW_BitMode CON %0100
    > > OW_HighSpd CON %1000
    > > ReadROM CON $33 ' read ID,
    > serial
    > > num, CRC
    > > SearchROM CON $F0 ' search
    > >
    > > NoDevice CON %11 ' no device
    > > present
    > >
    > > '
    [noparse][[/noparse] Variables ]
    ---
    > -
    > >
    > > '
    > > idx VAR Byte ' loop
    > > counter
    > > romData VAR Byte(8) ' ROM data from
    DS1820
    > > devCheck VAR Nib ' device
    > > check return ocde
    > >
    > > '
    [noparse][[/noparse] Initialization ]
    ---
    > -
    > >
    > > '
    > > Initialize:
    > > PAUSE 1000 '
    let DEBUG
    > > window open
    > >
    > > '
    [noparse][[/noparse] Main Code ]
    ---
    > -
    > >
    > > '
    > > Main:
    > > DEBUG CR
    > > DEBUG "Start of Code"
    > >
    > > GOSUB DeviceCheck ' look for
    > > device
    > > IF (devCheck <> NoDevice) THEN DisplayROM
    > >
    >
    > '******************************************************************
    *
    > *
    > > *****
    > > '
    IT SEEMS AS IF THE CODE NEVER GETS TO THIS STAGE
    > > '
    WHEN IT ATTEMPS TO RETURN FROM THE SUBROUTINE "
    > > Display Rom"
    > > '
    the Stamp seems to reset it self.
    > > '
    It goes to the DisplayRom Subroutine
    successfull,
    > > but resets when it returns from it
    > > '
    >
    > '******************************************************************
    *
    > *
    > > *****
    > >
    > >
    > > DEBUG " It returns OK"
    > >
    > > END
    > >
    > >
    > >
    > > '===============================================================
    > > NoDeviceFound:
    > > DEBUG "No 1-Wire device(s) present."
    > > END
    > >
    > > DisplayROM:
    > > DEBUG "Dallas 1-Wire ID : "
    > > OWOUT OWpin,OW_FERst,[noparse][[/noparse]ReadROM] ' send Read
    > > ROM command
    > > OWIN OWpin,OW_BERst,[noparse][[/noparse]STR romData\8] ' read
    serial
    > number
    > > & CRC
    > >
    > > FOR idx = 0 TO 7
    > > DEBUG HEX2 romData(idx)," " ' show ID,
    > serial
    > > num, CRC
    > > NEXT
    > >
    > > DEBUG "Returning" '********** THis is the last instruction
    before
    > > the 'Return'
    > > '********** THE STAMP THEN RESETS IT SELF
    > > RETURN
    > >
    > >
    > >
    > > '
    [noparse][[/noparse] Subroutines ]
    ---
    > -
    > >
    > > '
    > > ' This subroutine checks to see if any 1-Wire devices are
    present
    > on
    > > the
    > > ' bus. It does NOT search for ROM codes
    > > '
    > > DeviceCheck:
    > > devCheck = 0
    > > OWOUT OWpin,OW_FERst,[noparse][[/noparse]SearchROM] ' reset and start
    > > search
    > > OWIN OWpin,OW_BitMode,[noparse][[/noparse]devCheck.Bit1,devCheck.Bit0]
    > > RETURN
    > >
    > >
    > >
    > >
    > > '===============================================================
    > > NoDeviceFound:
    > > DEBUG "No 1-Wire device(s) present."
    > > END
    > >
    > > DisplayROM:
    > > DEBUG "Dallas 1-Wire ID : "
    > > OWOUT OWpin,OW_FERst,[noparse][[/noparse]ReadROM] ' send Read
    > > ROM command
    > > OWIN OWpin,OW_BERst,[noparse][[/noparse]STR romData\8] ' read
    serial
    > number
    > > & CRC
    > >
    > > FOR idx = 0 TO 7
    > > DEBUG HEX2 romData(idx)," " ' show ID,
    > serial
    > > num, CRC
    > > NEXT
    > >
    > > DEBUG "Returning" '********** THis is the last instruction
    before
    > > the 'Return'
    > > '********** THE STAMP THEN RESETS IT SELF
    > > RETURN
    > >
    > >
    > >
    > > '
    [noparse][[/noparse] Subroutines ]
    ---
    > -
    > >
    > > '
    > > ' This subroutine checks to see if any 1-Wire devices are
    present
    > on
    > > the
    > > ' bus. It does NOT search for ROM codes
    > > '
    > > DeviceCheck:
    > > devCheck = 0
    > > OWOUT OWpin,OW_FERst,[noparse][[/noparse]SearchROM] ' reset and start
    > > search
    > > OWIN OWpin,OW_BitMode,[noparse][[/noparse]devCheck.Bit1,devCheck.Bit0]
    > > RETURN
Sign In or Register to comment.