V-USB and ATmega problems - Page 1
Forum section: electronics / general

author: skerdzius
author_rank: Contributor
timestamp: December 05, 2012, 07:47:46 pm
content: hi, i have some trouble doing well explained project here:http://codeandlife.com/2012/01/22/avr-attiny-usb-tutorial-part-1/. i do all steps required, but my hardware is not recognized on my laptop. i asked my tutor for help, he also couldn't find solution.i use ATmega 8 or ATtiny2313, i used all three options for 3.3V usb powering (zener diodes, voltage regulator and diodes) nothing helps. i used 12 MHz crystal and 16MHz one and yes, i changed settings in required files and makefile compile my code... can someone please give me some guidelines for this project to make it work?

author: Psi
author_rank: Super Contributor
timestamp: December 06, 2012, 12:34:43 am
content: Picture of your breadboard/circuit?Do you have a common ground between the laptop and the MCU?

author: skerdzius
author_rank: Contributor
timestamp: December 06, 2012, 07:15:26 pm
content: i do my project with this schematichttp://codeandlife.com/wp-content/uploads/2012/01/usb_schematic.png. i mostly use common ground from my laptop, but i also tried different ground while powering from other computer but still no luck

author: hotshot05
author_rank: Newbie
timestamp: December 08, 2012, 03:06:59 pm
content: Quote from: skerdzius on December 05, 2012, 07:47:46 pmDid you change thefuse bits?Since you are using an external oscillator, you will have to change the fusebits to tell the chip about the presence of the external oscillator. Otherwise it will continue running with the internal oscillator @ 1MHz.Check the makefile. There will be s section with the wordshighfuseandlowfuse. Hexadecimal values of the form 0x?? [? represents and unknown value] will follow these words. The fuse bits will have to be set with these two values.

author: skerdzius
author_rank: Contributor
timestamp: December 09, 2012, 06:26:33 pm
content: sure, i changed fuse bits. i personally think i made everything right, but my windows laptop doesn't recognize my usb device it shows 0x000 PID and VID unknown device, however i have installed libusb drivers for it. and when i turn to linux OS it even doesn't show any device connected at all.

author: miceuz
author_rank: Frequent Contributor
timestamp: December 09, 2012, 09:55:34 pm
content: aha, so the device does get enumerated! Atleast in windows.Why don't you try uploading some simple HID firmware to it? Somethig like mouse running pointers in circles, etc - v-usb page has some simple examples. At least that's how I've started using v-usb once before.One strange glitch I've encontered with v-usb is that it wasn't enumerating the device upon connection unless I reset it via reset button. The device had usbasp bootloader in it and worked as a HID mouse, so it had TWO v-usb stacks. Unfortunatelly, I never resolved this issue...

author: skerdzius
author_rank: Contributor
timestamp: December 13, 2012, 02:28:38 pm
content: i uploaded this code#include <avr/io.h>#include <avr/interrupt.h>#include <avr/wdt.h>#include "usbdrv.h"#define F_CPU 12000000L#include <util/delay.h>USB_PUBLIC uchar usbFunctionSetup(uchar data) {return 0; // do nothing for now}int main() {uchar i;wdt_enable(WDTO_1S); // enable 1s watchdog timerusbInit();usbDeviceDisconnect(); // enforce re-enumerationfor(i = 0; i<250; i++) { // wait 500 mswdt_reset(); // keep the watchdog happy_delay_ms(2);}usbDeviceConnect();sei(); // Enable interrupts after re-enumerationwhile(1) {wdt_reset(); // keep the watchdog happyusbPoll();}return 0;}to my ATmega8 or ATtiny2313 but nothing interesting happens. i'll try to make my project from scratch once again today.. hoping the best

author: free_electron
author_rank: Super Contributor
timestamp: December 13, 2012, 03:28:59 pm
content: I hope you do realise that vusb is NOT usb compliant. It is a kludge and pile of trickery that may or may not work. It does not implement a full USB engine , nor does it implement a correct USB engine. It is one of these things that may or may not work.If your USB host uses a different order of commands or slightly different timing this whole thing stops working. VUSB is an experiment in futility. Nothing more. Making something with it that works reliably is not possible. End of story.

author: skerdzius
author_rank: Contributor
timestamp: December 13, 2012, 03:53:56 pm
content: yes, i know that it is firmware-only usb driver, and ATmega8 doesn't have hardware to support usb, but i thought it must work with my laptop as this v-usb thing is widely popular among developersand i must make this in order to make my university project, or other option would be to make STM32F4 Discovery board to communicate with pc in a similar way via USB. and i thought using ATmega would be much easier than ARM programming

author: Ragorh
author_rank: Newbie
timestamp: December 13, 2012, 05:13:12 pm
content: I made a HID device with V-USB a long time ago.. And it worked:) But a bit unstable though..My first thought when I saw the breadboard-pic, was noise.. I think you can get enumeration problems because of package loss.Place a scope probe at the USB header and take a closer look!Pictures from the scope will look good in your school report;)

author: free_electron
author_rank: Super Contributor
timestamp: December 13, 2012, 07:01:35 pm
content: Quote from: skerdzius on December 13, 2012, 03:53:56 pmnot guaranteed to work with anything ... it will work with some usb controllers , not with others. its hit and miss.as for being popular.... not with developers. with idiots maybe.... you have to be mad to do this.

author: skerdzius
author_rank: Contributor
timestamp: December 13, 2012, 07:30:50 pm
content: So maybe STM32F4 with RTOS would do the trick? i am in desperate situation right now. i want to make it work badly. so i think i have to make USB transfer with ARM then. P.S. i made this schematic with atmega again, but no luck as always.

author: senso
author_rank: Frequent Contributor
timestamp: December 13, 2012, 08:28:07 pm
content: Buy a Teensy 2, it has an atmega32u4, and code to use with the Arduino IDE, putting native USB working is a matter of buying one of them and 5 lines of code..

author: free_electron
author_rank: Super Contributor
timestamp: December 13, 2012, 09:06:03 pm
content: But why do you make it so bloody difficult ? slap on an ftdi chip and off you go ! guaranteed to work right. and no mucking with USB.USB is not an easy bus to handle if you have never done it . the learning curve is steep. Having correct hardware is problem number one. VUSB is NOT the answer there. they are shoehorning a badly emulated USB rptocol on an , electrically incorrect, i/o structure. The voltage levels are wrong , the thresholds are wrong and much more. It may work with some usb host controller but not with others. Especially with the newer controllers i predict trouble. The USB standards for timing have tightened ove rthe years and now with USB3.0 it is going to be even more misery to get it to do anything.VUSB will work if you have a 1.1 compliant USB port. plug it into a 2.0 host and all bets are off. the host will most likely not be able to detect correctly that he has to switch down to 1.1 speeds.Take a cpu that does have a USB engine on board and load the LUFA stack and off you go.VUSB really is a pest that needs to die. The only reason it has for exisiting is to show off some low level programming skills of a madman. It was made becasuse there were very few small cpu's available with an on board USB hardware block. ( simply because the USB hardware block is large ).Do yourself a favor and grab a cpu supported by LUFA. Or grab a PIC processor and use the USB library available on Mikroe compilers. Or any other cpu that has USB supported including a library that does work. you don;t want to be mucking about trying to develop that if you are under time pressure. The same goes for the 'other side' , meaning the operating system driver. Use an existing class like VCP or CDC.Still the simplest solution is : slap on an FTDI chip. they give you the drivers and the new H versions go full throttle at 480Mbit/s

author: skerdzius
author_rank: Contributor
timestamp: December 13, 2012, 09:32:53 pm
content: it was my main purpose to understand USB more deeply and to make it a little more difficult than just few lines of code in Arduino for example. but now i see it is too hard to make it work for me. thanks for guidance anyway

author: jeroen74
author_rank: Frequent Contributor
timestamp: December 13, 2012, 09:50:55 pm
content: If you want to understand USB more deeply, for example, read 'USB Complete' by Jan Alexson or 'USB in a nutshell' onbeyondlogic.org.I have to agree that V-Usb is a nice experiment, but no more.Is USB a main objective of your uniproject?

author: free_electron
author_rank: Super Contributor
timestamp: December 13, 2012, 09:57:04 pm
content: What jeroen74 said.Read USb complete or get the intel book on USB. Better yet , get the USB spec. it's free. And a bloody nightmare to read.To develop a USB system stack from scratch ( assuming correct hardware .... ) is a major undertaking. And you will need some advanced tools to actually 'sniff' the bus. Getting it to be fully compliant will cost you some $$$. be prepared to buy a USB bus analyser like the CATC machines ( now owned by lecroy-teledyne) that can tap into a bus stream and fulle decode the packets.

author: cwalex
author_rank: Frequent Contributor
timestamp: December 14, 2012, 11:26:08 am
content: Years ago I got the CDC demo with VUSB working perfectly first time. I looked at the code to make the micro do the other things I wanted and quickly realised I was way over my head and gave up

author: skerdzius
author_rank: Contributor
timestamp: December 15, 2012, 08:19:26 pm
content: yes, USB was one of key elements in this project.. another one is ADC which is capturing sine wave and uC outputs its period to pc. but now i think i could change usb interface with something else in order to make everything working.