uartprintf Library Readme

  1. Copy or link "uartprintf.h" and "uartprintf.c" to your project.
  2. Include "uartprintf.h" in your main and/or other source file where you want to use the uartprintf() function.
  3. In your main() function call void uartprintf_init(uint32_t baudRate, uint32_t wordLength, uint32_t stopBits, uint32_t parity) by specifing serial comunication parameters.
    For example standard values may be uartprintf_init(115200, UART_WORDLENGTH_9B, UART_STOPBITS_1, UART_PARITY_ODD)
    [If you don't call the uartprintf_init() function a default configuration will be automatically set when calling uartprintf() for the first time in your program. (This is discuraged when you also want to enable UART reception because you will be listening on serial port only after initialization)]
  4. If you want to enable data reception from UART you have to implement one (or both) of this functions in your program:
    void uartprintf_charreceived(char rxchar)
    It will be automatically called when a new char is received (received char is passed as first argument) void uartprintf_linereceived(char* rxline)
    It will be automatically called when a linebreak char is received (received string is passed as first argument).
    [All chars received before the linebreak char are stored in a buffer: max size is 512 chars (included '\0' string termination literal char)]
    [All "\r" or "\n" or "\r\n" or "\n\r" combination are recognized as linebreaks]

uartprintf(const char* format, ...) limits

These limits can be changed by acting on these defines in "uartprintf.h" file: #define _UARTPRINTF_MAX_BUFF         128     N+1 max consecutive calls
#define _UARTPRINTF_MAX_STR          512     Max resulting string length
#define _UARTPRINTF_RXLINE_MAX_STR   512     Max received line length

Download source ->
Nicholas Rocchi  •  Marco Simonazzi