Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

V-USB not working properly on atmega328p

Status
Not open for further replies.
7130.680049] usb 5-1: new low speed USB device using ohci_hcd and address 7
[27130.831914] usb 5-1: device descriptor read/64, error -62
[27131.090051] usb 5-1: device descriptor read/64, error -62
[27131.340052] usb 5-1: new low speed USB device using ohci_hcd and address 8
[27131.760051] usb 5-1: device not accepting address 8, error -62
[27131.930049] usb 5-1: new low speed USB device using ohci_hcd and address 9
[27132.350038] usb 5-1: device not accepting address 9, error -62
[27132.350063] hub 5-0:1.0: unable to enumerate USB device on port 1
When I plug in my avr using a USB 1.1 Type B socket i get the above errors within the dmesg. Any ideas I've double checked my circuit I can't see any obvious errors.

I'm using zener diodes method as my circuit supply voltage is 5v. They're rate for 3.6V at 0.6W. I'm trying to use BOOTHID bootloader so I can upload my firmware via usb. I have the firmware flashed onto my chip. I'm using a 20 MHZ crystal. It's setup as a full swing oscillator.
 
Last edited:
What AVR are you talking about, what's the schematic for your circuit and where's the code for it? You've not given us much to work with.
If you're trying to use the BootHID bootloader to flash the firmware how is it that you then say you have the firmware flashed onto your chip already?

I've read the thread you posted on the AVRFreak forum they seemed to be pointing you on the right track.
 
yeah that was when I thought I didn't need a programmer when I've configured boothid. Sorry I wasn't but I mean't I've loaded the usb bootloader onto my atmega 328p but it's
giving me the errors above everytime I plug it in.

The code isn't my code I used boothid which is written by Christian Starkjohann. It's on the same site as v-usb.
I was more after of an explanation of what the heck that error code means.

The schematic for the usb part is exactly the same as the attachment except it's externally powered. The pull up for d- draws from external 5v power supply.

I'm using a 1.1 type B socket
 
It's getting a read error when it tries to read the device descriptor, which pretty much means it's not talking over USB properly.

How did you flash the chip with the USB bootloader in the first place? Perhaps there are some fuses that weren't set or the chip isn't running at the frequency you think it is. The speed the chip runs at is hyper critical for working over USB. Perhaps it's simply a matter of it's not running at the frequency the software is set for. The default refrence schematic for the V-usb shows a 12mhz clock, if you're using a 20mhz clock perhaps you didn't change the code properly to allow for 20mhz operation?

Re-verify the code you've flashed to the device is configured properly and that your fuse bits are set properly.
 
Last edited:
I used a avrisp mk2 programmer. I'm trying to add the extra feature of flashing the firmware via usb.
The fuses were set to use the external 20mhz crystal as a Full Swing Crystal Oscillator.

I set in bootloaderconfig.h #define USB_CFG_CLOCK_KHZ 20000

Inside the MakeFile for the bootloader firmware, it compiles the source to run at a certain speed based on constant.
COMPILE = avr-gcc -Wall -Os -fno-move-loop-invariants -fno-tree-scev-cprop -fno-inline-small-functions -Iusbdrv -I. -mmcu=$(DEVICE) -DF_CPU=$(F_CPU) -DDEBUG_LEVEL=0 # -DTEST_MODE
I set the F_CPU to 20000000

high FUSE = 0xd8
low FUSE = 0xf7

Perhaps my crystal aint running at 20MHZ. I heard breadboards can mess up the crystal.
However I'm sure it's running because I was debugging yesterday and I could flash the avr.
 

Attachments

  • bootloaderconfig.h
    5.6 KB · Views: 350
  • usbconfig.h
    12.3 KB · Views: 377
Determine what frequency it's actually running at or you're just guessing.
 
The crystal is shud be 20MHZ because I specifically brought it.
As for the chip internal oscillator it's 8 mhz as thats what the spec says.
I don't have the equipment to actually take a reading. My multimeter doesn't read frequencies that low and I don't have access to oscilloscope.
 
So write a program for it and flash it (since you have one) that uses a timer pre-scaled down to a frequency low enough for you to register.

A 20mhz crystal on a breadboard could be pulled far enough out of spec that it might not work properly, or it could be at 10 or 30mhz and you wouldn't even know it unless you have some way to measure the clock speed.
 
Last edited:
Just to be sure am not being an amateur here.

I connected the 68ohm pull up to the pin then the appropriate wire from the usb socket.
In between those I have 3.6v 0.6w zene didode wired to gnd (the end without the black mark to gnd)
On the D- line I have a 1.5K pull up connected to port PD1.

I might as well give you the code for initialising the usb as well. So say it is the breadboard that causing load capacitance issues, it would go away if I solder the parts together right?

I was going to solder it anyway since breadboard not really a replacement for USB.

The zeners pull down 3.9V according to my multimeter but their rating is for 3.6V but that is normal because components are never bang on right?

Also do the two earth pins ( the ones connected to the external casing) make a difference I snapped them when I was soldering the wires onto the port.
 

Attachments

  • main.c
    7 KB · Views: 439
Last edited:
What does any of that have to do with verifying the actual running clock speed of the setup as it now is? There are a lot of unknowns like you said this was on a breadboard and crystals operating at that frequency don't like breaboards sometimes. You could be operating at a harmonic, especially if the 20mhz crystal is an overtone crystal, don't now.

It's probably something very simple that you're overlooking because you've already checked over everything multiple times. You're missing something, a good first step at this point would be to find out what the clock frequency of the chip right now actually IS. You're assuming FAR too many things without testing for them.

Write a simple program that uses a timer prescaler to turn an LED on and off with a high prescaler, like 1024, that will turn the I/O line on an off at near audio frequencies.
 
The highest prescaler I have is 256 as the rest are labelled as reserved.

I used clock_prescale_set(8) macro to set the prescale to 256
The usb is outputting the same errors

Does that mean it was running at the right frequency then?
I did notice the following warnings but I thought warning are not errors and there just to help us develop good code?

./usbconfig.h:180:1: warning: "/*" within comment
usbdrv/usbdrv.h:213: warning: 'usbFunctionDescriptor' used but never defined
usbdrv/usbdrv.h:220: warning: 'usbSetInterrupt' declared 'static' but never defined
 
Last edited:
Sorry Amateur, but nothing in your post makes any sense, just setting the prescaler won't do anything. I was suggesting using a timer prescaler and perhaps an overflow interupt, some relativly basic code to output a simple square wave that you could read on something like a sound card. You have to write this code yourself, you don't appear to know how to write any kind of code? There's definitly something you're doing wrong in setting up and compiling the code. Not a thing I can do to help.
 
Thanks for being patient. IT's fair enough you can't help on the compiling.

The trouble was I didn't understand how that could help. Now you're making sence to me but I still don't have a clue how to go about it.
Any guidance is greatly appreciated. Would any sound card work? I have a sound blaster audigy 2 ls. What software/ other equipment ( i.e. cables etc) would I need to sample the frequency ?

To be fair I did say i was am amateur lol. I'm reading on how to setup the overflow / timer prescaler now.
 
Last edited:
Think of it this way. If you set up a timer with a 256 prescaler the timer will increment 1 per every 256 clock ticks.
AT 20mhz divided by 256 and set up an interupt to triger on a timer overflow (that's another 256) The timer overflow interupt routine will trigger 305.17578125 times per second. So If you set up a timer overflower interupt routine with a 256 prescaler on the timer to toggle an I/O line you'll get a frequency output of 152.587890625 hertz. You can work the math backwards after you figure out what frequency a simpler overflow I/o toggle routine like that gives you.
 
Thanks alot for your help so far. After saving up, I've now got myself a digital oscilloscope. According the scope my crystal is working fine at 20MHZ. I have noticed the occasional glitch where it will run slightly higher/ lower then return to 20MHZ.

I've setup the avr clock source to be low power crystal.
 
Define slightly higher and slightly lower 'slightly' isn't a numbering system I'm familiar with =)
 
Define slightly higher and slightly lower 'slightly' isn't a numbering system I'm familiar with =)

well 19.something or 20.2MHZ. But isn't that normal? Sometimes you get that whilest taking measurement with multimeters as well.
The datasheet says it's +/- 30PPM for the tolerance. I'm guessing it's within that?


to be fair I thought it was normal since components have tolerances. Like my 150ohm resistor measure 149 on my meter
 
Last edited:
amateur, you need to do some remedial math =)

A crystal at 20mhz with a 30ppm tolerance should read no lower or higher than 30 parts per million times 20 millions. So 600ppm.
The low on that would be around 19.99400mhz, and the high end would be around 20.000600mhz.

19.something isn't a number. 20.2mhz is, but it's also almost 200khz out of tune with the desired frequency.


You're guessing wrong and assuming your guesses are correct.
 
Status
Not open for further replies.

Latest threads

Back
Top