This example demonstrates how the Vendor class on the AVR® DU microcontroller (MCU), paired with the AVR64DU32 Curiosity Nano Board, enables data transfer to and from a PC through interrupt, bulk, and isochronous transfers.
- MPLAB® X IDE 6.20 or newer
- MPLAB® XC8 Compiler 2.46 or newer
- MPLAB® Code Configurator (MCC) 5.5.0 or newer
The AVR DU Curiosity Nano development board has two USB-C ports
- The Debugger port programs the device with the code example
- After programming, the cable connected to the Debugger may be disconnected, but it will not affect the example if it remains
- The Target port must be connected to the PC in order to transfer data between the decive and the PC
This section shows how the example is set up using MPLAB® Code Configurator (MCC).
Set the class configuration to Vendor, so that the AVR DU will use the USB vendor protocol to communicate with the PC.
The Device Descriptors can be left as default.
For this example, Interface 0 with Alternates 0-4 is required, click "Add Interface" to add them. Alternate 0 will remain as it is.
We must set up separate endpoints for the interrupt, bulk, and isochronous transfers. To configure the endpoints, click "Add Endpoint" and select the correct configurations corresponding to each Alternate, 1 to 4.
By default, the target voltage on the AVR64DU32 Curiosity Nano is 3.3V and VUSB is connected to 3.3V using the provided jumper. However, if 5V operation is preferred, the jumper must be removed and the internal USB voltage regulator must be enabled.
This example is configured to run on 24 MHz under System Firmware -> CLKCTRL. The minimum oscillator frequency available for USB on the AVR DU is 12 MHz.
To ensure that the USB peripheral only tries to attach to the bus when the Curiosity Nano is connected to the PC, the Analog Comparator will periodically check if the voltage is within the acceptable range for VBUS.
The Voltage Reference is set to 2.048V.
The Analog Comparator must be enabled by toggling Enable under Hardware Settings. To measure the correct values, the positive input must be connected to AINP4, while the negative input is set to the DAC Reference. The DACREF register must be set to a value that can detect the correct voltage level at a minimum of 0.4V. The reference voltage 0.48V (DACREF = 60) used in this project is a little higher to ensure a stable connection. Refer to the AVR64DU32 Curiosity Nano User Guide to find the values for the voltage divider on Pin PC3.
The Periodic Interrupt Timer (PIT) is enabled for this example, and the period selection is set to RTC Clock Cycles 1024. This value must be changed according to the clock source selection. The PIT's Interrupt Flag is also enabled to allow for an interrupt routine.
Global interrupts must be enabled for the RTC and the USB communication to work.
One pin is used for this example: VBUS on PC3 set as input with "Digital Input Buffer disabled". This can be verified under System Firmware -> Pins.
This example can be tested by following these steps:
- Generate the MCC code and replace the generated main.c file with the given main.c from the source code
- Upload the c-code by connecting the Debugger plug on the Curiosity Nano Board (cnano) to the PC
- Connect the PC to the Target plug on the cnano and install the libusbK driver as shown in Driver Installation
- Run the python script
vendor_endpoints.py
from the given python_test code and see the data transfer
A USB driver is required to enumerate vendor devices. The LibusbK driver is recommended to handle isochronous transfers, it can be downloaded from here: https://zadig.akeo.ie/ (choose libusbK after downloading). Make sure to select the correct device from the drop-down menu, with VID = 0X04D8 and PID = 0X0B0A. If the device does not show up, select List all devices->Options.
This example has shown how the USB Vencor class can be used on an AVR DU to transfer data to and from a PC, using interrupt, bulk and isocronous transfer.