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

RS232 with variable bytes to recieve

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



Joined: 21 Sep 2005
Posts: 12

View user's profile Send private message Yahoo Messenger

RS232 with variable bytes to recieve
PostPosted: Wed Sep 21, 2005 11:49 am     Reply with quote

My code only receives two bytes or 2 Hex Characters. Ideas? I am trying to receive various amounts of data. Rolling Eyes Rolling Eyes

Code:

void recv()
   {
   
   for(i=0;i<=127;i++)
         {
         if(kbhit())
            {
            buffer[i]=getc();
            print_value(i*2,buffer[i]);  //used to show the hex code on my screen
            restart_wdt();
            }
         }
   }
ckielstra



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

View user's profile Send private message

PostPosted: Wed Sep 21, 2005 12:06 pm     Reply with quote

This is a common error for people new to serial communications in the PIC processor. The hardware UART can buffer up to two characters before it reaches an buffer overflow condition and stalls, so make sure your program is fast enough to read all incomming data.
A printf command in a serial receive routine is a tricky thing as the transmission of a single byte takes an equal time to receiving a new byte. From your comments I understand you are showing the hex value, this takes at least two bytes. In the time you receive a single byte you want to transmit two bytes which is impossible.

To get the UART out of the error situation add the ERRORS keyword to the #use RS232 clause. You will still loose data but don't lock up anymore.
cam_male2003



Joined: 21 Sep 2005
Posts: 12

View user's profile Send private message Yahoo Messenger

I will try that
PostPosted: Wed Sep 21, 2005 12:28 pm     Reply with quote

I will add error to my code.. and not print until all the data is received..
Smile
asmallri



Joined: 12 Aug 2004
Posts: 1635
Location: Perth, Australia

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Wed Sep 21, 2005 3:40 pm     Reply with quote

if Recv() is not an interrupt handler then you have another problem. Assume you receive a character every millisecond. The first time through the loop you find a character so it gets put at buffer[0]. The time taken to get thru the loop is 0.8ms. The next time thru the loop (i now = 1) kbhit() returns false. We are now 1.6ms in from the first character. A new character is received. When we call kbhit() the next character is put in buffer[2]. The problem is that buffer[1] did not have anything written to it.
_________________
Regards, Andrew

http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!!
Mark



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

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

PostPosted: Wed Sep 21, 2005 6:25 pm     Reply with quote

http://www.ccsinfo.com/forum/viewtopic.php?t=19306
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