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

Serial Time Out

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



Joined: 03 Aug 2009
Posts: 1067
Location: Panama

View user's profile Send private message

Serial Time Out
PostPosted: Wed Feb 13, 2013 9:17 am     Reply with quote

Hi All,

I am just about finished with a new SMS remote control "driver" (to be posted shortly on the library) but i am a bit annoyed by the use of "delay_ms()"

Due to the nature of the modems, the time they take to reply varies and its nessesary to wait for the modem to accept and reply to the commands sent ...or else

I need a better way to wait for the modem replys...

Currently i use something like this:
Code:
   printf("AT+CMGD=1\r");                 // Send Delete SMS command
   While(counter_read==0){}               // wait for modem to replay
   Delay_ms(1000);                        // delay long enough for modem response


where i poll the buffer counter and then have a fix delay after the first character arrives... this approach works fine but id like something cleaner, that adapts to the modem rather than just a fix delay and be done with it...

i was thinking of setting a timer and having it reset on the UART ISR and stop waiting (as in continue with the rest of the code) upon the timers overflow...

so instead of having a 1 second (completly arbitrary) fixed delay i would end up waiting whatever the overflow period is on the timer only, after the last char arrives...

i was doing my "homework" prior to writing this post and found this:

Quote:
#use rs232(UART1,baud=9600,timeout=500) //timeout = 500 milliseconds, 1/2 second

as suggested by Temtronic...


suggestions? snippets? i welcome your experiences!

thanks,
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: Wed Feb 13, 2013 10:24 am     Reply with quote

might be of help to you - check the listing at end of thread

[url]
http://www.ccsinfo.com/forum/viewtopic.php?t=49625&highlight=timer
[/url]
Gabriel



Joined: 03 Aug 2009
Posts: 1067
Location: Panama

View user's profile Send private message

PostPosted: Wed Feb 13, 2013 11:03 am     Reply with quote

asmboy,

Thank you for your reply.

you might not remember but you already provided me with your delay function previously... It was a thread on changing baud rates.
It is indeed a very versatile delay function.

i might not have explained my self properly.... or didnt understand what you where trying to say... probably the latter

My problems is not with delay_ms() or with setting a proper time out period.


what i would like is something like:

"wait for one character to arrive at UART and continue executing code after 50ms of no chars being received on UART"...

Something like:


Code:
While(counter_read==0){}   // wait for first char
set_timer0(0);                     // start timer
While (!overflow_flag)          // wait for flag to be set in TMR0 ISR
.
.
. code continues


and then have in my Serial ISR:

Code:
#INT_RDA
void serial_isr
{
circle buffer stuff...
set_timer0(0);                     // Reset timer
}


Code:
#INT_TMR0
void Timer0_isr
{
overflow_flag=1;
}


... i have it figured out i think... i just want your input and experiences on doing something like this...


Thanks
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: Wed Feb 13, 2013 12:42 pm     Reply with quote

you can use the function i offered by putting a kbhit(stream);
check in the inner loop "polling location" of the function or adapting it to
be part of your receiver function , as the defined poll location lets you do
any check or other fast acting code snippet on a looping basis - as opposed to the dead-time , thumb twiddling of delay_ms();

BTW i never use fixed delays of other than cycles or usecs in CCS code- its always a counter/timer based function similar to the post ,
as much of what i do is for medical/research instruments- and there is
usually a watchdog barking over my shoulder Very Happy Very Happy Very Happy
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