Getting Started with USB on SAM MCUs Using MPLAB® Harmony v3: Step 2
Configure TIME System Service, I2C, USB, and ADC
Configure TIME System Service
Switch to the MHC window and look for the TIME System Service module. You can add this by double-clicking the module name under Available Components > Harmony > System Services > TIME.

Figure 1: Add TIME System Service Component
Accept the Core module auto-activation prompt by clicking Yes. Since we will not use FreeRTOS for our application, defer enabling this component for now. Once you are done, the module should be visible in the Project Graph pane.

Figure 2: Accept Core module auto-activation

Figure 3: Defer FreeRTOS auto-activation

Figure 4: Project Graph after adding TIME System Service
Add the TC0 Peripheral Library as the timekeeper for the TIME System Service, which will set itself up automatically once this dependency is added. No further configuration is required for our use case of generating a periodic interrupt every second. You can add this by right-clicking on the dependency icon on the module.

Figure 5: Add TC0 Peripheral Library

Figure 6: Project Graph with TIME System Service successfully configured.
Configure I²C Driver
Add the I²C Driver module. You can add this by double-clicking the module name under Available Components > Harmony > Drivers > I2C.

Figure 7: Add I²C Driver Component

Figure 8: Project Graph after adding I²C Driver
Add the TWIHS0 Peripheral Library to satisfy the I²C Driver's direct dependency.

Figure 9: Add TWIHS0 Peripheral Library

Figure 10: Project Graph after adding Peripheral Library
Verify the TWIHS0 clock settings by clicking on the module in the Project Graph. It should be set to 400 kHz.

Figure 11: Verify I²C clock settings
Add an additional client to the existing I²C Driver Instance 0 by clicking on it in the Project Graph. Set the number of clients to 2 (one for the temperature sensor, another for the EEPROM).

Figure 12: Add Client
Configure USB Device Stack Middleware
Add the USB CDC Function Driver module. You can add this by double-clicking the module name under Available Components > Libraries > USB > Device Stack > CDC Function Driver.

Figure 13: Add CDC Function Driver Component
Allow the auto-activation of USB Device Layer and USB High Speed Driver. These are required by the CDC Function Driver.

Figure 14: Allow the auto-activation of USB Device Layer

Figure 15: Allow the auto-activation of USB High Speed Driver

Figure 16: Project Graph after adding USB Middleware
Configure the USB High Speed Driver module by clicking it in the Project Graph. Since the E70 Xplained Evaluation Kit is bus-powered, we can uncheck the VBUS sense option.

Figure 17: Uncheck Enable VBUS Sense
Configure the USB Device Layer module by clicking on it in the Project Graph. Under Product ID Selection, select cdc_com_port_single_demo from the list.

Figure 18: Select USB Product ID
This application uses a single USB CDC Instance. Click on Instance 0 under the CDC Function Driver module in the Project Graph to view its parameters. No further configuration is required.

Figure 19: Verify CDC Instance 0 Parameters
Configure ADC Peripheral Library
Add the AFEC1 Peripheral Library module. You can add this by double clicking the module name under Available Components > Peripherals > AFEC > AFEC1.

Figure 20: Add AFEC1 Peripheral Library

Figure 21: Project Graph after adding AFEC1 Peripheral Library
Configure the AFEC1 Peripheral Library module by clicking on it in the Project Graph.
Under AFEC1 > ADC Configuration, set the Prescaler spinbox to 24 and the Conversion Mode selection to Software Trigger. The TEMT6000 Ambient Light Sensor is connected to the pin PC31, which is connected internally to AFEC1 Channel 6. Enable channel 6 using the checkbox as shown in Figure 22 under AFEC1 > Channel Configuration > Channel 6 > Enable Channel 6.

Figure 22: Configure AFEC1 Peripheral Library