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

getc() and 6 bytes ?

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







getc() and 6 bytes ?
PostPosted: Tue Sep 13, 2005 8:32 am     Reply with quote

Hello,

what i want to do is simple, i have something that is coming on the serial port to the PIC and i usually use getc() function to get a byte.

It is working properly, the only thing is now, that i have to getc() is an information of 6 bytes.

Do i have to do :

Code:
for(i=0;i<5;i++) getc();


Or is there a way to catch all 6 bytes with one instruction to be sure nothing is lost ?

Many thanks.

Best regards.
Ttelmah
Guest







PostPosted: Tue Sep 13, 2005 9:19 am     Reply with quote

The standard multi-byte command is gets, which waits for a carriage return at the end of the data. However it is only implemented using getc.
However it might be work your while looking at input.c, which contains standard definitions for versions to get hex values, numbers, and a string of a defined maximum length.

Best Wishes
Mark



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

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

PostPosted: Tue Sep 13, 2005 11:55 am     Reply with quote

Another solution would be to receive the data into a buffer (using an interrupt) and then process later. If the data can come without be requested, then this is a better approach and less likely to miss any bytes especially if you have other tasks that take longer to complete than the time required to receive a couple of bytes.
Jojo
Guest







PostPosted: Wed Sep 14, 2005 3:15 am     Reply with quote

Ok thanks for you help.
Jojo
Guest







PostPosted: Thu Sep 15, 2005 10:04 am     Reply with quote

A have a problem :

If i do like i said something like :

Code:
a = getc();
b = getc();
c = getc();
d = getc();


It only gets the first byte.

I have send a int32 so 4 bytes.

I tried to cut to have 4 separated bytes but no way it is still locked on the first byte.

Do you have an idea why ?

Is there a time i should put between receiving or sending bytes?

Many thanks.

Best regards.
Ttelmah
Guest







PostPosted: Thu Sep 15, 2005 10:34 am     Reply with quote

If four bytes are being sent, what you post, should receive four bytes.
You need to post some more details. Try a simple example program to do it, like:
Code:

#include <16C717.h>
#use delay(clock=4000000)
#fuses HS,PUT,BROWNOUT,NOWDT,NOMCLR,BORV27
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,ERRORS)

void main() {
   char temp[5];
   int8 ctr;
   setup_counters(RTCC_INTERNAL,WDT_OFF);
   setup_timer_1(T1_DISABLED);
   while(TRUE){
      for (ctr=0;ctr<4;) {
         temp[ctr++]=getc();
      }   
      temp[4]=0;
      printf("Got : %s\n\r",temp);
   }
}

Obviously, the initial settings, will need to change to suit your hardware.
However this is the sort of 'size' of program you need to actually find out what is going on. If you still can't get it to work, post back your test program trimmed to this sort of scale, togethr with the hardware details (how the serial is actually connected etc.).

Best Wishes
Mark



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

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

PostPosted: Thu Sep 15, 2005 12:06 pm     Reply with quote

How are you sending it? Are you really sending all 4 bytes or maybe the int32 is being converted to and int8 and sent thus only getting a single byte.
Jojo
Guest







PostPosted: Fri Sep 16, 2005 3:01 am     Reply with quote

Hello,

i tried different ways and i know that 2 getc() one after another is working well.

But the 3rd byte is not receiving anything and so wait for a data.

It is really a problem, do you think there is a flag or a register that must be cleared when receiving many times ?

I don't really know what's wrong. Maybe there is something i can't understand or can't really know in the PIC, that allows to do this ?

Does someone tested a programm that receive 4 bytes that are sent one after another with a getc() function ?

The 4 bytes are sent separatly one after an other by another device, and they are received on the RX pin of the PIC.

Please, if you can help me. I may try Ttelmah programm, but is there something else ?

Many thanks.

Best regards.
Ttelmah
Guest







PostPosted: Fri Sep 16, 2005 4:44 am     Reply with quote

Simple answer, no.
The only thing is if a receive is not done 'in time', when a character arrives, then characters may be missed, and when using the hardware UART, this can result in the UART switching into an 'error' state, where it stops receiving. This is what the 'errors' statement cures. However with the sort of code shown, this should not even be the remotest possibility. You can hit this sort of problem when trying to receive data at (say) 112Kbaud, on a relatively slow processor clock and writing it to an array, since array accesses are relatively slow, and at this sort of rate, it can just take too long to save the data.
Your example, showing the bytes being written to seperate variables, would avoid this.
Seriously, many of the posters here handle continuous data streams at high rates without problems. For instance I routinely receive and decode packets of data, 32 bytes long at 38400bps, on a processor running at 14.75MHz, 'non stop', and some of these systems have been running without fault for years.
You really should post a lot more details. A simple example that shows the problem, what clock rates and serial rates are involved, processor, and compiler version, would be a good start.
One obvious possibility is that you are actually running into a 'framing' error, because the baud rate you are using cannot be accurately synthesed with the particular crytstal involved, and missing the start bit on the third character.

Best Wishes

Best Wishes
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