Use printf function through serial port in IAR

Source: Internet
Author: User

1. Key. Otherwise, the putchar function will be undefined.

Right-click the project and choose option> general option> ibrary configuration to change library to full, and select full2 from general option> library option> printf formatter.

2. Add in Main. C, where Serial Port 1 is used

/* --------------------------- Privatefunction prototypes -----------------------------------------------*/

# Ifdef _ gnuc __

/* With GCC/raisonance, small printf (option LD linker-> libraries-> small printf

Set to 'Yes') CILS _ io_putchar ()*/

# Define putchar_prototype int _ io_putchar (INT ch)

# Else

# Define putchar_prototype int fputc (int ch, file * F)

# Endif/* _ gnuc __*/

And

 

/**

* @ Brief retargets the C library printffunction to the usart.

* @ Param none

* @ Retval none

*/

Putchar_prototype

{

/* Place your Implementation of fputc here */

/* E.g. Write a character to the usart */

Usart_senddata (eval_com1, (uint8_t) CH );

 

/* Loop until the end of transmission */

While (usart_getflagstatus (eval_com1, usart_flag_tc) = reset );

 

Return ch;

}

The printf function prints the string and ends only when \ 0 is encountered.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.