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

if statement doesn't work..???
Goto page Previous  1, 2
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Jody



Joined: 08 Sep 2006
Posts: 182

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

PostPosted: Tue Oct 17, 2006 3:14 am     Reply with quote

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

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

PostPosted: Thu Oct 19, 2006 3:06 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Oct 19, 2006 3:32 pm     Reply with quote

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

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

PostPosted: Fri Oct 20, 2006 2:14 am     Reply with quote

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







PostPosted: Fri Oct 20, 2006 3:59 am     Reply with quote

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

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

PostPosted: Fri Oct 20, 2006 4:45 am     Reply with quote

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..??
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2
Page 2 of 2

 
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