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

Putty and RS 232C question Question

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



Joined: 02 Jun 2010
Posts: 74

View user's profile Send private message

Putty and RS 232C question Question
PostPosted: Tue Apr 26, 2011 1:59 am     Reply with quote

Hi, I am trying to make a simple program where the target board prompts the user(PC) to say something, and the user is suppose to return some strings.

The displaying of the character(TX from MCU to PC) works fine on Putty.

However, When I type something on Putty, they don't show but when I press

enter, they get transmitted to MCU and MCU gets it.

I don't know why the Putty is not showing the strings.

Anybody has idea?

Code:
#INCLUDE<18F46K22.h>
#FUSES HSH, NOPLLEN, NOIESO, PUT, NOBROWNOUT, NOWDT, NOPBADEN, MCLR, STVREN

#USE DELAY(clock = 14745600)//14.7456 MHz crystal for baud rate
char string[30];
void main(void){
#USE RS232(UART1, BAUD = 115200, PARITY = E, BITS = 8, STOP = 1)
setup_uart(115200);
set_uart_speed(115200);
while(1){
   printf("Say something \n \r");//need both new line(LF) and carriage return
   gets(string);
   printf("You entered ");
   printf(string);
   printf("\n\r");
}
}


My compiler version is 4.120

Thanks

Thanks
Ttelmah



Joined: 11 Mar 2010
Posts: 19546

View user's profile Send private message

PostPosted: Tue Apr 26, 2011 2:23 am     Reply with quote

First a comment. Lay things out slightly differently. Not 'critical', _but_ will prevent problems latter:
Code:

//SETUP
#INCLUDE<18F46K22.h>
#FUSES HSH, NOPLLEN, NOIESO, PUT, NOBROWNOUT, NOWDT, NOPBADEN, MCLR, STVREN

#USE DELAY(clock = 14745600)//14.7456 MHz crystal for baud rate
#USE RS232(UART1, BAUD = 115200, PARITY = E, BITS = 8, STOP = 1)

//Now GLOBALs
char string[30];

void main(void){
   //setup_uart(115200);
   //set_uart_speed(115200); neither of these are needed - only if you want
   //to change speed - then only one or the other, not both!....
   while(1){
      printf("Say something \n\r");
      gets(string);
      printf("You entered ");
      printf(string);
      printf("\n\r");
   }
}

Now, one other change in this. /n/r, not /n /r.
Some terminal programs _require_ these to be adjacent to one another. May be your entire problem. Smile

Best Wishes
hello188



Joined: 02 Jun 2010
Posts: 74

View user's profile Send private message

PostPosted: Tue Apr 26, 2011 2:56 am     Reply with quote

I am sorry, but it doesn't fix the problem.

When I tried AVR mega644 and scanf function from avrgcc, the cursor blinks as if prompting for response and all the characters I type display.

So, I am thinking maybe there should be a character(esacape sequece)

missing?

Of course, I can force the putty to display the characters I type instead of trying to decide on its own whether or not to display. But i want it to decide on its own correctly.

Thanks
temtronic



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

View user's profile Send private message

PostPosted: Tue Apr 26, 2011 5:26 am     Reply with quote

Is 8 bits AND Even Parity valid for PC hardware and PuTTY ?

Old school guys like me could only have 7 bits AND parity OR 8 bit data only.
hello188



Joined: 02 Jun 2010
Posts: 74

View user's profile Send private message

PostPosted: Tue Apr 26, 2011 10:33 am     Reply with quote

Yea, I think it is possible

It's 8 bit data + 1 parity bit + 1 stop bit
Ttelmah



Joined: 11 Mar 2010
Posts: 19546

View user's profile Send private message

PostPosted: Tue Apr 26, 2011 1:58 pm     Reply with quote

OK.
I was slightly misunderstanding what you were saying was happening. I was getting it as the first string not displaying, but then when you sent the string 'back', it did.
Your problem sounds like local echo being off. This is normally controlled by ESC'E', if your copy is setup in the default mode. The alternative in a sense better, since it then proves that the link is working both ways), is to implement 'echo' yourself in the line input routine. There is an alternative function to gets, that does this for you, and is also better, in allowing you to limit the maximm lne length input, and avoid buffer overflows. Look at get_string in input.c.

Best Wishes
hello188



Joined: 02 Jun 2010
Posts: 74

View user's profile Send private message

PostPosted: Tue Apr 26, 2011 7:48 pm     Reply with quote

Thanks for the replies

What i didn't know was that Hyperterminal/Putty only supposed to display the characters recieved, and not the characters to be sent.

What most of the target devices communicating with PC does is that they echo the characters that they receive, so if you type "c", the MCU receives it and sends "c" again until carriage return.


Thanks
hello188



Joined: 02 Jun 2010
Posts: 74

View user's profile Send private message

PostPosted: Wed Apr 27, 2011 11:51 pm     Reply with quote

That "get_string()" function does just the right thing for me.

It's works virtually like the AVR-GCC's "scanf" function.

Thank's a lot Ttelmah!!
bkamen



Joined: 07 Jan 2004
Posts: 1615
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Fri Apr 29, 2011 10:19 am     Reply with quote

hello188 wrote:
Thanks for the replies

What i didn't know was that Hyperterminal/Putty only supposed to display the characters recieved, and not the characters to be sent.

What most of the target devices communicating with PC does is that they echo the characters that they receive, so if you type "c", the MCU receives it and sends "c" again until carriage return.


Yes. Once upon a time, we actually had use for "echo" (ATE1) being turned on. Very Happy

If your remote application doesn't do it - it's still there.

However, if you want most people to turn on and go, make sure to always echo back stuff you want to be seen in the terminal. It doesn't happen automatically.

I use puTTY all the time. I love that program.

-Ben
_________________
Dazed and confused? I don't think so. Just "plain lost" will do. :D
temtronic



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

View user's profile Send private message

PostPosted: Sat Apr 30, 2011 5:52 am     Reply with quote

What you are talking about is 'local echo', where the device shows you what is transmitted.Probably every 'terminal' program will have it as an option.
I always have it 'disabled' during a debug session,as you can be misled that the remote device is echoing it back,when really it's just the local echo.With local echo enabled and a loopback connector or program running, you'll see 2 copies of each character sent.
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