Keil Logo Arm Logo

UART - printf - keil

Next Thread | Thread List | Previous Thread Start a Thread | Settings

Details Message
Read-Only
Author
Niraj chavda
Posted
19-Nov-2007 11:48 GMT
Toolset
ARM
New! UART - printf - keil

printf() is a library routine provided by keil library.
So whenever we use printf in our code I assume what it
might be doing is calls a routine which places characters
of the printf statement in the UART buffer to get it
transmitted from there.

Now in LPC2000 we have two UARTs UART0 and UART1. So the
routine called for printf must be placing characters in one
of these UART buffers. Now I dont find any method to force the
printf tatement to place characters in buffer of specific UART
of our choice.

SO I assumed keil printf statement may be using UART1 data
buffer as default. Because it works fine with UART1 but not
with UART0.

While testing in our code I configured UART0 to transmitte
the data and than used printf statement to send the data. Than I
connected RS232 port of the PC with UART0 of our controller and
observed that it was receiving no data at all.

But when I connected the port to UART1 it was receving garbej
data. Data was garbej because I didnt configure UART1(I assume)

Code and other configuration was same in both the cases except
connection of the PC Rs232 port with UART1 instead of
UART0.

So I am Concluding that keil uses UART1 as default for printf
statments. AM I CORRECT?

Plz guide me if my conclusion is wrong and plz suggest some method
to use UART0 with printf statements because I cant use UART1 in
my project.

Read-Only
Author
Andy Neil
Posted
19-Nov-2007 12:26 GMT
Toolset
ARM
New! RE: UART - printf - keil

http://www.keil.com/support/man/docs/armlib/armlib_cihefhge.htm

Read-Only
Author
Martin Günther
Posted
19-Nov-2007 12:45 GMT
Toolset
ARM
New! RE: UART - printf - keil

Hello Niraj Chavda,

if you want to use printf in your project you have use retargetting and must also provide lowlevel routines for
sending / receiving one character over UART.

Please take a look at example project C:\Keil\ARM\Boards\Keil\MCB2300\Blinky, especially file Retarget.c, to see how retargetting is used.

Best Regards,
Martin Guenther

Read-Only
Author
Niraj chavda
Posted
20-Nov-2007 06:32 GMT
Toolset
ARM
New! RE: UART - printf - keil

Thanks for all replies

I have found the solution.

Just simply create and putchar function in
your main.c file. in that function place the
data into transmitt buffer of uart0 instead of
uart1.

Now wheneveer you use printf in your code printf statment will use your putchar function rather than
library putchar function.

This way you can send data easily to PC using UART0 and printf statement.

Thanks
Niraj
Suggestions comments are always invited

Read-Only
Author
Andy Neil
Posted
20-Nov-2007 07:02 GMT
Toolset
None
New! Suggestion

"create a putchar function in your main.c file."

Don't have it in your main.c file.

Instead, have it in its own putchar.c file.

That way, it will be easier to re-use in other projects!

Read-Only
Author
Niraj chavda
Posted
22-Nov-2007 05:16 GMT
Toolset
ARM
New! RE: Suggestion

There is something more I would like to know

I implemented the scheme as described above but one thing I noticed that the scheme works fine when code is compiled for thumb mode.
i.e. compiler settings are set for generating code in thumb mode (options for target->C->use thumb mode)

If I set this option to generate code in ARM mode than compiler is generating an error such as

*** ERROR L104: MULTIPLE PUBLIC DEFINITIONS

SYMBOL: putchar?A

MODULE: C:\KEIL\ARM\LIB\CALFP.LIB (putchar)

DEFINED: .\Obj\main.obj (main)

Is it that I cant redirect printf to use my putchar routin in ARM mode? Can anybody put some light on it?

Thanks

Next Thread | Thread List | Previous Thread Start a Thread | Settings

Keil logo

Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings