O'Reilly logo

The Definitive Guide to ARM® Cortex®-M0 and Cortex-M0+ Processors, 2nd Edition by Joseph Yiu

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

18.2. Handling printf

18.2.1. Overview

Based on the examples in the previous section, we can create our own string printing function to handling printing of text strings, as shown below.
// Uart string output
void UART_puts(char  mytext)
{
  char CurrChar;
  CurrChar = ∗mytext;
  while (CurrChar != (char) 0x0){
    UART_putc(CurrChar);  // Normal data
    mytext++;
    CurrChar = ∗mytext;
    }
  return;
}
This works great for printing constant strings. We can also use this function to print other information by using sprint function to print the information to a text buffer, and then output it using UART_puts, the string output function we created:
char txt_buf[30];
sprintf(txt_buf,"%d∖n",1234);
UART_puts(txt_buf);
However, it would also be useful if we can ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required