PIC HANGS with SERIN and Timeout?


Closed Thread
Results 1 to 21 of 21

Hybrid View

  1. #1

    Default PIC HANGS with SERIN and Timeout?

    I'm struggling for hours now.
    I use the following code and added an LED Blink for debug purposes,
    but only gets one blink and then it hangs (on the serin2).
    I have also tried serin.
    Using Pic16F877 and have 2 PIR Sensors,
    one on SENSORPIN1 and one on SENSORPIN2.

    Any ideas?

    <code>


    &nbsp;&nbsp;&nbsp;Include "Modedefs.bas"

    &nbsp;&nbsp;&nbsp;DEFINE&nbsp;&nbsp;&nbsp;OSC 4 ' Set the Xtal frequency

    &nbsp;&nbsp;&nbsp;N2400&nbsp;&nbsp;&nbsp;CON 16780
    &nbsp;&nbsp;&nbsp;P0&nbsp;&nbsp;&nbsp;VAR PORTB.6
    &nbsp;&nbsp;&nbsp;P1&nbsp;&nbsp;&nbsp;VAR PORTB.7
    &nbsp;&nbsp;&nbsp;SENSORNUMBER&nbsp;&nbsp;&nbsp;CO N 0
    &nbsp;&nbsp;&nbsp;SENSORPIN1&nbsp;&nbsp;&nbsp;V AR PORTB.4
    &nbsp;&nbsp;&nbsp;SENSORPIN2&nbsp;&nbsp;&nbsp;V AR PORTB.5
    &nbsp;&nbsp;&nbsp;LEDPIN&nbsp;&nbsp;&nbsp;VAR PORTD.1
    &nbsp;&nbsp;&nbsp;SENSORSTATUS&nbsp;&nbsp;&nbsp;VA R BYTE
    &nbsp;&nbsp;&nbsp;DATARECEIVED&nbsp;&nbsp;&nbsp;va r byte
    &nbsp;&nbsp;&nbsp;CCP1CON = 0
    &nbsp;&nbsp;&nbsp;ADCON1 = 7

    Main:
    &nbsp;&nbsp;&nbsp;OUTPUT LEDPIN
    &nbsp;&nbsp;&nbsp;input SENSORPIN1
    &nbsp;&nbsp;&nbsp;input SENSORPIN2
    Loop:
    &nbsp;&nbsp;&nbsp;IF (SENSORPIN1 = 1) OR (SENSORPIN2 = 1) THEN
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SENSORSTATU S = "1"
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;HIGH LEDPIN
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;PAUSE 1000
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;LOW LEDPIN
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;PAUSE 1000
    &nbsp;&nbsp;&nbsp;ENDIF

    &nbsp;&nbsp;&nbsp;OUTPUT P0
    &nbsp;&nbsp;&nbsp;INPUT P1
    &nbsp;&nbsp;&nbsp;LOW P0

    &nbsp;&nbsp;&nbsp;' ============ LED BLINK FOR DEBUG PURPOSES =================
    &nbsp;&nbsp;&nbsp;HIGH LEDPIN
    &nbsp;&nbsp;&nbsp;PAUSE 100
    &nbsp;&nbsp;&nbsp;LOW LEDPIN
    &nbsp;&nbsp;&nbsp;PAUSE 100
    &nbsp;&nbsp;&nbsp;' ================================================== =========

    &nbsp;&nbsp;&nbsp;SERIN2 P1, N2400, 10, Loop,[wait("T"),DATARECEIVED]

    &nbsp;&nbsp;&nbsp;' ============ LED BLINK FOR DEBUG PURPOSES =================
    &nbsp;&nbsp;&nbsp;HIGH LEDPIN
    &nbsp;&nbsp;&nbsp;PAUSE 100
    &nbsp;&nbsp;&nbsp;LOW LEDPIN
    &nbsp;&nbsp;&nbsp;PAUSE 100
    &nbsp;&nbsp;&nbsp;' ================================================== =========

    &nbsp;&nbsp;&nbsp;if (DATARECEIVED = SENSORNUMBER) then
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;OUTPUT P1
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SEROUT2 P1, N2400, ["R",SENSORSTATUS]
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SENSORSTATU S = "0"
    &nbsp;&nbsp;&nbsp;endif

    &nbsp;&nbsp;&nbsp;' ============ LED BLINK FOR DEBUG PURPOSES =================
    &nbsp;&nbsp;&nbsp;HIGH LEDPIN
    &nbsp;&nbsp;&nbsp;PAUSE 100
    &nbsp;&nbsp;&nbsp;LOW LEDPIN
    &nbsp;&nbsp;&nbsp;PAUSE 100
    &nbsp;&nbsp;&nbsp;' ================================================== =========

    &nbsp;&nbsp;&nbsp;Goto Loop
    end
    </code>

    Thank you!!
    koossa

  2. #2
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by koossa View Post
    I'm struggling for hours now.
    I use the following code and added an LED Blink for debug purposes,
    but only gets one blink and then it hangs (on the serin2).
    I have also tried serin.
    Using Pic16F877 and have 2 PIR Sensors,
    one on SENSORPIN1 and one on SENSORPIN2.
    Any ideas?
    koossa
    I think this is going to tie back into that IDLE state thing, not sure off the top of my head.
    Do a search on the IDLE. Seems to me, if the pin is IDLING in the wrong state, SERIN will hangout waiting for something that ain't comin...

    In the meanwhile, try using a timeout in the SERIN command and see what happens.

  3. #3


    Did you find this post helpful? Yes | No

    Default

    Skimask, thank you very much for your feedback.

    I have taken a look at the idling thing, but don't understand it.

    I have also tried both SERIN and SERIN2 with timeout (10 milliseconds)

    Koossa

  4. #4
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by koossa View Post
    I have taken a look at the idling thing, but don't understand it.
    I have also tried both SERIN and SERIN2 with timeout (10 milliseconds)
    Koossa
    Well, I've never had the idling problem myself, so I can't really comment.
    About all I can suggest is to read the threads again (there's one by Melanie that's especially long and useful) and you're answer will be in there somewhere.
    If I would have to guess, I would say that your input pin is just sitting there at a low logic level. If it is, pull it high and see if the timeout works.
    If it's sitting high, pull it low and see if the timeout works.

  5. #5
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    I do not use spaces in the SERIN2. Try:
    Code:
    SERIN2 P1,N2400,10,Loop,[wait("T"),DATARECEIVED]
    And maybe use 16780 instead of N2400? And DEC before DATARECEIVED.

    Maybe
    Dave
    Always wear safety glasses while programming.

  6. #6
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mackrackit View Post
    I do not use spaces in the SERIN2. Try:
    Code:
    SERIN2 P1,N2400,10,Loop,[wait("T"),DATARECEIVED]
    And maybe use 16780 instead of N2400? And DEC before DATARECEIVED.

    Maybe
    I haven't had a problem with spaces in PBP2.50, had problems back in 2.42 I think it was.
    I've got a program that has about 50-60 different SERIN2 lines and they all look like:

    SERIN2 serialinpin , 84 , 5000 , baddata , [ WAIT ( ">" ) , STR string\255 ]

    Lots of spaces, etc.etc.etc...like I said, the older PBP, broke, newer, good.

  7. #7
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    COOL ,Now I need to upgrade. I am still at 2.47.
    Dave
    Always wear safety glasses while programming.

  8. #8
    Join Date
    Sep 2003
    Location
    Vermont
    Posts
    373


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by skimask View Post
    I haven't had a problem with spaces in PBP2.50, had problems back in 2.42 I think it was.
    I've got a program that has about 50-60 different SERIN2 lines and they all look like:

    SERIN2 serialinpin , 84 , 5000 , baddata , [ WAIT ( ">" ) , STR string\255 ]

    Lots of spaces, etc.etc.etc...like I said, the older PBP, broke, newer, good.
    This may be a moot point, but, I recently had the hang situation with a GPS unit interface. The unit's serial output would go to ground when the unit was put into sleep. I did a little loop that would sense if the line went high at all over a hundred mS period. If not,I would skip the Serin line. It works quite well without any hardware changes.
    Ron

Similar Threads

  1. Serin timeout not working properly!
    By Megahertz in forum mel PIC BASIC Pro
    Replies: 26
    Last Post: - 1st January 2010, 20:56
  2. PIC Hangs when using Serin TimeOut
    By Squibcakes in forum Serial
    Replies: 2
    Last Post: - 20th July 2006, 01:59
  3. 16F628A Serin timeout and Timer1
    By Rubicon in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 26th March 2006, 23:20
  4. SERIN SERIN2 Timeout
    By markedwards in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 23rd June 2005, 18:59
  5. SERIN & Timeout
    By BigWumpus in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 30th October 2004, 07:33

Members who have read this thread : 2

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