EUSART Stop Receiving


Closed Thread
Results 1 to 2 of 2
  1. #1

    Default EUSART Stop Receiving

    I've noticed a problem and can't seem to find an answer. If I run this program everything appears to work great and I get the bytes received back. The problem appears when I trying to send lots of data the program starts to receive and after on or two transmissions is just hangs up and stops responding to data coming in. Anyone have any ideas what might be causing this issue?

    Code:
    DEFINE  LOADER_USED 1
    
    DEFINE  OSC 16
    DEFINE  HSER_BAUD 2400
    DEFINE  HSER_SPBRG 103 ' 19200 Bauds
    DEFINE  HSER_CLROERR 1  ' Automatically clear over-run errors
    DEFINE  HSER_RCSTA 90h	' Enable USART receive
    DEFINE  HSER_TXSTA 20h	' TXSTA=%00100000. TX enable, BRGH=0 for low-speed
    
    
        x       var     byte        ' General purpose variable
        BytesIn var     byte[80]    ' Serial array - can receive up to 80 bytes
        ByteCnt var     byte        ' Indicates number of bytes in buffer
        eom     con     "~"         ' End Of Message marker
        rcif    var     PIR1.5      ' Alias USART received character interrupt flag bit
    
        ByteCnt = 0             ' Zero counter
    
    INCLUDE "DT_INTS-18.bas"     ' Base Interrupt System
    INCLUDE "ReEnterPBP-18.bas"     ' Include if using PBP interrupts
    
    ASM
    INT_LIST  macro    ; IntSource,        Label,  Type, ResetFlag?
            INT_Handler    RX_INT,  _Receive,   PBP,  yes
        endm
        INT_CREATE               ; Creates the interrupt processor
    
        INT_ENABLE   RX_INT     ; enable external (INT) interrupts
    ENDASM
    
    Main:
        pause 1
        goto Main
    
    Receive:
        if rCIF then                                ' If RCIF=1 there's a new character in RCREG
            BytesIn[ByteCnt] = RCREG               ' Yes. Then store it in array
            if BytesIn[ByteCnt] = eom then OutMsg
            ByteCnt = ByteCnt + 1                  ' Increment array index pointer 
        endif
        goto Receive
    
    OutMsg:
        hserout [13,10,dec ByteCnt," Bytes Received",13,10]
        hserout [str BytesIn\ByteCnt,13,10]
        for x = 0 to ByteCnt                        ' Clear array bytes 0 to ByteCnt
            BytesIn[x] = 0
            next x
        ByteCnt = 0                                 ' Reset index pointer back to first element
        while RCIF                                  ' Keep reading until RCIF is clear to flush buffer
         x = RCREG                                  ' after EOM is received
        wend
    @ INT_RETURN

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

    Default

    Once in your interrupt handler, interrupts are disabled, so you'll miss new data
    that's arriving until you exit & re-enable the interrupt.

    I don't think DEFINE HSER_CLROERR 1 is doing any good unless you use
    HSERIN, so you would need to clear this manually.

    Try reducing the time spent in your interrupt handler. I.E. place;

    if BytesIn[ByteCnt] = eom then OutMsg in Main. Remove OutMsg from your int
    handler, and let Main take care of displaying messages after eom.

    Your interrupt handler should then be fast enough to keep up.
    Code:
    Receive:
        if rCIF then ' do you really need this? ' If RCIF=1 there's a new character in RCREG
            BytesIn[ByteCnt] = RCREG               ' Yes. Then store it in array
            ByteCnt = ByteCnt + 1                  ' Increment array index pointer 
        endif
        @ INT_ENABLE
    It wouldn't hurt to allocate time on the sending device for the PIC to respond
    with the complete message before sending more data after the eom marker.
    Regards,

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

Similar Threads

  1. Defining 2 stop bits using HSEROUT
    By yba2cuo3 in forum Serial
    Replies: 1
    Last Post: - 25th September 2006, 13:12
  2. Too Simple To just Stop!
    By Homerclese in forum mel PIC BASIC
    Replies: 1
    Last Post: - 16th October 2005, 21:39
  3. USB Receiving a Word
    By sean-h in forum USB
    Replies: 2
    Last Post: - 9th October 2005, 16:56
  4. Start and stop a timer
    By Jan Bot in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 10th September 2005, 17:06
  5. Stop program
    By Sam in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 30th March 2004, 14:57

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