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

gets function for receiving uart data doesn't work

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



Joined: 16 Jan 2008
Posts: 61

View user's profile Send private message

gets function for receiving uart data doesn't work
PostPosted: Tue Sep 11, 2012 1:44 pm     Reply with quote

I am using PIC16f1937 and I am using UART. getc() and putc() works. But gets(string) doesn't work.
Code:

#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)


void main(){
   char string[30];
   setup_oscillator(OSC_16MHZ);
   while(1){
         gets(string);
         puts(string);
    }
}

_________________
nehal
Ttelmah



Joined: 11 Mar 2010
Posts: 19563

View user's profile Send private message

PostPosted: Tue Sep 11, 2012 2:09 pm     Reply with quote

Big difference is you need to send a line feed before gets will return.

Best Wishes
temtronic



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

View user's profile Send private message

PostPosted: Tue Sep 11, 2012 2:35 pm     Reply with quote

also add 'errors' to the use rs232(...) statement to avoid UART 'lockup'.
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Tue Sep 11, 2012 5:11 pm     Reply with quote

Let me politely add, that i never have used gets() as it makes it too easy to hang the program.

The ONLY TWO receive functions i ever use on the USART are:
KBHIT, and when it is TRUE.

mybyte=getc();
and follow that -- process and loop while KBHIT stays true.

I build a string buffer as i go, ignoring ASC 10 and replacing ASC 13 with ASC 0 in the recovered string data.

By putting a KBHIT, conditional block in main() - you can run other processes instead of stall on the 'deadwait' that the pitiful (and really useless) GETS() imposes.
Douglas Kennedy



Joined: 07 Sep 2003
Posts: 755
Location: Florida

View user's profile Send private message AIM Address

PostPosted: Tue Sep 11, 2012 6:58 pm     Reply with quote

Many fail to recognize that rs232 is asynchronous...yes it is never ever synchronized to your code unless you use flow control or if you have a very short isr linked to the RDA interrupt. Never never put delay_xx or puts or printf into an isr and expect a pleasant result.
The code below might work sometimes and sometimes not. The reason is while the puts is sending data the gets is blocked. If you are typing at a keyboard and stop to view the puts data before typing the next line you have created human flow control and it has a good chance of working. Otherwise just hope it's your lucky day.

Code:

while(1)
  {
   gets(string);
   puts(string);
  }
   
nehallove



Joined: 16 Jan 2008
Posts: 61

View user's profile Send private message

PostPosted: Mon Sep 17, 2012 5:50 pm     Reply with quote

Thank you guys.
_________________
nehal
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