Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Over flow in pic RCIF flag

Status
Not open for further replies.

Naumanpak

Member level 2
Joined
Nov 19, 2009
Messages
51
Helped
2
Reputation
4
Reaction score
2
Trophy points
1,288
Location
Pakistan
Activity points
1,635
Experts,

I am reading serial data from a GPS into PIC. And it works fine(data is being sent at 1hz).

PROBLEM:

Going further, I will put some instructions that will require a 5 ms delay once every second.

but if I put some delay, RCIF overflows never sets again, I get only 2 char printed.

By checking the overflow, I can revive continuous transmission but the data received is not correct.

Code:
if(RCSTA.OERR==1){
            RCSTA.CREN= 0 ;
            RCSTA.CREN=1;}

Any help will be appreciated.

thanks

Code:
void main()
     {
      unsigned char ch='\0';
      TRISB = 0;
      TRISD = 0;
      Lcd_Ini();
      
      SPBRG=0x26;
      TXSTA.SYNC=0;
      RCSTA.SPEN=1;
      RCSTA.RX9=0;
      RCSTA.CREN=1;
      RCSTA.RX9=0;

      while (1)
            {
             while(!PIR1.RCIF){;}
             ch=RCREG;
             RCREG=0;
             //PIR1.RCIF=0;
             LCD_putc(ch);
                                // Delay_ms(5);
            }


      }
 

Hi Naumanpak,

From the datasheet:

"The RCREG is a double-buffered register (i.e., it is a two-deep FIFO). It is possible for two bytes of data to be received and transferred to the RCREG FIFO and a third byte to begin shifting to the RSR register. On the detection of the Stop bit of the third byte, if the RCREG register is still full, the Overrun Error bit, OERR (RCSTA<1>), will be set. The word in the RSR will be lost. The RCREG register can be read twice to retrieve the two bytes in the FIFO. Overrun bit OERR has to be cleared in software. This is done by resetting the receive logic (CREN is cleared and then set). If bit OERR is set, transfers from the RSR register to the RCREG register are inhibited and no further data will be received. It is, therefore, essential to clear error bit OERR if it is set."

If there is an overflow, the last received byte would be lost and the previous two bytes can be obtained by reading RCREG twice.

I recommend you to first save the received bytes to an array and then display the values or try reducing the baud rate so that you can get ample time in between two successive receptions.
 

    Naumanpak

    Points: 2
    Helpful Answer Positive Rating
Hey thanks matbob!

Real useful and worthy info, its resolved now.


cheers
Nauman
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top