RCSTA1 issue?


Closed Thread
Results 1 to 10 of 10

Thread: RCSTA1 issue?

Hybrid View

  1. #1
    Join Date
    May 2013
    Location
    australia
    Posts
    2,631


    Did you find this post helpful? Yes | No

    Default Re: RCSTA1 issue?

    there is also this define
    DEFINE HSER_CLROERR 1

  2. #2
    Join Date
    Oct 2005
    Location
    New Jersey
    Posts
    425


    Did you find this post helpful? Yes | No

    Default Re: RCSTA1 issue?

    there is also this define
    DEFINE HSER_CLROERR 1
    That I didn't have in my program. Does it matter where the define goes? If I'm understanding the manual correctly, I shouldn't have to use this any longer? Also, didn't see it mentioned in the manual but will the define clear RCSTA1 and RCSTA2?

    Code:
     IF RCSTA1.1 = 1 THEN    
           RCSTA1.4 = 0          
           RCSTA1.4 = 1
           DAT_IN1 = RCREG1         
           IF PIR1.5 = 1 THEN DAT_IN1 = RCREG1  
        ENDIF
    It still won't help my original problem but I'll try lowering the baud rate and see if that helps. If not, I guess flow control is needed.

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


    Did you find this post helpful? Yes | No

    Default Re: RCSTA1 issue?

    Does it matter where the define goes?
    no defines can go anywhere but for readability most keep them altogether and before the main code begins
    you have not specified the version of pbp used it may mattter
    DEFINE HSER_CLROERR 1 is definitely a pbp3 define I'm not sure if it applies to pbp2.xx maybe someone else can verify or maybe even rtfm , my pbp2.6 book has been misplaced (again)

  4. #4
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,605


    Did you find this post helpful? Yes | No

    Default Re: RCSTA1 issue?

    Hi,
    As far as I know DEFINE HSER_CLROERR 1 (for the second USART it's DEFINE HSER2_CLROERR 1) is available in PBP2.x as well. But, remember that it only "works" when you're actually using HSERIN, if you "drive" the USART manually (like when you do DAT_IN1 = RCREG1) it won't do anything and you'd need to check/clear the overrun flag manually. It all it does is clear the overrun error flag (if set), it won't do anything to actually prevent the overrun condition in first place.

    The main issue here is most likely the overall structure of the program. The data needs to be read from the USART buffer before the next byte comes in, the "best" way to handle this (if you don't know when data is about to come in) is usually to use interrupts. I don't know how you're handling it in your program (I may have missed it).

    /Henrik.

  5. #5
    Join Date
    Oct 2005
    Location
    New Jersey
    Posts
    425


    Did you find this post helpful? Yes | No

    Default Re: RCSTA1 issue?

    As far as I know DEFINE HSER_CLROERR 1 (for the second USART it's DEFINE HSER2_CLROERR 1) is available in PBP2.x as well. But, remember that it only "works" when you're actually using HSERIN, if you "drive" the USART manually (like when you do DAT_IN1 = RCREG1) it won't do anything and you'd need to check/clear the overrun flag manually. It all it does is clear the overrun error flag (if set), it won't do anything to actually prevent the overrun condition in first place.
    Overruns aren't really a problem, except when that condition locks up the device. More importantly, you pointed out something I never caught onto. So there is a HSER@2_CLOERR 1 define.
    The main issue here is most likely the overall structure of the program. The data needs to be read from the USART buffer before the next byte comes in, the "best" way to handle this (if you don't know when data is about to come in) is usually to use interrupts. I don't know how you're handling it in your program (I may have missed it).
    I use HSERIN/HSERIN2 to get all data and I use interrupts to get it. If I understand your post correctly, I can remove this:
    Code:
    IF RCSTA1.1 = 1 THEN    
           RCSTA1.4 = 0          
           RCSTA1.4 = 1
           DAT_IN1 = RCREG1         
           IF PIR1.5 = 1 THEN DAT_IN1 = RCREG1  
        ENDIF
    And just use this:
    Code:
    DEFINE HSER_CLROERR 1
    Is that correct?

  6. #6
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,605


    Did you find this post helpful? Yes | No

    Default Re: RCSTA1 issue?

    Hi Christopher,
    Yes I believe that's correct. I Think what that define does is add code "in front" of the actual HSERIN code so that it checks the overrun flag and, if set, takes care of it.

    /Henrik.

Similar Threads

  1. IF-THEN issue
    By jmgelba in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 12th February 2014, 22:09
  2. TMR1 issue
    By Lestat in forum General
    Replies: 6
    Last Post: - 29th August 2012, 15:41
  3. Timing issue
    By gadelhas in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 29th November 2011, 14:13
  4. Code Issue - select case or 'if' issue - not sure why
    By jamie_s in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 7th October 2007, 08:52
  5. 16F877A issue
    By DynamoBen in forum Off Topic
    Replies: 9
    Last Post: - 31st August 2007, 04:15

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