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 support@ccsinfo.com

timed getc() at 115200 baud?

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



Joined: 15 Sep 2003
Posts: 36

View user's profile Send private message

timed getc() at 115200 baud?
PostPosted: Wed Feb 02, 2005 12:12 pm     Reply with quote

Hello,

I'm using the following code to receive a character at 4800 baud:

Code:

// ---------------------
// Function GetModemChar
// ---------------------
int GetModemChar(void) {
   long timeout;
   
   timeout_error = False;
   timeout = 0;
   while(!kbhit(MODEM) && (++timeout < 5000));
      delay_us(10);
      if (kbhit(MODEM)) return (fgetc(MODEM));
      else {
        timeout_error = True;
        return (0);
      }
}


the same code does not work at 115200, I guess I should change the delay_us sentence to another value?

Please advice
Peter
daveroll
Guest







PostPosted: Wed Feb 02, 2005 1:11 pm     Reply with quote

post all the code.

what clock?

hardware uart or software?

logic signals clean?

why the delay?
Douglas Kennedy



Joined: 07 Sep 2003
Posts: 755
Location: Florida

View user's profile Send private message AIM Address

PostPosted: Wed Feb 02, 2005 2:16 pm     Reply with quote

If I'm right it's in the math. 1/115200 is 8.681 us but you have a 10us delay so you are going to miss at least a bit.
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

PostPosted: Wed Feb 02, 2005 2:38 pm     Reply with quote

I think the delay plus the overhead of the while loop should be less than 1/4 of the bit time, preferably much less. At 115k baud that is less than 1/115k/4= 2.2us.
_________________
The search for better is endless. Instead simply find very good and get the job done.
Guest








PostPosted: Wed Feb 02, 2005 3:18 pm     Reply with quote

clock is at 20MHz, PIC18F252, I've tried from delay_us(2) to delay_us(8) and I am not getting a single char. If I set it back to 4800bps and delay_us(10) it works... :(

Thank you for your help
Peter
Mark



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

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

PostPosted: Wed Feb 02, 2005 3:48 pm     Reply with quote

Is this a hardware uart or software uart. If hardware, I would receive the data into a ring buffer. You can then get the data from the buffer.
runtime



Joined: 15 Sep 2003
Posts: 36

View user's profile Send private message

PostPosted: Wed Feb 02, 2005 3:50 pm     Reply with quote

The code I posted earlier is from the CCS Manual, it says that the delay should be less than a tenth of a bit time, so for 115200 I will get:

(1/115200)/10 = 8.68e-7 = 0.000000868 = 0.868us !!

So I don't think it will work at 115k...

Thank you
Peter
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