EmbeddedRelated.com
Forums

Annoying Scanf

Started by linked82 November 7, 2007
I didn't know it was a simple as that :-)
The higher layers of C library don't translate these chars.

There's 2 ways to overcome this :
- Set Hyperterminal to send a CR-LF when you press enter. (easiest)
Connection properties -> Settings -> ASCII setup -> ASCII Sending :
Enable "Send line ends with line feeds"
(same for receive if you want)
- You can set up your low level __getchar() func to translate a CR into CR-LF
This is easier to do when you use INT driven circular buffers though.

Best Regards,
Kris

-----Original Message-----
From: m... [mailto:m...] On Behalf Of linked82
Sent: Thursday, 8 November 2007 9:07 AM
To: m...
Subject: [msp430] Re: Annoying Scanf
> > The hardware works OK. If I call the __getchar() or getchar() function
> it works Ok. If I use gets() the softtware hangs waiting for some kind
> of character that never arrives. I've tested various terminal programs.
>

I've just solved my problem. I didn't knew that gets() function needs
a line feed character instead a carrier retur character to end typing
the string. After some reverse engineering and some tests, I realized
of this issue. This is still annoying, because I need to ype
Ctrl-Enter on my terminal (Realterm or Hyperterminal) every time I
have to send a LF character. Can I get rid off this?

TYA

Beginning Microcontrollers with the MSP430

linked82 wrote:
>
> > >
> >
> > The hardware works OK. If I call the __getchar() or getchar() function
> > it works Ok. If I use gets() the softtware hangs waiting for some kind
> > of character that never arrives. I've tested various terminal programs.
> > I've just solved my problem. I didn't knew that gets() function needs
> a line feed character instead a carrier retur character to end typing
> the string. After some reverse engineering and some tests, I realized
> of this issue. This is still annoying, because I need to ype
> Ctrl-Enter on my terminal (Realterm or Hyperterminal) every time I
> have to send a LF character. Can I get rid off this?
>
> TYA

Hi!

The "gets" function simply waits for the '\n' character.

Maybe you can do some kind of translation in your __getchar routine?
(I.e. when ever you recieve a CR you let __getchar return a NL.)

Alternatively, you can rewrite the "gets" routine (the full version of
IAR Embedded Workbench comes with library source).

-- Anders Lindgren
--
Disclaimer: Opinions expressed in this posting are strictly my own and
not necessarily those of my employer.
> > The hardware works OK. If I call the __getchar() or getchar() function
> it works Ok. If I use gets() the softtware hangs waiting for some kind
> of character that never arrives. I've tested various terminal programs.
>

I've just solved my problem. I didn't knew that gets() function needs
a line feed character instead a carrier retur character to end typing
the string. After some reverse engineering and some tests, I realized
of this issue. This is still annoying, because I need to ype
Ctrl-Enter on my terminal (Realterm or Hyperterminal) every time I
have to send a LF character. Can I get rid off this?

TYA