[TUT] [HARD] [SOFT] [C] USB tutorial with V-USB & ATtiny

Last post
19 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi all!

I recently managed to implement an USB powered device using ATtiny2313 and V-USB library. As a beginner, I needed several evenings of research prior to the project so I decided to compile a tutorial covering the steps for building a simple USB device:

http://codeandlife.com/2012/01/22/avr-attiny-usb-tutorial-part-1/

This first part covers the basics of getting USB connector to breadboard and using it to power a simple LED circuit. It can be extended to any USB-powered project.

http://codeandlife.com/2012/01/25/avr-attiny-usb-tutorial-part-2/

The second part goes through rest of the test breadboard setup, including wiring the ATtiny2313 to the USB with proper pullups for a low-speed device on D+ and D-, as well as enabling the 12 MHz crystal.

http://codeandlife.com/2012/01/29/avr-attiny-usb-tutorial-part-3/

The third part is the longest of the three and contains both device side and host side code, as well as a chapter on creating Windows drivers for V-USB devices using libusb-win32's INF-wizard.

http://codeandlife.com/2012/02/04/avr-attiny-usb-tutorial-part-4/

Fourth part details how to send data from and to your device. It also wraps up the tutorial series and contains the source code and schematic as well as needed libraries and drivers for Windows in one neat package.

I'm using quite a lot of pictures so I put the tutorial to my blog, but would appreciate any comments, feedback and discussion here. The spark for my electronics hobby started here in AVRfreaks tutorial section, so I felt it was time to contribute something.

Update: Two new parts have been added, first for making a HID mouse, and second which goes through adapting the tutorial for use with zener diodes to run the AVR at 5 volts, as well as switching to ATtiny85 (45 and 25 probably work just as well) and using internal oscillator instead of external crystal!

http://codeandlife.com/2012/02/11/v-usb-tutorial-continued-hid-mouse/
http://codeandlife.com/2012/02/22/v-usb-with-attiny45-attiny85-without-a-crystal/

Update2: Due to some requests, I've continued the tutorial with treatment of HID keyboards, too:

http://codeandlife.com/2012/06/18/usb-hid-keyboard-with-v-usb/

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

Second part is now also up. I felt that the breadboard connections, reprogramming the fuse bits for 12 MHz crystal & testing was suitably long already so I'll cover the V-USB in part 3. Stay tuned!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Seems to be quite some nice tutorials there, will surely check back for part 3! :)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'm glad someone is doing V-USB tutorial. I was too lazy to figure it out by my self.

Waiting for the critical 3rd part : )

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Part 3 is now finally up, thanks for all the comments so far. This is the longest and most detailed part, I may yet do some housekeeping work on the article, add one zip file for all the source code and insert proper copyright and license notices in the beginning of the files.

There will be part 4 with some additional techniques shortly, at least sending and receiving short buffers of data will be covered then.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Will go through it when I hit the bed tonight on my TV-pc, will be fun to read it. Good job jokkebk!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Fourth and so far final part is now released. It will explain transferring data from a to device in more detail, and I zipped everything up in one package so you don't have to cut-and-paste so much if you don't want to.

Planning to do a simple 7 segment multiplexing tutorial and a brief bit on driving LCDs directly with MCU when I get some free time. :)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Wow, I made it to Hack a Day with the tutorial!

To celebrate this, I made a new post outlining how to turn the tutorial project into a HID mouse. The current implementation just randomly moves the cursor, but with a few buttons a simple directional pad or joystick would be really easy to implement.

http://codeandlife.com/2012/02/11/v-usb-tutorial-continued-hid-mouse/

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I've received several questions regarding USB HID keyboards, and decided to continue the tutorial with a new post on that subject.

This should enable all kinds of data logger and interaction projects, especially since the type of keyboard I cover can also receive caps/scroll/num lock state changes from PC and react to them. :)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Awesome effort..!! However I had a question. Can this method be employed for making a USB programmer for Atmega 8,16,32,64 or 128?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
Can this method be employed for making a USB programmer for Atmega 8,16,32,64 or 128?

Yes: http://dicks.home.xs4all.nl/avr/usbtiny/

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi, Joonas...

Based on trying to assist someone in this 'V-USB Command line client' thread, I was looking at your tutorial and realized that, unless I'm missing something, you're attempting to drive an ATTiny2313 MCU at 12 MHz but only on 3.3V. If all of my datasheets are correct, then that is beyond the specifications of that MCU! If you want to run it (within spec) over 10 MHz, you must use 4.5V - 5.5V.

I reviewed all of the comments on that page but I see nobody ever mentioning that MCU spec violation.

I do see where you (wisely) modified that design for your ATTiny85 V-USB tutorial to power the MCU from +5V, but the ATTiny2313 tutorial is still using 3.3V.

Am I missing something?

Regards,
Bill

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi Bill,

You are correct, when I did the tutorial I was not aware of the frequency limitation. In practice, I've never had any problems "undervolting" the ATtiny2313 @12MHz. But it is possible that some problems people have had might be connected to this.

I'll add a note in the tutorial and advice people to try out the zener diode configuration if they continue to have problems. If I have the time, I might even do an additional post with new power supply and diagrams.

Thanks for the feedback!

Joonas

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ya thank you, i learned most of things of usb from this tutorial then i want to learn ethernet programming if guys know about ethernet communication, you can teach to lot of peoples also give details for beginners.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

great job!

"One's value is inherent; money is not inherent"

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

meteor wrote:
Hi, Joonas...

Based on trying to assist someone in this 'V-USB Command line client' thread, I was looking at your tutorial and realized that, unless I'm missing something, you're attempting to drive an ATTiny2313 MCU at 12 MHz but only on 3.3V. If all of my datasheets are correct, then that is beyond the specifications of that MCU! If you want to run it (within spec) over 10 MHz, you must use 4.5V - 5.5V.

I reviewed all of the comments on that page but I see nobody ever mentioning that MCU spec violation.

I do see where you (wisely) modified that design for your ATTiny85 V-USB tutorial to power the MCU from +5V, but the ATTiny2313 tutorial is still using 3.3V.

Am I missing something?

Regards,
Bill

Though with the ATtiny85, 12Mhz @3.3V is in spec according to Figure 22-2 of the datasheet.
It's also in spec for the 2313A/4313.

I have no special talents.  I am only passionately curious. - Albert Einstein

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ralphd wrote:
Though with the ATtiny85, 12Mhz @3.3V is in spec according to Figure 22-2 of the datasheet.
I disagree.

Figure 22-2 is simply plotting the active supply current versus MCU operating frequency. Just because Atmel happened to plot the 3.3V line out past the 12 MHz point does not (to me) imply that it's "in spec" under such conditions.

Sure, some people are operating ATTiny85 MCUs successfully under those conditions, but I would not call that "in spec". To me, and, I suspect, most others, the "Speed Grade" callout on the very 1st page of the datasheet is the relevant guideline and it clearly says:

ATTiny25/45/85 datasheet wrote:
0 - 20 MHz @ 4.5 - 5.5V

ralphd wrote:
It's also in spec for the 2313A/4313.
I see no evidence for that claim in my datasheet ("Rev. 8246BS-AVR-09/11") for the ATTiny2313A/4313 variants. In fact, the "Speed Grades" callout on page 1 is, for the speeds in question, identical to the quote above.

In summary: People are free to operate their MCUs (and PC CPUs/GPUs, for that matter) at whatever speed/voltage combination they're comfortable with. But I would not call combinations that violate the "Speed Grade" callout as being "in spec".

Regards,
Bill

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

My (fairly recent) copy of the t25/45/85 data has this.

One would need to interpolate but it looks like 12MHz/3.3V appears to be "safe"?

Attachment(s): 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Very interesting! Thanks for pointing that out, Cliff. It was in my older ("2586K-AVR-01/08") ATTiny25/45/85 datasheet as well, but I somehow missed it. I had even searched for "speed grade" before posting but upon further analysis, I clearly only had done that in the 2313A/4313 datasheet, where the same chart/info is (maddeningly!) under a different sub-section label (i.e. "Maximum Speed vs. VCC" instead of "Speed Grades").

Having my eyes further opened, I will happily concede that "in spec" is rather more debatable than I previously asserted, especially since Atmel's own documentation is somewhat misleading (almost contradictory, in fact).

But, since Joonas thoughtfully updated his tutorial long ago to address my point, this is now more of an academic (and interesting) debate rather than a real concern.

Thanks again (to both of you) for the added enlightenment.

Regards,
Bill