HSERIN restarts PIC18F2525?


Closed Thread
Results 1 to 8 of 8
  1. #1
    Join Date
    Jun 2006
    Posts
    12

    Default HSERIN restarts PIC18F2525?

    Hey, im trying to (at first) get some simple RS-232 communications between a computer the pic using the following code:

    DEFINE OSC 20

    ' Setup Hardware for UART
    DEFINE HSER_BAUD 9600
    DEFINE HSER_RCSTA 90h
    DEFINE HSER_TXSTA 24h
    DEFINE HSER_CLROERR 1

    RCIF var PIR1.5
    address var byte
    sentinal var byte
    buffer var byte[30]

    init:
    Pause 10 'Safe Start Up Delay

    ADCON1 = 15 ' All pins are digital
    CMCON = 7 ' Turn off comparators
    Poke $81,$FF ' Turn off PORT B pull ups

    TRISA = %00000000
    TRISB = %00000000
    TRISC = %10000000

    address = %00000100
    sentinal = %11111111

    HSEROUT ["Activated"]

    High PORTB.7

    ON Interrupt GOTO inthandle
    INTCON = %11000000
    PIE1.5 = 1

    mainloop:
    @ Nop
    Goto mainloop


    DISABLE

    inthandle:
    If RCIF Then
    HSERIN 100, intreturn, [wait(address),str buffer\30\sentinal]
    HSEROUT [str buffer\30]

    Low PORTB.7
    EndIf
    If RCIF Then inthandle

    intreturn:
    Resume mainloop

    ENABLE




    So what happens? Upon startup the pic reports 'Activated' and the LED on PORTB.7 lights up... When data is sent to the PIC the LED flickers off and on and sends 'Activated' to the computer, usually once but occasionally several times.

    When the 'Low PORTB.7' command is moved before the HSERIN command, incoming data shuts off the LED, but the PIC still restarts. The LED does not reignite after restart.

    Why does this happen?

  2. #2
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Hi breesy,

    It's probably the Resume mainloop causing a Stack Overflow.

    Change it to just Resume

    For more info, see this thread
    http://www.picbasic.co.uk/forum/show...ghlight=resume
    and post 17, same thread.
    <br>
    DT

  3. #3
    Join Date
    Jun 2006
    Posts
    12


    Did you find this post helpful? Yes | No

    Default

    No luck, still restarts after every HSERIN..

    Strange thing is with only a few small modifications the code works on 16F chips.

    Also, if i send data with the wrong address byte, ie something over than %00000100, it does not restart and does not disable the led. Jumps to intreturn after timeout?

  4. #4
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Hmmmm, very odd.

    I've run it here with an 18F452 and everything seems fine.
    Just changed the CMCON and the LED Port. (and the resume)



    Barring a wiring error, or maybe something with the 2525 (don't have one), ya got me.
    <br>
    DT

  5. #5
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    Don't use POKE. Just use the register name followed by the value to write to
    it like you have with ADCON1 = 15.

    Poke $81,$FF is writing $FF to RAM address $81 in bank 0 on this part.

    INTCON2.7 controls portb pull-ups, but you don't really need to turn them off
    with all of portb set to outputs. And the default value of INTCON2 at POR has
    them disabled.

    Don't use RETURN mainloop. As Darrel already pointed out, this is causing
    stack overflow. Using a specific return address here keeps the compiler from
    generating RETFIE, popping the "real" return address from the stack, and
    resetting global interrupts on return.

    Another potential problem is using a timeout with label allowing exit from your
    interrupt handler without clearing RCIF interrupt flag bit first.

    Also with address = %00000100 and wait(address) your terminal program ( or
    whatever you're sending serial data with ) needs to send this as non ASCII. If
    you make address = "4", then it should work when receiving the ASCII value 4.

    With the optional terminator stuck on the end, it can terminate reception of
    the full 30 byte string too. Then HSEROUT [str buffer\30] will send the whole
    30 byte string which may or may not be full of ASCII characters causing
    garbage to be output in non ASCII array element positions.

    Try this;
    Code:
    DEFINE OSC 20
    
    ' Setup Hardware for UART
    DEFINE HSER_BAUD 9600
    DEFINE HSER_RCSTA 90h
    DEFINE HSER_TXSTA 24h
    DEFINE HSER_CLROERR 1
    
    RCIF var PIR1.5
    Junk VAR BYTE
    address var byte
    sentinal var byte
    buffer var byte[30]
    
    init:
    Pause 10 'Safe Start Up Delay
    
        ADCON1 = 15 ' All pins are digital
        CMCON = 7 ' Turn off comparators
        ' Poke $81,$FF ' Turn off PORT B pull ups
        INTCON2.7=1   ' Turn off PORT B pull ups
        
        TRISA = %00000000
        TRISB = %00000000
        TRISC = %10000000
        PORTB = $ff
        
        address = "4" ' or %00000100 +"0"
        sentinal = $FF '%11111111
        
        HSEROUT ["Activated"]
        
        HIGH 7
        
        ON Interrupt GOTO inthandle
        INTCON = %11000000
        PIE1.5 = 1
        
    mainloop:
        @ Nop
        Goto mainloop
        
        
        DISABLE
        
    inthandle:
        TOGGLE 1
        If RCIF Then
         HSERIN 100, intreturn, [wait(address),str buffer\30\sentinal]
         HSEROUT [str buffer\30,13,10]
         Low 7
        EndIf
        If RCIF Then inthandle
        
    intreturn:
        WHILE RCIF
         Junk = RCREG ' trash leftovers to clear RCIF before return
        WEND
        
        Resume    
        ENABLE
        
        END
    Send 4=12345678901234567890123456789 with MCS terminal program to it.

    Then try inserting $FF in the string somewhere to see what happens when it
    finds the terminator. 4=123456789012345678$FF9012345678
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

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


    Did you find this post helpful? Yes | No

    Default

    I had issues like this with the LVP being enabled(The equation is...me = moron). It caused havoc, and was one of those stupid errors that create problems that are seemingly unrelated and difficult to debug.If you don't need it, disable it.

    Ron

  7. #7
    Join Date
    Jun 2006
    Posts
    12


    Did you find this post helpful? Yes | No

    Default

    Hmm I tried the changes that bruce recommended and made sure lvp was off, but still not working... I get 'Activated' after everything i send to it (and the LED doesn't turn off)

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


    Did you find this post helpful? Yes | No

    Default

    Bad psu filtering
    poor contact
    missing or loose MCLR pull-up
    bad crystal
    wrong crystal value

    my guesses as now.

    EDIT: i just tried it here with a 2525... it doesn't do the problem you have.
    Last edited by mister_e; - 1st July 2006 at 11:38.
    Steve

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

Similar Threads

  1. timeout of Hserin, goto, gosub or both?
    By flipper_md in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 28th October 2009, 18:43
  2. Instant Interrupts and HSERIN
    By Rob in forum mel PIC BASIC Pro
    Replies: 26
    Last Post: - 31st January 2009, 05:13
  3. HSERIN problem
    By eggman in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 6th October 2007, 21:31
  4. 16F877a Interupt driven Hserin
    By RFsolution in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 3rd November 2006, 00:38
  5. Hserin
    By egberttheone in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 27th November 2004, 15:42

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