printf with avr gcc over rs232?

Go To Last Post
5 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

hi there!

is it possible to use the printf-command to send the output over the serial interface (rs232)?

can someone post an example?

thanks in advance,
marcus

admin's test signature
 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

No, i don't think it is possible to do it directly! Of course you can use sprintf to fill a buffer and then send the buffer over a UART.

Also, if you want to print a specific kind of information (e.g. only numbers) you should consider writing your own routine, because the code space for printf is quite large.

admin's test signature
 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

In the examples that come with gcctest (available from the GCC pages here) is one that has a printf-like function using the UART. I've tested this and it does work. I think it is gcctest9. Note this is not full printf functionality.

Chris

admin's test signature
 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I've ported gnu printf function to support avr-gcc. It uses program memory to store the format string and this is done transparent to user with a GCC macro. This version of printf have some restrictions - it does not support floating point, because the code size becomes very large.
This function is can be found iin contrib directory of avr-libc. The file is called printf_P.zip

If you like it or have some suggestions, bug reports or so, you can freely e-mail me!

Enjoy!

Alexander Popov

admin's test signature
 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi Marcus!

I have updated my gcctest9 a little bit and have posted it on the web. Here is the link:
www.geocities.com/pieterconradie...

It allows you to do a printf to UART without buffering the whole string in SRAM. Note that it "blocks" until the whole string has been transmitted.

Some of the switches are:
%d - signed decimal
%u - unsigned decimal
%x - hexidecimal ("0x" is prefixed)
%s - string
use "l", e.g. %lx if the value is a 32-bit number

Hope that helps!

Regards
Pieter Conradie