Add ADC and USART Functionality to Application Code

Once the ADC and USART functional drivers have been added using Atmel | START, developing the application code can be started.

Todo: Add code to the application which performs ADC conversion and sends the ADC result via USART to a terminal.
  1. 1.Include functions for adding delays to the application code by adding the following line of code at the beginning of main.c.
    #include <util/delay.h>
  2. 2.Add ADC and USART functionality to the application, by adding the following piece of code in the while(1)-loop in the main function.
    
        ADC_0_start_conversion(10); //Start ADC conversion on channel 10
        while(!ADC_0_is_conversion_done()); //wait for ADC conversion is done
        USART_0_write(ADC_0_get_conversion_result()); //USART write ADC result
        while(!(USART0.STATUS & USART_TXCIF_bm)); //wait for USART TX complete
        _delay_ms(500); // delay to easier observe changes to ADC input in terminal
    Info: main.c should look similar to the code in Figure 1
    Figure 1. main.c Code
  3. 3.Go to the implementation of ADC_0_start_conversion() by
    1. 3.1.Hover over ADC_0_start_conversion().
    2. 3.2.Right-click → Goto Implementation
      Info: A menu, showing the different locations, will appear.
    3. 3.3.Jump to where the function is implemented by selecting the first option from the pop-up window.
      Info: The implementation of ADC_0_start_conversion(), which is located in adc_basic.c, should now be visible in the Atmel Studio editor window.
  4. 4.View the complete list of ADC driver functions by clicking the arrow, shown in Figure 2.
    Figure 2. ADC Driver Function List

    Info: The ADC driver functions marked with 2-5 in Figure 2 are all used by this training.
  5. 5.Go to the implementation of USART_0_write() by
    1. 5.1.Hover over USART_0_write() in the main.c file.
    2. 5.2.Right-click → Goto Implementation
      Info: A menu, showing the different locations, will appear.
    3. 5.3.Jump to where the function is implemented by selecting the first option from the pop-up window.
      Info: The implementation of USART_0_write(), which is located in usart_basic.c should now be visible in the Atmel Studio editor window, as shown in Figure 3.
      Figure 3. USART Driver Function List
      Info: USART_0_write is the only USART driver function used in this training.
Result: Adding ADC and USART functionality to the application code is completed.