How to clear RCREG


Closed Thread
Results 1 to 4 of 4
  1. #1
    Join Date
    Apr 2012
    Location
    Ptolemaida
    Posts
    50

    Cool How to clear RCREG

    Hello everyone,

    I would like to ask:
    --How can i clear the RCREGx buffer ?!
    --Is RCREGx a writable register or a readable only ?
    I'm asking because i am using a "Hserin [Str message\50\13]" command and if there are more bytes incoming after the "13" character they are saved right into the RCREGx and reappearing in the next Hsering command as the first received Bytes. And my Message array gets messed up.
    After a lot of testing and playing with the PBP hyperterminal i ended up with this solution:
    Code:
      RCREG1= 0
      RCREG1= 0
      Hserin [Str Message\50\13]
    It seems it is working perfectly and RCREGx cleared but i would like to know if there is anything else.
    There aren't many info about RCREGx in PIC's manual so any information is welcome!
    One man's magic is ANOTHER man's engineering.
    Supernatural is a null word

  2. #2
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,516

    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.

  3. #3
    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

  4. #4
    Join Date
    May 2013
    Location
    australia
    Posts
    2,379

    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, 14:40
  2. Clear LCD
    By rshaver in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 7th October 2011, 22:14
  3. saving RCREG to word
    By Macgman2000 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 15th September 2008, 14: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, 17:25
  5. No Data out of RCREG
    By grayfuse in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 23rd September 2005, 13:02

Members who have read this thread : 1

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