Build your first USB project

USB Library ›› Device ››
… visits
Parent Previous Next

Start with one simple test. Get the board recognized by the computer, send a small amount of data, then add the rest of your project. This guide covers Device Library 0.20.0 and Device Configuration Tool 1.17.1.


A device is the PIC board you plug into the computer. The computer is the host. You do not need to learn the whole USB protocol to begin.

Follow this route

  1. Choose the USB type below and collect the files and hardware.
  2. Make a configuration for your exact PIC and board.
  3. Copy and compile the starting program.
  4. Connect and test it.

Choose what the computer should see

First decide what you want the computer to see when you plug in the board. This choice is called the Device class in the tool.

Device class menu offering HID, CDC ACM serial, Mass storage (virtual files), and USB browser (RNDIS).

Choose what the computer should see: an input/data device, a serial port, a small drive, or a USB network adapter.

Choose

What appears on the computer

A typical use

Application interface

HID, HID data profile

A HID device

Exchange small commands, readings and control data with a PC program

TXReport, RXReport, USB_Write() and USB_Read()

HID, keyboard/mouse/joystick/consumer profile

The corresponding input device

Buttons, keys, movement or media controls

Fill the profile's report and send it

CDC ACM serial

A serial/COM port

Use a terminal or existing serial application

Send and receive a byte stream

Mass storage

A drive with 1–8 fixed files

Present measurements, stored data or settings as files

Handle file read/write requests

USB browser, RNDIS

A USB network adapter

Display values and send commands through a browser

Publish named values and consume incoming values

Choose one type for this program. CDC creates a serial port, MSC creates a drive, and browser mode creates a network adapter. Selecting one does not also turn on the others. The tool includes the connections needed by your chosen type.


With HID data, the board uses the standard HID class, but you choose what the sent bytes mean (a vendor-defined report). For example, one byte can be a command and the following bytes can hold a reading. It suits a custom PC program that exchanges small messages with your board.


For a first communication test, choose HID data or CDC ACM serial. For a keyboard or mouse project, choose its actual profile so that the host receives the correct report format.


The USB connection runs at full speed: 12 Mbit/s. Your own data moves more slowly than this bus speed. The chosen class, the computer, packet size and your program all affect the useful transfer rate.

Start from a supplied example

The Framework folder has tested working examples for the USB use cases. Start with the one closest to your project, check its board settings, and get it working before adding your own code. PIC Templates shows the basic interrupt setup for tested devices. Find the supplied examples explains which folder to open.

Have these ready

  1. Keep USB_Device.inc with your BASIC project, or in an include directory recognized by Positron.
  2. Use the USB Device Configuration program, UsbDeviceConfigTool.exe.
  3. Identify the complete PIC part number, its package, the fitted crystal or other supported clock source, and the board's supply arrangement.
  4. Check the board's USB connector, D+/D− wiring and required regulator capacitors against that PIC's datasheet.
  5. Have a way to program the PIC, including its configuration words. The configuration tool generates source code; it does not program the chip.

Use the Device tool: open UsbDeviceConfigTool.exe. The Host and OTG programs are for different jobs and are not used in this guide.

See also

Created with the Personal Edition of HelpNDoc: Easy CHM and documentation editor