| View previous topic :: View next topic |
| Author |
Message |
Jody
Joined: 08 Sep 2006 Posts: 182
|
|
Posted: Tue Oct 17, 2006 3:14 am |
|
|
Compiler version: 3.242
Alright I will correct the string[] problem... you all are right I should check it...
This have to wait to tommorow... I keep you all informed... |
|
 |
Jody
Joined: 08 Sep 2006 Posts: 182
|
|
Posted: Thu Oct 19, 2006 3:06 pm |
|
|
You all where right...
I was overwriting RAM of the PIC.... It is working sort of....
BUT:
I adopted the EX_SISR example.. and build in a RTS/CTS protocol...
But I am missing characters... A PC is sending a file to me and I fill a table in the PIC... But when I raise the CTS line the PC stops transmitting but still sometimes a character slips through... How do I catch that character...
I added mine ISR routine...
| Code: |
#int_rda
void serial_isr() {
int t;
next_in=(next_in+1) % BUFFER_SIZE;
output_high(CTS); //Stop communication
buffer[next_in]=getc();
t=next_in;
if(next_in==next_out)
{
next_in=t; // Buffer full !!
printf("Buffer Full!!");
}
if(buffer[next_in-1] == '\n') //Einde string
{
buffer[next_in] = '\0';
string_ready = TRUE;
output_toggle(EINDE);
}
output_toggle(HARTBEAT);
}
#define bkbhit (next_in!=next_out)
BYTE bgetc() {
BYTE c;
while(!bkbhit) ;
c=buffer[next_out];
next_out=(next_out+1) % BUFFER_SIZE;
return(c);
}
|
and in the main:
| Code: |
while(bkbhit)
putc( bgetc() );
|
When I have done mine calculations I lower the CTS line so the PC sends the rest of the data...
Thanks in advance,
Jody |
|
 |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Oct 19, 2006 3:32 pm |
|
|
The PIC has a hardware receive FIFO for the UART. It can hold
two characters. Also, a 3rd character could be coming into the input
shift register on the UART.
So even though you tell the other device to stop sending, you could
still have some characters in the UART's hardware receive FIFO.
You need to re-think your program design, to handle that issue. |
|
 |
Jody
Joined: 08 Sep 2006 Posts: 182
|
|
Posted: Fri Oct 20, 2006 2:14 am |
|
|
Is there a way to get the charachters out off the receive FIFO so that when I resume transmitting I am sure that the FIFI is empty..
Or do you have an other hint???
Thanks in advance,
Jody |
|
 |
Ttelmah Guest
|
|
Posted: Fri Oct 20, 2006 3:59 am |
|
|
The simplest way to empty the buffer, is:
while (kbhit) dummy=getc();
You need to be able to handle this, since RTS/CTS, definately should _not_ be relied on to stop data immediately on any system. Remember though that the character already in the output shift register, may arrive up to 0.99999* the character transmit time _after_ the line is asserted.
Also, In some cases you may need to deal with more than one character. It is common for the whole hardware transmit buffer on latter UARTs to empty after the line is asserted (typically up to 17 characters...).
Best Wishes |
|
 |
Jody
Joined: 08 Sep 2006 Posts: 182
|
|
Posted: Fri Oct 20, 2006 4:45 am |
|
|
Is it possible to read for i.e. 10 characters and raise the CTS line...but still keep on reading ??
If there are more characters receiving I will catch them..?? |
|
 |
|