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,
admin's test signature
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.
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.
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!
I have updated my gcctest9 a little bit and have posted it on the web. Here is the link:
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!
© 2020 Microchip Technology Inc.