circuitcellar.com
Magazine Support   Digital Library   Products & Services   Suppliers Directory 
 
 





 

May 2004, Issue 166

USB in Embedded Design (Part 2):
HIDmaker Converts an Application


HIDmaker HOST OUTPUT

On the host side, HIDmaker creates three main files and a bevy of support files (11 files in all for this project). USBX10_M.frm is the main program module. Adding this form to a project enables the HIDagentX object, which is used for a USB interface. It is similar to using an MSComm object for a serial interface. 

The USBX10_L.cls class module library file handles the variables and functions that make direct interfacing with the HID system calls unnecessary. The OneHidVar.cls class module file represents one USB HID data item or variable with all its attributes. Additional modules are created by HIDmaker, PC_Consts.bas (a file of expected device strings) plus error checking, and context help support files.

You can create a project .EXE file for the HIDmaker-created application using Visual Basic IDE, or you can run it in Debug mode from the IDE. Photo 5 gives you a quick picture of what is going on. The application will not run if it doesn’t find a matching device enumerated on the USB bus. Assuming it does, the application pops up a window and shows that it has found a device. You can use the Send All Reports and Read All Reports buttons to test the communication to and from the attached device. The transferred data, which is hard coded into both applications (the host PC and the device microcontroller), originates from the HIDmaker define data steps.

(Click here to enlarge)

Photo 5—HIDmaker creates device and PC applications that complement one another. Here the PC application demonstrates that it has succeeded in providing a working USB connection by allowing you to pass your defined data to and from the PC.

Unless you can see into the microcontroller, you won’t know if the correct data has arrived. However, you will see the data arriving from the device displayed in the host application program. At that point HIDmaker has proven its success. You can take these applications and integrate them with your own code. But wait, HIDmaker is still of use. 

OPTIONAL TOOLS

Remember how I said that you couldn’t see inside the micro? Well, if Microchip had its act together, they would have the USB devices available in flash memory and the ICD in-circuit debugger could be used to look at the microcontroller’s registers.

Trace Systems has added hooks within its code to allow messages to be output through a serial port on the microcontroller. (Isn’t it ironic to use a serial port to debug its replacement?) You can use this technique to log messages (including any values) at any point in the application, so you can see the values received from the application. In fact, if for some reason your device doesn’t enumerate correctly, this can provide you with feedback about the failure’s location.

Enumeration failure can be the biggest source of headaches for a designer. Although HIDmaker generates working code for you, if enumeration fails, HIDmaker offers suggestions about potential problems.

USBwatch is a terminal-style application that interprets tokens sent by the microcontroller out of the debugging serial port. Tokens are used to reduce serial traffic to a minimum. The USBwatch application expands the tokens back into real English text. Note that there are a number of indicators above the text window in Photo 6. These help determine the status of enumeration and the present endpoint in use.

(Click here to enlarge)

Photo 6—The USBwatch interpreter works in conjunction with a serial port on the microcontroller. Embedded commands allow you to see what’s happening inside the microcontroller. You determine the information reported by enabling the hooks within the HIDmaker-generated code.

From the PC side, you can investigate all USB devices using the AnyHID application, which shows all of the USB devices (except hubs and the system’s keyboard and mouse). When you choose a device, AnyHID will tell you all about it by reading the descriptor tables from the selected device (see Photo 7). Because the descriptors contain information about each data item, AnyHID is presents you with the opportunity to configure a data packet to send to the device and to receive and interpret requested data.

(Click here to enlarge)

Photo 7—AnyHID is a peephole into USB devices enumerated by your PC. You can interrogate each device and actually send and receive data to and from the device.