AN INTRODUCTIONTO USB ANDUSB PROGRAMMING ON MICROCHIP DEVICES
VOL. 1PROGRAMMING MICROCHIP PIC18 USB DEVICES
Copyright Andrew W. Eliasz and The Internet Technical Bookshop
ISBN 978-0-9935315-0-7
Published by:
The Internet Technical Bookshop awe@itbs.co.uk
www.itbs.co.uk
No representation or warranties are made with respect to the contents or use of this material, and
Although third-party applications and software packages may be referenced herein, this is done fordemonstration or explanatory purposes only and shall not constitute an endorsement of any of these software applications.
Microchip is a registered trademark of Microchip Technology Inc.
Linux is a registered trademark of Linux Torvalds.
If there are any questions regarding the proper and fair use of the material herein, please contact Andrew Eliasz at awe@itbs.co.uk.
i
INTRODUCTION
The origins of this book were via a Kickstarter project, which, it turned out was much more ambitious than I realised at the time. The amount of material that needed to be included was much greater than could be accomplished in a single volume.
covering the topic of . The PIC18 exemplar board used is the Microchip Picdem FUSB board.
will cover on PIC18, PIC24, dsPIC and PIC32 devices.
. Will cover on PIC24 and PIC32 devices.
. Will cover .
Purchasers of the First Edition of this volume will be entitled to an upgrade to the second edition at a 50% discount.ii
Introduction .............................................................................................................................................................................pii
1.0 First Steps .............................................................................................................................................................. p1
1.1 Getting to Know USB ............................................................................................................................................ p3
1.2 USB as a Networking Technology .......................................................................................................................... p3
1.3 Connecting up The Parts ....................................................................................................................................... p3
1.4 USB Cables and Connectors ................................................................................................................................ p3
1.5 USB Device Power Provision ................................................................................................................................. p4
1.6 Data Transmission ................................................................................................................................................. p5
1.7 Conserving Power by Powering Down Unused Devices ....................................................................................... p9
1.8 USB Packets and Data Transmission ................................................................................................................. p10
.................................................................p10
1.8.2 Transactions ........................................................................................................................................................ p13
1.9 USB Data Flow Types ......................................................................................................................................... p14
1.9.1 Bulk Transfers ..................................................................................................................................................... p14
1.9.2 Interrupt Transfers ............................................................................................................................................... p15
1.9.3 Isochronous Transfers ......................................................................................................................................... p15
1.9.4 Control Transfers ................................................................................................................................................. p16
1.10 The USB Protocol In Action ................................................................................................................................. p17
1.10.1 Standard Requests And Device Operation .......................................................................................................... p19
1.10.2 Get Descriptor Requests ..................................................................................................................................... p21
............................................................................................................................. p23
1.10.4 SET_CONFIGURATION Requests ..................................................................................................................... p26
1.11USB Device Classes ........................................................................................................................................... p27
2.1 Picdem FSUSB Board - Running the Microchip Example Applications ............................................................... p32
2.1.1 Getting To Grips With The MPLABX IDE (Integrated Development Environment) and the XC8 C Compiler ..... p33
2.1.2 Compiling and Trying Out The composite_hid_msd Project ............................................................................... p37
2.2 An Overview Of The Microchip USB Framework Modules .................................................................................. p45
2.2.1 app_device_hid.c - Source Code Overview ........................................................................................................ p47
2.3 The Generic Hid Simple Demo - Code Overview ................................................................................................ p50
2.4 Hid PnP Demo ..................................................................................................................................................... p54
2.5 Command Line Applications ............................................................................................................................... p60
2.5.1 Microsoft Windows - Raw HID Input .................................................................................................................... p60
2.5.2 Building An Initial Application ............................................................................................................................... p69
2.5.3 Adapting the Rawhid Teensy AVR Example For the Picdem FSUSB ................................................................. p69
2.5.4 Implementing a PC Windows HID Application
Communicating with the Picdem FSUSB ............................................................................................................ p70
iii
3.0 Introduction .......................................................................................................................................................... p71
3.1 Understanding the PIC18 USB Subsystem ......................................................................................................... p72
3.1.1 Resources and Documentation ........................................................................................................................... p72
3.2 USB - Oscillator Related Issues .......................................................................................................................... p74
3.2.2 Oscillator Settings for USB .................................................................................................................................. p76