Yahoo Groups archive

Lpc2000

Index last updated: 2026-04-28 23:31 UTC

Thread

Printf Problem

Printf Problem

2004-12-14 by gustavo_sagasti

Hi:
I 'm working with Keil and GNU Compiler, and I try to use the printf 
function. I initialised the UART0 and the putchar function works 
fine. But the printf doesn't work. It only works if I use it as printf
("H"), but if I use printf("Hello"), it doesn't work.

This is the putchar function...

int putchar(int ch)  {                  /* Write character to Serial 
Port    */

  if (ch == '\n')  {
    while (!(U0LSR & 0x20));
    U0THR = CR;                      /* output CR */
  }
  while (!(U0LSR & 0x20));
  return (U0THR = ch);
}
I also include the stdio.h library. Do I have to include something 
else to have the printf function working correctly?

Thanks

Re: Printf Problem

2004-12-14 by Gus

what is printf expecting back from putchar?
what is the return value of your printf? if printf is returning 
number less than the character count then printf is not likeing the 
return value from putchar()


Gus

--- In lpc2000@yahoogroups.com, "gustavo_sagasti" 
<gustavo_sagasti@y...> wrote:
> 
> Hi:
> I 'm working with Keil and GNU Compiler, and I try to use the 
printf 
> function. I initialised the UART0 and the putchar function works 
> fine. But the printf doesn't work. It only works if I use it as 
printf
> ("H"), but if I use printf("Hello"), it doesn't work.
> 
> This is the putchar function...
> 
> int putchar(int ch)  {                  /* Write character to 
Serial 
Show quoted textHide quoted text
> Port    */
> 
>   if (ch == '\n')  {
>     while (!(U0LSR & 0x20));
>     U0THR = CR;                      /* output CR */
>   }
>   while (!(U0LSR & 0x20));
>   return (U0THR = ch);
> }
> I also include the stdio.h library. Do I have to include something 
> else to have the printf function working correctly?
> 
> Thanks

Re: Printf Problem

2004-12-14 by gustavo_sagasti

My question is:
In order to have the printf function properly working, What do I have 
to do?
- Do I have to include the stdio.h file?
- Do I have to define a putchar function?
- If printf() uses putchar(), does the putchar() included in the 
compiler? Do I have to provide it?

So, what are the steps in order to use the serial with printf()? 
(assumming I already have the serial initialised and working with the 
putchar routine...)

Thanks

--- In lpc2000@yahoogroups.com, "Gus" <gus_is_working@y...> wrote:
> 
> what is printf expecting back from putchar?
> what is the return value of your printf? if printf is returning 
> number less than the character count then printf is not likeing the 
> return value from putchar()
> 
> 
> Gus
> 
> --- In lpc2000@yahoogroups.com, "gustavo_sagasti" 
> <gustavo_sagasti@y...> wrote:
> > 
> > Hi:
> > I 'm working with Keil and GNU Compiler, and I try to use the 
> printf 
> > function. I initialised the UART0 and the putchar function works 
> > fine. But the printf doesn't work. It only works if I use it as 
> printf
> > ("H"), but if I use printf("Hello"), it doesn't work.
> > 
> > This is the putchar function...
> > 
> > int putchar(int ch)  {                  /* Write character to 
> Serial 
> > Port    */
> > 
> >   if (ch == '\n')  {
> >     while (!(U0LSR & 0x20));
> >     U0THR = CR;                      /* output CR */
> >   }
> >   while (!(U0LSR & 0x20));
> >   return (U0THR = ch);
> > }
> > I also include the stdio.h library. Do I have to include 
something 
Show quoted textHide quoted text
> > else to have the printf function working correctly?
> > 
> > Thanks

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.