Page 1 of 1

A simple example

Posted: Mon May 03, 2010 3:05 pm
by wireframewolf
Here's what I am looking for: The simplest possible firmware that could be burned onto an atmega168 with a 16mhz, and still be recognized as a USB device when plugged into a computer. Preferably in the form of a makefile, a main.c, and the usbconfig.h file.

I've been trying for a while now, unsuccessfully, to get V-USB working. But when I think I have it all straight, neither my PC nor my Mac recognize it as a USB device (Windows gives me a "device has malfunctioned error).

It could be anything: Code, Configuration, or hardware... but I have no way to debug any of that except to flash some leds when I reach a certain part of my code : / For all I know, one of my components could be bad. If someone could provide the simplest example of a USB device with a 16mhz crystal that doesn't require anything but the base circuitry for the chip and USB, I could focus on the checking the hardware, confident that the firmware end should work.

Re: A simple example

Posted: Mon May 03, 2010 11:08 pm
by ulao
Well I know its not on the 168 chip but this should work on it.

http://forums.obdev.at/viewtopic.php?f=8&t=3931

Re: A simple example

Posted: Tue May 04, 2010 4:21 am
by wireframewolf
Yo know, I saw that example, but at the bottom he says there's an error with it. Now that I'm looking at it again, even that error would appear to prove that the USB initializes.

But I'm a little confused at one thing... why does he calibrate the internal oscillator from 16.5 down to 8.25? If I'm using a 16mhz crystal, do I have to do some funky timing thing to make it work that isn't included in that simple example?

Re: A simple example

Posted: Tue May 04, 2010 7:47 pm
by ulao
The latest version of v-usb supports 16mhz, all you should have to do is set the freq in your make.

Re: A simple example

Posted: Tue May 04, 2010 11:35 pm
by maxi
I am wondering about your hardware setup, please tell us more about this. For example are you using the zener diode method, I would assume this as the mega's wont do that fcpu at under 4.5V. IME all enumeration errors with the stock examples have been down to either incorrect fuse settings or disfunctional electronics.

Re: A simple example

Posted: Wed May 05, 2010 1:45 pm
by wireframewolf
My breadboard setup is almost identical (barring possible mistakes made) to the metaboard here: http://metalab.at/wiki/Metaboard. The only difference is I left out the 7805 and related components since they are only needed if you play to have another power source besides USB.

Re: A simple example

Posted: Fri May 07, 2010 12:10 pm
by PHermansson
wireframewolf wrote:Yo know, I saw that example, but at the bottom he says there's an error with it. Now that I'm looking at it again, even that error would appear to prove that the USB initializes.

But I'm a little confused at one thing... why does he calibrate the internal oscillator from 16.5 down to 8.25? If I'm using a 16mhz crystal, do I have to do some funky timing thing to make it work that isn't included in that simple example?


Yes there's an error message, but as the device shows up with lsusb I'm sure it's working as it shall. I have another project (http://www.patrikhermansson.se/?q=node/419), which doesn't add much code but works lika a charm.

Re: A simple example

Posted: Sat May 08, 2010 7:20 am
by wireframewolf
Well I finally got it working. Rebuilt my circuit and used the HID-Mouse example that comes with V-USB, and it worked for some reason. Now my problem is when I try to turn the example from a mouse to a keyboard, it shows up under keyboard devices in Windows, but tells me 'this device cannot start'. However, maybe that issue is for another thread.