USB Options

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

So as a newcomer to AVR (moving over from Arduino), I'm finding the most horrendously confusing hurdle yet.. is understanding the various options for adding USB functionality to my project.

Originally I was looking at a small project on something like ATTiny45 / 84.
I just need to pass a few bytes back and forth between AVR & PC every minute or so.

SO far the main options I have registered from Google, are:
'V-usb'; FTDI adaptor; AT90USB... ; ATmegaxUx

I still only have vague and clumsy understandings of these options, as follows...

My first exploration was into v_usb, and I'm finding that quite a struggle getting into the depths of 'C' makefiles, & libraries.
It seems a lot of effort just to send a few bytes to/from avr/pc
I am unsure, but I understand that even if I get the darn thing to work... it behaves 'awkwardly' with a virtual COM port assgined to a specific physical USB port, rather than the seemless behaviour of a 'production' device?

FTDI 'appears' simpler, but more costly.
It's also bulkier, so making a tight compact USB 'pen' becomes less realistic ?

I am yet to explore the AT90USB option ...
Yet I understand that this would create more of a 'proper' USB PnP COM connections similar to a 'professional' device ?
Inofrmation on this I'm finding harder to come across.

As a newbie to this area, I'm finding several evenings/days dissapear just to get a half realistic idea of each option.
One article will boast the virtues and simplicity of 1 route, and the next article completley contradicts.
And tbh, most use terminnlogy that takes me another hour to understand !

Does anyone know of an 'all-in-one' guide to USB-AVR options ?
What they each involve with regards to hardware, expertise/disciplins required to impliment etc etc ??

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

Quote:

SO far the main options I have registered from Google, are:
'V-usb'; FTDI adaptor; AT90USB... ; ATmegaxUx

1) v-usb
this is a software only solution that runs on any AVR and uses two IO lines to implement the USB D+/D- signals. It is the cheapest/simplest solution but also the most limited (CPU spends a lot of its time just processing USB) but it could well work for what you want

2) ftdi
(also pl2303 and CP2202). These are chips you lay down next to the AVR and that connect to its UART pins on one side and provide a standard SB (virtual COM port) connection in the PC direction. It's a complete potted solution. However they are all QFP packaged solutions so you'll need to be making PCBs and be able to do SMD soldering. An alternative is to buy a cable that has a FT232/PL2303/CP2202 in it already. Many are sold for about $1.50 on ebay as USB-RS232. At the AVR end you then place a MAX232 to convert the AVR TX/RX to RS232 levels/signalling. Or you can buy USB-TTL cables (also $1.50 ebay) that remove the need for the MAX232 at the VR end (because they don't contain one either). I would say this is the very simplest solution of all.

3) at90usb
These are "mega" AVR chips that Atmel have put USB electronics into so you can make a direct connection from AVR to PC. What's moer you aren't tied to just virtual COM port (also known as CDC-ACM) as the electronics and your software can pretend to be any kind of USB device (HID - ie keyboard/mouse/joystick, MSD-memory strick, printer, etc, etc). For software you would use LUFA from Dean Camera which is the best (only as well!) library for at90usb chips. AT90USb can run at either 3.3 or 5V

4) X-U
Recently Atmel has been fitting out most of the Xmegas with a USB variant (and fixing some silicon bugs at the same time), The situation is similar to at90usb execpt that there are two software stacks you can use: LUFA or ASF and the chips are limited to 3.3 only operation.

Bottom line: just buy this:

http://www.ebay.co.uk/itm/USB-To...

Job done.

(I've typed a variant of this answer a few times - think I might consider writing a tutorial article about it with a bit more depth on each of the options...)

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

You have to decide what kind of device to enumerate - network interface, com port, keyboard, etc. The keyboard is simple and can input comma-separated data directly into a text editor or spreadsheet and accept a few commands back (caps lock, led on). But you can't be using another keyboard in another window at the the same time.

V-USB is worth exploring more. See
http://vusb.wikidot.com/usb-devi...

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

I think I've just found a new best friend!

As for writing a tutorial, all I can say is that I have learnt some amazing stuff over the years via Google ... and I think this USB topic is 'the' one that's most made me feel like a confused 3 year old.

I'm off to dig into your suggestions ... will try to come back and let people know how I get on !!

THANK YOU !

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

Cliff, unless you've got an inside track at the Skunkworks department at Silicon Labs :wink:, I think you mean CP2102, not CP2202. As for the tutorial, I'm surprised that you haven't written a brief tutorial on this long ago, given how often this has come up just in the time I've been on the forum. As I mentioned in the URL below, I think your summary there was excellent and the one you give in this thread is even better (more detailed). Please put it in a tutorial (even as-is, to be potentially "fleshed out" later) and we can all just point new users to that.

esby_2013, welcome to the forum!. In case the product at Cliff's suggested eBay URL isn't to your liking, you may want to check out this thread ("Controlling Embedded Device from PC") where Cliff and I have a(nother) friendly argument about the merits of the expensive-but-handy FTDI 'TTL-232R-3V3' cable. I use one quite frequently for easily debugging AVR firmware over UART (and, as mentioned in that thread, for other purposes).

esby_2013 wrote:
I'm off to dig into your suggestions ... will try to come back and let people know how I get on !!
Please do keep us posted. I'd be interested to hear what works for your situation.

Regards,
Bill

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

Well I've already ordered the cable that Clawson suggested, simply because on the surface at least, it seems the simplest way to get my main project moving again after a long time stalled on the USB issue, (dithering between this way and that has left me unashamedly itching to get moving), and realizing that I just need to step back and re-start 'simple'.

AVR USB is a topic 100 times bigger than I naiively first thought it to be.

It might be a few days before work begins, but I did find an article aimed at 'first steps' of implementing this approach, angled towards people like me who are migrating from Arduino: http://www.evilmadscientist.com/...

However, I still aim to explore some of the other options for longer term solutions.

Out of interest, from a newbie perspective...
> Looking at LUFA (view to exploring at90usb), it is reported that getting it to work with AtmelStudio 6 is a bit of a nightmare, whereas with AS6.1, is a 'relative' breeze. Now I already bought a pololu AVR programmer, which works with AS6, but not AS6.1 !

Not sure if any of you can confirm that or not ... but I post in case it forewarns anyone else poised to take this route.
I think Farnel offer the Atmel MKII at around £25 GBP which is about the cheapest I've seen.

(anyone want to buy a Pololu AVR Programmer from me ?)

Will keep you posted ;)

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

Does it really matter whether a programmer can be driven from within AS6? Tons of people use AS6 to build .hex files then program into an AVR externally using avrdude+USBAsp or similar. Quite workable.

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

Just FYI for anyone else attacking this route :
NOTE: Windows 8 is NOT supported in PL-2303HXA and PL-2303X EOL chip versions.

http://www.prolific.com.tw/US/Sh...

... timeout to consider next step ;)

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

look for ft232 or cp2102 based converters.

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

So, I got hold of an FTDI breakout board (uses a ft232 chip).. and within minutes I am up and running with my communications over USB Serial on my AT2313.
Fantastic.

Cost me £10, which is fine as a 'development' expense, and I'll have other uses for it too.

Wouldn't want to add £10 to the cost of every USB device I make going forward though, especially when you look at the cost relative to other parts typicaly involved.
I could I guess get the chip by itself, but ...

..I'd also like to achieve true Plug-n-play for my finished devices, hence I'll continue to look into the AT90USB/X-U route.
Moving to these SMD devices will also be nice for a smaller sized end product.
I suspect more learning curves ahead with all this !

Main thing for me, is that I can now continue development of my application with very little fuss.
I also have a clearer understanding of how to take this forward to a true PnP USB device, of reasonable small form factor, by utilizing either AT90USB or X-U.

Job done, I think !?

Many Thanks for all of your wonderful advice and help ... I really so appreciate the time and effort :)

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

Quote:
I could I guess get the chip by itself, but ...

Been there, done that. Works well.

This project is only two chips, a Mega168 and a FTDI USB to Serial bridge. The photo shows the V. 1 prototype talking to an Xprotolab module and a PC.

The FTDI FT232RL chip is easy to use. I was annoyed at its price, as I thought even the chip alone was rather expensive. But, it also provides a 3V, 50 mA power source which in this case can completely power the remainder of the circuit.

This eliminates an additional USB to 3 V power supply circuit, and thus decreases the parts count, design time, etc.

Since my projects are all small quantity volumes the hardware cost is not generally a factor. If you are doing your project in C then you might want to consider the Xmegas with their internal USB module, or using a separate micro running V-USB, (and an external USB power supply), but both of these increase the complexity of the project compared to using the FDTI chip which just makes USB comm's trivial.

JC

Attachment(s): 

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

Thanks DocJC, that's good to see, and the thought processes around available options especially.

I think I've hit another 'challlenge' though already.

I also wanted to use SPI to connect with an NRF24L01.
Now reading the data sheet (too late!), I see that on ATTiny's, the SPI runs off UART.
So I understand I cannot talk to FTDI and SPI ??

Code-wise, I can see I could switch from 1 to the other, but the Tx/Rx pins would be physically shared.

Have I understood this correclty ?

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

Spi is easy to implement by 'bit bashing'ie write code to toggle the bits in the correct sequence. Then you can use just about any port pin.

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

I have little experience with the Tiny's, but I believe you are correct in your evaluation of the pin usage.

As Kartman just suggested, one can bit-bang an SPI interface. It will be slower than a hardware module, but fully functional.

Another option, of course, is to switch to a Mega168 or similar. The Mega's have more pins, more modules, and one hence has an easier time developing the software.

If, when everything is working, one decides it will be a high quantity production item, then one can look at the code size, hardware modules used, and options for switching to a smaller, (and less expensive), micro.

For low volume projects the small difference in cost is easily outweighed by the flexibility and ease of using the larger micro and then getting on with using it, or developing the next project.

JC

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

Bit-banging is fine. I did a large 120-LED clock using a 2313, bit-banging the connection out to two MAX7219 drivers. That handled the clock and all LEDs with visible resolution down to 1/12 second LEDs. No problem.

Dean 94TT
"Life is just one damn thing after another" Elbert Hubbard (1856 - 1915)

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

Quote:
Bottom line: just buy this:

www. ebay. co.uk/itm/USB-To-RS232- ... 2a1ab67943

Job done.

I've come to this party late, but I'd like to thank you, Cliff, for this pointer (actual URL in text above). I ordered 5 of these at about $1.65 each with a $2 shipping fee for the lot from Hong Kong. They shipped within 8 hours. I don't really need 5, but hey, I had to amortize that shipping charge over several units. :) I've previously had great luck ordering from Hong Kong.

I've used the TI Launchpad in the past - I think they're $5.60 (IIRC) and have a circuit board which can be physically split into an independent USB side and the rest of it. That, and Smiley/Jesper's USB thingie were my previous USB-TTL toys, but these will be much better and far cheaper and easier.

Yes, I should learn LUFA. Old dog.

edit: They arrived on May 7th, 12 days later. Pretty amazing.

Chuck Baird

"I wish I were dumber so I could be more certain about my opinions. It looks fun." -- Scott Adams

http://www.cbaird.org

Last Edited: Tue. May 7, 2013 - 11:35 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I guess if this is going to be the USB Info Thread then it would be worthwhile mentioning that a decent reference for USB info is:

USB Complete, Fourth Edition
by Jan Axelson

while her USB Info web site can be found Here .

JC

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

Agreed. All of her books are very good, but that one stands out.

Chuck Baird

"I wish I were dumber so I could be more certain about my opinions. It looks fun." -- Scott Adams

http://www.cbaird.org

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

Quote:

but I'd like to thank you, Cliff, for this pointer

It took mine almost 2 weeks to arrive after I got the "shipped" notice but I guess that's what they call a "slow boat from China"?

One word of warning. These are based on the Prolific PL2303. While personally I've never had problems with these and their driver (perhaps because I use Linux ;-)) I have read many threads of people having problems with Windows drivers and most recently with the fact that Prolific simply aren't making drivers for them in Windows 8. So pick your operating system wisely!

(I have the best of both worlds - Linux as my host OS to which the beasty actually connects and then Windows XP in VirtualBox which gets a VBox "filtered" view of the device).