> > 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?
Reply by Anders Lindgren●November 8, 20072007-11-08
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.
Reply by microbit_virgin●November 7, 20072007-11-07
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
Reply by linked82●November 7, 20072007-11-07
> > > > Hi all,
> > > >
> > > > I'm still unable to use scanf because I can't find any useful
info
> > > > about how to make it work. I've implemented the getchar() and
> > > > putchar() on my own code, but it still hangs when enters the scanf() > > > > or gets() functions. I know that there are low
level get functions, > > > > but how to configure them? I can't
understand why putchar() works fine > > > > with printf() but getchar don't.
Here's may code.
> > >
> > > What compiler?
> > >
> >
> > IAR 3.40A
>
> Do you use CLib or DLib?
> CLIB
Reply by linked82●November 7, 20072007-11-07
> If it doesn't work with a simple poll
there's obviously no point in putting in interrupts. > Can you probe/trace on RXD pin & check that your
serial (logic) data indeed arrives at MSP430 ? > Set your Terminal for slow speed, like 1200 bps or
so. When you press a key you should see the RXD > pin pulsing to low for a few mS - make sure
that's OK.
> If all OK, check initialisation, some simple test code :
>
> Say, using SMCLK at 8 MHz, 9,600 bps :
>
> #define BAUD (9600)
>
> void init_UART1 (void) {
> UCTL_1 |= SWRST;
> UCTL_1 |= CHAR; // UART1=Async,8 bit,1 stop, > // no
parity, enable SWRST=0, > UTCTL_1 = SSEL1+SSEL0; //
SSEL=SMCLK
> URCTL_1 = URXEIE; // all RXd chars set URXIFG1 > U1BR0 = (unsigned char)(8000000UL/BAUD);
> U1BR1 = 8000000UL/BAUD/256;
> UMCTL_1 = 0; // Baudrate set
> ME2 |= URXE1+UTXE1; // enable UART1 RX + TX
> UCTL_1 &= ~SWRST;
> P3SEL |= (BIT6 + BIT7); // select RXD & TXD alt pin
> P3DIR |= BIT6; // TXD1 out
> }
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.
Reply by microbit_virgin●November 7, 20072007-11-07
Hmmm. OK, these things can get frustrating at times.
You must have a problem with either :
- initialisation of USART1
- hardware issue
If it doesn't work with a simple poll there's obviously no point in
putting in interrupts.
Can you probe/trace on RXD pin & check that your serial (logic) data indeed
arrives at MSP430 ?
Set your Terminal for slow speed, like 1200 bps or so. When you press a key you
should see the RXD
pin pulsing to low for a few mS - make sure that's OK.
If all OK, check initialisation, some simple test code :
-----Original Message-----
From: m... [mailto:m...] On Behalf Of linked82
Sent: Thursday, 8 November 2007 2:16 AM
To: m...
Subject: [msp430] Re: Annoying Scanf
I'm sorry for saying that this still doesn't works. When I call
gets(), I've seen that it is polling getchar for incoming characters,
but it loops and doesn't ends, even if I send CR, LF, EOL or whatever.
I'm going mad.
Reply by John Speth●November 7, 20072007-11-07
> I'm sorry for saying that this still
doesn't works. When I call
> gets(), I've seen that it is polling getchar for incoming characters,
> but it loops and doesn't ends, even if I send CR, LF, EOL or whatever.
> I'm going mad.
Did you enable interrupts properly?
JJS
Reply by linked82●November 7, 20072007-11-07
--- In m..., "microbit_virgin" wrote: >
> If you don't use ints but polling, the least you need to do is to wait until a char is available. > Here's a simple example of polled serial :
>
> int __putchar (int ch)
> {
> while (!(IFG2 & UTXIFG1));
> U1TXBUF = ch;
> return ch;
> }
>
> int __getchar (void)
> {
> while (!(IFG2 & URXIFG1));
> return (U1RXBUF);
> }
>
> Also note that if you don't stick to the prototype of the LIB I/O, your func(s) won't be called. > Make sure getchar() returns an int.
>
I'm sorry for saying that this still doesn't works. When I call
gets(), I've seen that it is polling getchar for incoming characters,
but it loops and doesn't ends, even if I send CR, LF, EOL or whatever.
I'm going mad.
Reply by Leon●November 7, 20072007-11-07
----- Original Message -----
From: "linked82"
To:
Sent: Wednesday, November 07, 2007 1:29 PM
Subject: [msp430] Annoying Scanf > Hi all,
>
> I'm still unable to use scanf because I can't find any useful
info
> about how to make it work. I've implemented the getchar() and
> putchar() on my own code, but it still hangs when enters the scanf()
> or gets() functions. I know that there are low level get functions,
> but how to configure them? I can't understand why putchar() works fine
> with printf() but getchar don't. Here's may code.
Reply by Anders Lindgren●November 7, 20072007-11-07
linked82 wrote: > --- In m... , "Leon"
> wrote:
> >
> > ----- Original Message -----
> > From: "linked82"
> > To: >
> > Sent: Wednesday, November 07, 2007 1:29 PM
> > Subject: [msp430] Annoying Scanf
> >
> >
> > > Hi all,
> > >
> > > I'm still unable to use scanf because I can't find any useful
info
> > > about how to make it work. I've implemented the getchar() and
> > > putchar() on my own code, but it still hangs when enters the scanf()
> > > or gets() functions. I know that there are low level get functions,
> > > but how to configure them? I can't understand why putchar() works
fine
> > > with printf() but getchar don't. Here's may code.
> >
> > What compiler?
> > IAR 3.40A
Do you use CLib or DLib?
-- Anders
--
Disclaimer: Opinions expressed in this posting are strictly my own and
not necessarily those of my employer.