View previous topic :: View next topic |
Author |
Message |
runtime
Joined: 15 Sep 2003 Posts: 36
|
timed getc() at 115200 baud? |
Posted: Wed Feb 02, 2005 12:12 pm |
|
|
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
|
|
Posted: Wed Feb 02, 2005 1:11 pm |
|
|
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
|
|
Posted: Wed Feb 02, 2005 2:16 pm |
|
|
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
|
|
Posted: Wed Feb 02, 2005 2:38 pm |
|
|
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
|
|
Posted: Wed Feb 02, 2005 3:18 pm |
|
|
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
|
|
Posted: Wed Feb 02, 2005 3:48 pm |
|
|
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
|
|
Posted: Wed Feb 02, 2005 3:50 pm |
|
|
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 |
|
|
|