View previous topic :: View next topic |
Author |
Message |
Nick Guest
|
buffer problem when recieving from rs232 |
Posted: Mon Aug 08, 2005 11:08 am |
|
|
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
|
|
Posted: Mon Aug 08, 2005 12:13 pm |
|
|
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
|
|
Posted: Mon Aug 08, 2005 4:17 pm |
|
|
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
|
|
Posted: Mon Aug 08, 2005 4:31 pm |
|
|
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
|
|
Posted: Mon Aug 08, 2005 5:36 pm |
|
|
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
|
|
Posted: Tue Aug 09, 2005 12:24 am |
|
|
Mark wrote: | I hope the 2nd uart is the hardware one. |
correct |
|
|
|