WHILE WEND and SHIFTIN


Closed Thread
Results 1 to 9 of 9

Hybrid View

  1. #1
    Join Date
    Nov 2007
    Location
    South-West of Australia. A small town called Denmark. 'Where the forest meets the sea.'
    Posts
    136


    Did you find this post helpful? Yes | No

    Default Re: WHILE WEND and SHIFTIN

    Thanks for all your replies.

    1. Mackrackit. Yes, there is a 10k pull-up on the data line.
    2. Mr_e. Yes, OSC 32 is in the code.
    3. Mr_e. OSC switchover to use a slower internal oscillator - how do you do this?

    4. Sayzer. Use a timer interrupt to kill the WHILE. I think this is the best way to go but I'm not clear how to make the interrupt jump over the necessary lines. Can an interrupt direct the execution of the code to a label later in the program? I'd appreciate some advice. I am happy with both PBP and assembler coded interrupts.

    The code bit causing the problem is:
    Code:
     
    ' *****************************************************************************
    ' *                                                                           *
    ' *  READ SHT15. Using default setting of 12 bit humidity,14 bit temperature  *
    ' *  Because of the WHILE statemets, this hangs if the SHT15 is not conected  *
    ' *                                                                           *
    ' *****************************************************************************
    ReadSensor:
     gosub Initialise_SHT15
     gosub Start_Sequence
        shiftout DataPin,Clk,1,[SHTCommand\8]     ' Send command byte %0000000011 or %000000101
        input DataPin                             ' Wait for acknowledge
        low Clk
        while DataPin = 1                         ' Sensor ACK by making Data = 0
        wend
        pulsout Clk,10                            ' Send acknowledge
        while DataPin = 0
        wend
        while DataPin = 1                         ' Wait for conversion to complete
        wend
        low Clk
        shiftin DataPin,Clk,0,[RawData.byte1\8]   ' Get the first byte, 8 bits
        low DataPin
        pulsout Clk,10                            ' Send acknowledge
        shiftin DataPin,Clk,0,[RawData.byte0\8]   ' Get the second byte, 8 bits
        low DataPin
        pulsout Clk,10                            ' Send acknowledge
        shiftin DataPin,Clk,0,[CRCsensirion\8]    ' Get third byte, 8 bits, CRC
        high DataPin
        pulsout Clk,10                            ' Send acknowledge
        input DataPin                             ' End of Transmission
        input Clk
        return
    If anyone is interested, I'm happy to post all the SHT15 code?

    Regards Bill Legge

  2. #2
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default Re: WHILE WEND and SHIFTIN

    check this out
    http://www.picbasic.co.uk/forum/showthread.php?t=4093

    still, an home made shiftin is well under 20 lines of code.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  3. #3
    Join Date
    Nov 2007
    Location
    South-West of Australia. A small town called Denmark. 'Where the forest meets the sea.'
    Posts
    136


    Did you find this post helpful? Yes | No

    Default Re: WHILE WEND and SHIFTIN

    Mister_e
    Thanks for that, I didn't know it was possible.
    Another solution to prevent the code hanging has just occured to me.
    Replace the WHILEs with fixed delays that are equal to the longest conversion time of the SHT15 sensor. I think this will be OK but it seems a crude solution compared with an interrupt?

    Regards Bill Legge

  4. #4
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default Re: WHILE WEND and SHIFTIN

    well if you build your own shiftin routine... you could check the state at each clock pulse... neat too.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

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