View previous topic :: View next topic |
Author |
Message |
kam
Joined: 15 Jul 2005 Posts: 59
|
Serial timeout issues! |
Posted: Thu Aug 09, 2012 2:35 pm |
|
|
Hi all,
Wow, this is maddening
My setup: CCS 4.135
CCS dev boad pic24HJ128GP306
All I want to do is test the "timeout" feature of the rs232. It just would not work for me; so I took the example in the manual and still no go!
Code: |
#include <24HJ128GP306.h>
#device icd=true
#IGNORE_WARNINGS 203
#FUSES HS // high speed
#FUSES NOWDT // no watchdog
#FUSES PR // primary osc
#use delay(clock=20Mhz)
#use rs232(UART1, baud=38400,parity=N,bits=8, timeout=500, STREAM=RS1)
void main()
{
char c;
set_tris_b(0); // port B are all outputs
puts("Start typing...");
while (TRUE)
{
c=getc(RS1);
if(c)
{
putc(c, RS1);
}
output_toggle(PIN_B5);
}
}
|
If I type, I see the characters, and the LED toggles just fine.
If I do nothing, no key press, it just stays in getc, and does not toggle.
It makes no difference if I use or do not use the "stream" name RS1, same results. It makes no difference if I adjust the timeout value. Nada.
I've used different com ports, rebooted, re-flashed, kicked my dog (ok, I did not do that )
~Kam |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9241 Location: Greensville,Ontario
|
|
Posted: Thu Aug 09, 2012 2:39 pm |
|
|
quickly...
maybe ....
this statement ...
#device icd=true
...might affect the program ???
I never use it but maybe ????
grasping at straws here...
also you should always add 'errors' to every use rs232(...options)...
hth
jay |
|
|
Gabriel
Joined: 03 Aug 2009 Posts: 1067 Location: Panama
|
|
Posted: Thu Aug 09, 2012 2:41 pm |
|
|
I might be completely wrong... but i believe... that maybe... in a parallel universe... in a galaxy far away... i seem to rememeber somthing about
getc() waiting for a char or "enter" before breaking from its "internal waiting loop".....
Something along those lines....
I hope I sort of kinda helped you look in what could possibly be the right direction...
and also.... your getc is inside your main... in a while (1) loop.... it will stay there... like batman.
and you never clear the contents of C.
G _________________ CCS PCM 5.078 & CCS PCH 5.093 |
|
|
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
|
Posted: Thu Aug 09, 2012 3:41 pm |
|
|
Code: |
while (TRUE) {
if (kbhit(RS1)){
c=getc(RS1);
if(c) putc(c, RS1);
}
}
|
NEVER EVER call getc unless the low overhead function kbhit says there IS a char to get - unless you feel like HANGING there if no char is in the UART buffer ........ |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Aug 09, 2012 3:53 pm |
|
|
He wants to wait for up to 500ms. If no char arrives in that interval, then exit.
Your method causes immediate exit. But that's not what he wants.
So "never ever" is not correct. It depends on the program design.
Kam,
I don't have the PCD compiler, but your basic program works OK
on an 18F4620, tested in hardware. |
|
|
kam
Joined: 15 Jul 2005 Posts: 59
|
|
Posted: Thu Aug 09, 2012 6:06 pm |
|
|
Hey all,
Ya, I want to wait 1/2 for a timeout...actually, this is the example in the manual (section: how to timeout rs232)...I took it verbatim...I was having error in my program and wanted to provide the smallest possible program showing the error...
Alas, this also happens on my same hardware at home...
CCS support has asked for the lst file...
~Kam |
|
|
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
|
Posted: Thu Aug 09, 2012 6:53 pm |
|
|
Code: |
unsigned int16 count=0;
while(0){
while (count++<500) {
delay_ms(1);
if (kbhit(RS1)){
c=getc(RS1);
if(c) putc(c, RS1);
// break; HERE cold be done here to exit after EACH new char rcvd
// so as not to over run rcv fifo
}
}
// do other stuff after timeout here
// while not ignoring chars that come in
// during monitored 1/2 sec
count=0;
}
|
better or ok ? |
|
|
kam
Joined: 15 Jul 2005 Posts: 59
|
|
Posted: Thu Aug 09, 2012 8:21 pm |
|
|
There are ways around it like you showed, but the REAL issue here is that something is broke in the compiler for the rs232 define regarding "timeout"
I've tried it with both hardware and software uarts, same...
Lets see tomorrow if support can help.
On a good note, they accepted my other "crash" (pointer to array of strings) as a real compiler issue! woot woot...we should get $1 for each bug we find!
~Kam |
|
|
kam
Joined: 15 Jul 2005 Posts: 59
|
[SOLVED] |
Posted: Tue Aug 14, 2012 9:11 am |
|
|
Just a followup to close this thread.
There is a compiler issue causing timeout not to work with at least my chipset, CCS did not elaborate the complete issue/scope (ie. list of effected pics etc). Will be fixed in next release...but they did verify the issue.
~Kam |
|
|
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
|
Posted: Tue Aug 14, 2012 10:39 am |
|
|
Quote: |
something is broke in the compiler for the rs232 define regarding "timeout"
|
I am going out on a limb here to GUESS that implementing the timeout function at the compiler level is not trivial, and does not result in ultra compact code. Consider that, to stay in good form - the compiler can not (safely) dedicate a hardware timer to that feature - hence is stuck with a #use delay style, CPU cycle counting implementation while waiting for a character to arrive - much like the code I wrote. |
|
|
|