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

Serial timeout issues!

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



Joined: 15 Jul 2005
Posts: 59

View user's profile Send private message

Serial timeout issues!
PostPosted: Thu Aug 09, 2012 2:35 pm     Reply with quote

Hi all,

Wow, this is maddening Sad

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 Razz )

~Kam Sad
temtronic



Joined: 01 Jul 2010
Posts: 9243
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Thu Aug 09, 2012 2:39 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Aug 09, 2012 2:41 pm     Reply with quote

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

View user's profile Send private message AIM Address

PostPosted: Thu Aug 09, 2012 3:41 pm     Reply with quote

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 ........ Very Happy
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Aug 09, 2012 3:53 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Aug 09, 2012 6:06 pm     Reply with quote

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

View user's profile Send private message AIM Address

PostPosted: Thu Aug 09, 2012 6:53 pm     Reply with quote

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 ? Very Happy
kam



Joined: 15 Jul 2005
Posts: 59

View user's profile Send private message

PostPosted: Thu Aug 09, 2012 8:21 pm     Reply with quote

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

View user's profile Send private message

[SOLVED]
PostPosted: Tue Aug 14, 2012 9:11 am     Reply with quote

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

View user's profile Send private message AIM Address

PostPosted: Tue Aug 14, 2012 10:39 am     Reply with quote

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.
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