Skip to content

This example uses the MCC Melody Library to show how to configure the USART on the AVR128DB48 CNANO to print 'Hello World' in the MPLAB Data Visualizer. This example can be used with MPLABX or MPLAB XPRESS IDE.

License

Notifications You must be signed in to change notification settings

microchip-pic-avr-examples/avr128db48-hello-world-over-usart-mplab-mcc

Repository files navigation

MCHP

AVR128DB48 USART "Hello World!" Code Example

This example shows how to configure the Universal Synchronous and Asynchronous serial Receiver and Transmitter (USART) on the AVR128DB48 Curiosity Nano to print Hello World in the Data Visualizer using driver in MPLAB Code Configurator (MCC).

AVR128DB48 Illustration image

Related Documentation

Software Used

Hardware Used

Setup

MCC with the Melody library was used to implement this example as shown in the following section.

Hardware User Guide

To be able to configure the USART for printing, we would read the Hardware User Guide - Chapter 5 with the pinout.

Hardware User Guide

The hardware user guide shows that USART3 is connected to Virtual Serial Port (CDC) that acts as a general purpose bridge between the host PC and target device. This means we will be selecting USART3 for this example.

USART Configuration

Open up MCC by clicking the blue MCC button

Start MCC

In the Device Resources scroll down to Drivers, select UART and choose USART3 in the list.

Add USART

Select USART3 in the image in the middle, then click on the button for printf support. This will make it possible to use the printf statement in C and get the output to the Data Visualizer.

  • Note that the baud rate is here set to 9600.

Configure USART

Generating project

  1. Right click on Generate button & click Force update on all.
  2. Left Click Generate button.

The files have now been generated and the only thing you would have to update now is to add the printf statement in main.c.

  • The printf has been added already by convenience.

The main file shows two different approaches to write over USART.

The first approach handles everything automaticly by doing all the necessary checks before sending the data. The only thing needed is to make sure to configure for printing on the USART.

The second approach checks the status register if the DREIF flag is set, which signals that the TXDATA register is empty and ready for new data. The nice thing about the second approach is having more control, when it is needed.

#define STRING_END '\0'

int main(void)
{
    SYSTEM_Initialize();

    while(1)
    {
        /* Configured USART3 for printing, so this is one way of 
         * writing text over USART. 
         */
        printf("Hello ");
        
        /* Another way is to use the USART3_Write function directly
         * Can also be used to send uint8_t values directly */
        char world[] = "World \r\n";
        for(uint8_t i = 0; world[i] != STRING_END; i++){
            /* Checks if USART3 is ready to send data */
            while(!USART3_IsTxReady());
            USART3_Write(world[i]); 
        }
        
    }    
}

Data Visualizer

Makre sure to flash the device. Flashing the device is done using the play-button Program Device

To see the output from the device, we would like to use the Data Visualizer.
The Data Visualizer needs to be installed from Tools -> plugins. Adding Data Visualizer Plugin

Start the Data Visualizer by pressing the green Data Visualizer button at the top.

Start Data Visualizer

  • Fill out baud rate of 9600 and choose the correct COM-port on the right side.

Configure Data Visualizer

Operation

After having flashed the application to the AVR128DB48 Curiosity Nano, you should be able to see continous printing of hello world using the Data Visualizer.

Scrolling hello world

Summary

The example has shown how MCC can be used to easily configure the USART of the AVR DB device and how to get the output to the Data Visualzier.

About

This example uses the MCC Melody Library to show how to configure the USART on the AVR128DB48 CNANO to print 'Hello World' in the MPLAB Data Visualizer. This example can be used with MPLABX or MPLAB XPRESS IDE.

Topics

Resources

License

Stars

Watchers

Forks

Packages