How to clear RCREG


Closed Thread
Results 1 to 4 of 4

Hybrid View

  1. #1
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,614

    Default Re: How to clear RCREG

    Hi,
    I thought HSERIN flushed the buffer first thing - apparently not.... Or are you just concerned that what you describe MIGHT happen if you DON'T clear the buffer before issuing a HSERIN?

    A quick look in the datasheet for a 18F25K22 doesn't really say (or I missed it) if RCREG is writable so I can't really answer that with certainty but how it's "usually" done is to read it untill there's no more data available.

    Code:
    RC1IF VAR PIR1.5   ' Alias to USART receive interrupt flag
    
    WHILE RC1IF
      Dummy = RCREG1
    WEND
    Or, since the FIFO is only two bytes deep, simply
    Code:
    Dummy = RCREG1
    Dummy = RCREG1
    /Henrik.

  2. #2
    Join Date
    Apr 2012
    Location
    Ptolemaida
    Posts
    50

    Default Re: How to clear RCREG

    Thank you for the info Henrik.
    I thought HSERIN flushed the buffer first thing - apparently not
    I used my pic as a Command Line Editor to communicate from my PC Hyperterminal with many Devices. In the past i did care only for debuging those devices so i never went into trouble looking "why the HECK" those two Bytes pop up into my array and as a result to my Hyperterminal.
    Since i have to make a more stable program with many "Command Messages" comming via SMS i tried to debug those two Bytes.
    After a lot of search and testing the result was that Hserin [Str Arrayvar\n\c] saves the string until the "c" char received but it doesn't clear the RCREGx after so if Hserin is used again, the last 2 Bytes that remain in the RCREGx become the 2 first received Bytes !

    I believe RCREGx is both Readable/Writable register because all the codes bellow worked fine.
    Code:
    WHILE RC1IF
      Dummy = RCREG1
    WEND
    Code:
    Dummy = RCREG1
    Dummy = RCREG1
    Code:
    RCREG1= 0
    RCREG1= 0

    Best Regards, Kostas.
    One man's magic is ANOTHER man's engineering.
    Supernatural is a null word

  3. #3
    Join Date
    May 2013
    Location
    australia
    Posts
    2,655

    Default Re: How to clear RCREG

    I tend to use

    RCSTA.4=0 ; (cren)
    RCSTA.4=1

    to clear buffer overrun etc

    but now I wonder if it clears rcreg

Similar Threads

  1. What does CLEAR actually clear?
    By BrianT in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 27th August 2014, 13:40
  2. Clear LCD
    By rshaver in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 7th October 2011, 21:14
  3. saving RCREG to word
    By Macgman2000 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 15th September 2008, 13:51
  4. Does CLEAR Command clear return adrress of a subroutine?
    By sayzer in forum mel PIC BASIC Pro
    Replies: 14
    Last Post: - 19th February 2008, 16:25
  5. No Data out of RCREG
    By grayfuse in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 23rd September 2005, 12:02

Members who have read this thread : 0

You do not have permission to view the list of names.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts