Sunday, June 28, 2009

USB Communication...

The USB interface is heaven for the users... mostly plug and play... or simply install the driver and everything would be working from there on... After short journey into USB, I realized it was a far jump from the RS232 I'm used to.

My learning points:

1. USB devices must have some intelligence built in. When you connect a device to a serial port, windows does not do anything UNTIL you tell it do so. Remember the old days when you connect a serial modem? You have to tell windows you have connected a serial modem and then install the necessary driver and then you can start using it by telling windows the comm port, baud rate, etc.

2. With USB, the moment you plug it that device, windows knows that a USB device has been connected. It will automatically try to identify the device and 'configure' it for use. If it fails to find a suitable driver or if it fail to properly communicate with the device, then it will complain... asking you for the driver or simply state that the USB device fails to be recognized.

3. When windows detect a USB device connection (pull up resistor on the data line)... it will query the device for its' class (mass storage, HID, etc). If the driver for the class is already available to windows then it will just install the driver and the device is ready for use...

4. SO, if you want you PIC to talk to the PC via USB... several key things need to be understood and programmed for...
** Your PIC must comply to the USB-bus strict timing requirement... for full speed USB, the timing is based on 48MHz clock... the USB portion of your PIC must operate at that speed, the main controller can operate at lower speed...
** Your PIC must response to PC initial queries (also called USB enumeration) to exhange various information in order for windows to recognise the device and use it...
** Your PIC USB portion must have what's called VendorID and ProductID in order for windows to manage USB communication destined for your device...

I was ready to give up and revert back to my convenient RS-232 interface (via USB to serial converter) but decided to dwell into USB for learning sake. To avoid having to write my own device driver, I decided to use the HID (Human Interface Device) class. Windows (and MacOS) already have driver for HID class so windows will detect the device, install the driver and I'm ready to go. Sound simple eh... wait for the next installment of blog... :-)

If up to this stage, you still have braincells to waste... go on to these sites for more indepth info on USB...
USB at BeyondLogic.com
Or something from Atmel
Or something else here...

4 comments:

Unknown said...

If you are thinking about tagging your pet to have his ID recorded, his medical status in him, or simply to open his door flap, you should right away get in touch with your vet. Microchip Direct is a big provider of microchips for the security of your pet.
microchip direct

Unknown said...

A microchip cat flap is a classical cat flap that is opereated by a microchip carried by your cat. The cat flap has a digital code and only your cat has the matching code. Even if your neighbour cat has one as well, it will not enter your home.
microchip cat flap

Anonymous said...
This comment has been removed by the author.
Anonymous said...

Microchip reader is paired with microchip needle to produce dynamic outcomes at user-end.

happy-shop.co.uk

happy-shop