CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

buffer problem when recieving from rs232

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Nick
Guest







buffer problem when recieving from rs232
PostPosted: Mon Aug 08, 2005 11:08 am     Reply with quote

pic16f876a with 4800-8-n-1 is the configuration for the rs232, i can get the buffer to fill usually once time some times two or none before the pic stops. anyone see a problem with my buffer code? Is there something I am forgeting to do after I fill up th buffer?

buffersize = 80


Code:

void main{
char buffer[buffersize];
int run2=0;
boolean start= false;
while(1)
{



         if (run2 < buffersize-1)
            {
            if (kbhit())
            {
            buffer[run2++]=getc();
                       
             }
             }
            else
            {

              output_high(PIN_B7);
              delay_ms(500);
              output_low(PIN_B7);
               run2=0;
               }
           
            }//end of if statem
           
         
           

}
}
Nick
Guest







PostPosted: Mon Aug 08, 2005 12:13 pm     Reply with quote

i found the answer

SETUP_UART(FALSE); ... before the delay. I guess an overflow error is happening during the delay.

after the delay SETUP_UART(TRUE);

solves the problem, but might not be the best solution.

Nick
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Mon Aug 08, 2005 4:17 pm     Reply with quote

Sounds like a hardware UART buffer overrun.
The UART is capable of buffering up to three incomming characters, after that it will stall until the error flags are cleared. I don't know the side effects of the setup_uart() function, but very likely it also clears the error flags.

Depending on your system requirements a better way for solving this problem is by adding the ERRORS option to your #USE RS232 line. This will ensure the error flags are cleared at every getc() call. Unless you want to detect overrun errors ofcourse....
Nick
Guest







PostPosted: Mon Aug 08, 2005 4:31 pm     Reply with quote

thats a much better solution, my problem was I forgot to add errors to the second RS232 port, causing me alot of headaches. Thanks for the reminder.

Nick
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Mon Aug 08, 2005 5:36 pm     Reply with quote

I hope the 2nd uart is the hardware one. The software uart doesn't need the errors parm. You probably shouldn't be getting overruns though. This means that you missed some data. Receiving the data into a software buffer and keeping interrupts very very short should eliminate those errors but it is still a good idea to have the errors as a back up.
Nick
Guest







PostPosted: Tue Aug 09, 2005 12:24 am     Reply with quote

Mark wrote:
I hope the 2nd uart is the hardware one.


correct
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group