A simple example

General discussions about V-USB, our firmware-only implementation of a low speed USB device on Atmel's AVR microcontrollers
Post Reply
wireframewolf
Posts: 6
Joined: Tue Apr 27, 2010 11:42 pm

A simple example

Post by wireframewolf » Mon May 03, 2010 3:05 pm

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.

ulao
Rank 4
Rank 4
Posts: 481
Joined: Mon Aug 25, 2008 8:45 pm

Re: A simple example

Post by ulao » Mon May 03, 2010 11:08 pm

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

wireframewolf
Posts: 6
Joined: Tue Apr 27, 2010 11:42 pm

Re: A simple example

Post by wireframewolf » Tue May 04, 2010 4:21 am

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?

ulao
Rank 4
Rank 4
Posts: 481
Joined: Mon Aug 25, 2008 8:45 pm

Re: A simple example

Post by ulao » Tue May 04, 2010 7:47 pm

The latest version of v-usb supports 16mhz, all you should have to do is set the freq in your make.

maxi
Rank 3
Rank 3
Posts: 122
Joined: Fri Jul 24, 2009 6:13 pm

Re: A simple example

Post by maxi » Tue May 04, 2010 11:35 pm

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.

wireframewolf
Posts: 6
Joined: Tue Apr 27, 2010 11:42 pm

Re: A simple example

Post by wireframewolf » Wed May 05, 2010 1:45 pm

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.

PHermansson
Posts: 10
Joined: Tue Oct 07, 2008 11:44 am

Re: A simple example

Post by PHermansson » Fri May 07, 2010 12:10 pm

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.

wireframewolf
Posts: 6
Joined: Tue Apr 27, 2010 11:42 pm

Re: A simple example

Post by wireframewolf » Sat May 08, 2010 7:20 am

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.

Post Reply