Skip to content

Latest commit

 

History

History

Send_Formatted_String_Using_Printf

MCHP

Send Formatted Strings Using 'printf'

This example demonstrates how to send formatted messages through the Universal Synchronous and Asynchronous Receiver and Transmitter (USART) using 'printf'. It sends the value of an 8-bit counter every 500ms, as a message and then increases the counter.

Related Documentation

More details and code examples on the ATMEGA4809 can be found at the following links:

Software Used

Hardware Used

Setup

The ATMEGA4809 Xplained Pro Development Board is used as test platform.


The following configurations must be made for this project:

  • Clock frequency set to 3.33 MHz

USART1 configuration:

  • 9600 baud rate
  • 8 data bits
  • no parity bit
  • 1 stop bit
  • TX pin enabled (PC0)
Pin Configuration
PC0 (USART1 TX) Digital output

Operation

  1. Connect the board to the PC.

  2. Open the atmega4809-getting-started-with-usart-studio.atsln solution in Microchip Studio.

  3. Set the Send_Formatted_Strings_Using_Printf project as Start Up project. Right click on the project in the Solution Explorer tab and click Set as StartUp Project.


  1. Build the Send_Formatted_Strings_Using_Printf project: right click on the atmega4809-getting-started-with-usart-studio solution and select Build Solution.


  1. Select the ATMEGA4809 Xplained Pro in the Connected Hardware Tool section of the project settings:
  • Right click on the project and click Properties;
  • Click on the Tool tab.
  • Select the ATMEGA4809 Xplained Pro (click on the SN) in the Selected debugger/programmer section, and save (CTRL + S):


  1. Program the project to the board: click on the Debug tab and click Start Without Debugging.


Demo


In this demo, the value of the increasing counter is transmitted in the form of Counter value is: <counter_value>\r\n.

Summary

This project shows how to use the USART peripheral to send formatted strings.