USB communication problems with ATmega8 (4nes4snes-adapter)

General discussions about V-USB, our firmware-only implementation of a low speed USB device on Atmel's AVR microcontrollers
Post Reply
Gizmoomzig
Posts: 5
Joined: Wed Aug 03, 2011 11:06 pm

USB communication problems with ATmega8 (4nes4snes-adapter)

Post by Gizmoomzig » Wed Aug 03, 2011 11:41 pm

Hi,
I am new to microcontrollers and USB programming and I encountered a problem on my first project. I was rebuilding the 4nes4snes adapter from http://www.raphnet.net/electronique/4nes4snes/index_en.php and everything went fine until I connected the board with the USB port on my PC. As there was no communication at all with the ATmega8-16PU I used, I read through the Troubleshoot section on this webpage.
First I verified the fuse-bytes on the MC with avrdude which were fine (high: 0xC9 and low: 0x9F) as described on the homepage. I went through the code and found that F_CPU was set to 12000000 as it should be because I use a 12 MHz external crystal oscillator. I recompiled the source code on my own computer and flashed it again (and verified it), but it didnt change anything. Aftwards I added 104pF capacitors to D- and D+ which actually lets the computer communicate with the device but as it seems, it cannot decide on what speed it has to communicate with the 4nes4snes adapter. I also checked the wiring but it should be correct. So I think this might be a software problem and as said I tried compiling the source on my computer and the hex file from the homepage with the same result.

I use an ATmega8-16PU and the host is a Gentoo Linux 2.6.39-gentoo-r2. libusb does not list the device.

Output from dmesg after plugging the adapter in:

Code: Select all

[38018.859056] hub 6-0:1.0: hub_suspend
[38018.859075] usb usb6: bus auto-suspend
[38018.859081] usb usb6: suspend_rh
[46177.884928] hub 2-0:1.0: state 7 ports 6 chg 0000 evt 0004
[46177.884954] ehci_hcd 0000:00:1d.7: GetStatus port:2 status 001403 0  ACK POWER sig=k CSC CONNECT
[46177.884972] hub 2-0:1.0: port 2, status 0501, change 0001, 480 Mb/s
[46177.988119] hub 2-0:1.0: debounce: port 2: total 100ms stable 100ms status 0x501
[46177.988140] ehci_hcd 0000:00:1d.7: port 2 low speed --> companion
[46177.988178] usb usb6: usb wakeup-resume
[46177.988188] usb usb6: usb auto-resume
[46177.988193] usb usb6: wakeup_rh
[46178.020111] hub 6-0:1.0: hub_resume
[46178.020144] uhci_hcd 0000:00:1d.0: port 2 portsc 01a3,00
[46178.020152] hub 6-0:1.0: port 2: status 0301 change 0001
[46178.039126] ehci_hcd 0000:00:1d.7: GetStatus port:2 status 003002 0  ACK POWER OWNER sig=se0 CSC
[46178.039164] hub 2-0:1.0: state 7 ports 6 chg 0000 evt 0004
[46178.121154] hub 6-0:1.0: state 7 ports 2 chg 0004 evt 0000
[46178.121177] hub 6-0:1.0: port 2, status 0301, change 0000, 1.5 Mb/s
[46178.172256] hub 6-0:1.0: unable to enumerate USB device on port 2
[46178.172401] hub 2-0:1.0: state 7 ports 6 chg 0000 evt 0004
[46178.172421] ehci_hcd 0000:00:1d.7: GetStatus port:2 status 001403 0  ACK POWER sig=k CSC CONNECT
[46178.172438] hub 2-0:1.0: port 2, status 0501, change 0001, 480 Mb/s
[46178.276127] hub 2-0:1.0: debounce: port 2: total 100ms stable 100ms status 0x501
[46178.276145] ehci_hcd 0000:00:1d.7: port 2 low speed --> companion
[46178.327130] ehci_hcd 0000:00:1d.7: GetStatus port:2 status 003002 0  ACK POWER OWNER sig=se0 CSC
[46178.327166] hub 2-0:1.0: state 7 ports 6 chg 0000 evt 0004
[46178.454170] hub 6-0:1.0: state 7 ports 2 chg 0000 evt 0004
[46178.454188] uhci_hcd 0000:00:1d.0: port 2 portsc 01a3,00
[46178.454205] hub 6-0:1.0: port 2, status 0301, change 0001, 1.5 Mb/s
[46178.558140] hub 6-0:1.0: debounce: port 2: total 100ms stable 100ms status 0x301
[46178.609162] hub 6-0:1.0: unable to enumerate USB device on port 2
[46178.704101] hub 6-0:1.0: state 7 ports 2 chg 0000 evt 0004
[46178.704122] uhci_hcd 0000:00:1d.0: port 2 portsc 01a3,00
[46178.704139] hub 6-0:1.0: port 2, status 0301, change 0001, 1.5 Mb/s
[46178.808160] hub 6-0:1.0: debounce: port 2: total 100ms stable 100ms status 0x301
[46178.859201] hub 6-0:1.0: unable to enumerate USB device on port 2
[46178.859351] hub 2-0:1.0: state 7 ports 6 chg 0000 evt 0004
[46178.859374] ehci_hcd 0000:00:1d.7: GetStatus port:2 status 001403 0  ACK POWER sig=k CSC CONNECT
[46178.859392] hub 2-0:1.0: port 2, status 0501, change 0001, 480 Mb/s
[46178.963119] hub 2-0:1.0: debounce: port 2: total 100ms stable 100ms status 0x501
[46178.963137] ehci_hcd 0000:00:1d.7: port 2 low speed --> companion
[46179.014133] ehci_hcd 0000:00:1d.7: GetStatus port:2 status 003002 0  ACK POWER OWNER sig=se0 CSC
[46179.014170] hub 2-0:1.0: state 7 ports 6 chg 0000 evt 0004
[46179.204167] hub 6-0:1.0: state 7 ports 2 chg 0000 evt 0004
[46179.204184] uhci_hcd 0000:00:1d.0: port 2 portsc 01a3,00
[46179.204200] hub 6-0:1.0: port 2, status 0301, change 0001, 1.5 Mb/s
[46179.308064] hub 6-0:1.0: debounce: port 2: total 100ms stable 100ms status 0x301
[46179.359177] hub 6-0:1.0: unable to enumerate USB device on port 2
[46179.359319] hub 2-0:1.0: state 7 ports 6 chg 0000 evt 0004
[46179.359337] ehci_hcd 0000:00:1d.7: GetStatus port:2 status 001403 0  ACK POWER sig=k CSC CONNECT
[46179.359353] hub 2-0:1.0: port 2, status 0501, change 0001, 480 Mb/s
[46179.463153] hub 2-0:1.0: debounce: port 2: total 100ms stable 100ms status 0x501
[46179.463170] ehci_hcd 0000:00:1d.7: port 2 low speed --> companion
[46179.514172] ehci_hcd 0000:00:1d.7: GetStatus port:2 status 003002 0  ACK POWER OWNER sig=se0 CSC
[46179.514208] hub 2-0:1.0: state 7 ports 6 chg 0000 evt 0004
[46179.704078] hub 6-0:1.0: state 7 ports 2 chg 0000 evt 0004
[46179.704100] uhci_hcd 0000:00:1d.0: port 2 portsc 01a3,00
[46179.704117] hub 6-0:1.0: port 2, status 0301, change 0001, 1.5 Mb/s
[46179.808176] hub 6-0:1.0: debounce: port 2: total 100ms stable 100ms status 0x301
[46179.859201] hub 6-0:1.0: unable to enumerate USB device on port 2
[46179.954162] hub 6-0:1.0: state 7 ports 2 chg 0000 evt 0004
[46179.954183] uhci_hcd 0000:00:1d.0: port 2 portsc 01a3,00
[46179.954199] hub 6-0:1.0: port 2, status 0301, change 0001, 1.5 Mb/s
[46180.058118] hub 6-0:1.0: debounce: port 2: total 100ms stable 100ms status 0x301
[46180.109172] hub 6-0:1.0: unable to enumerate USB device on port 2
[46180.109356] hub 2-0:1.0: state 7 ports 6 chg 0000 evt 0004
[46180.109376] ehci_hcd 0000:00:1d.7: GetStatus port:2 status 001403 0  ACK POWER sig=k CSC CONNECT
[46180.109393] hub 2-0:1.0: port 2, status 0501, change 0001, 480 Mb/s
[46180.213117] hub 2-0:1.0: debounce: port 2: total 100ms stable 100ms status 0x501
[46180.213135] ehci_hcd 0000:00:1d.7: port 2 low speed --> companion
[46180.264133] ehci_hcd 0000:00:1d.7: GetStatus port:2 status 003002 0  ACK POWER OWNER sig=se0 CSC
[46180.264170] hub 2-0:1.0: state 7 ports 6 chg 0000 evt 0004
[46180.454071] hub 6-0:1.0: state 7 ports 2 chg 0000 evt 0004
[46180.454088] uhci_hcd 0000:00:1d.0: port 2 portsc 01a3,00
[46180.454104] hub 6-0:1.0: port 2, status 0301, change 0001, 1.5 Mb/s
[46180.558134] hub 6-0:1.0: debounce: port 2: total 100ms stable 100ms status 0x301
[46180.609166] hub 6-0:1.0: unable to enumerate USB device on port 2
[46180.609349] hub 2-0:1.0: state 7 ports 6 chg 0000 evt 0004
[46180.609367] ehci_hcd 0000:00:1d.7: GetStatus port:2 status 001403 0  ACK POWER sig=k CSC CONNECT
[46180.609384] hub 2-0:1.0: port 2, status 0501, change 0001, 480 Mb/s


The message are repeated until i unplug the adapter. As Im not familiar with USB debug messages it seems as the computer cant figure out if its a USB 2 or USB 1 device as it switches between 480 and 1.5 Mb/s.

As my USB-cable comes from an older keyboard and has no shielding, I tried shortening it to 20cm but without luck. I dont know how this error can be resolved but maybe one of you here has encountered similar problems and can help.

Thanks
Gizmoomzig

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

Re: USB communication problems with ATmega8 (4nes4snes-adapter)

Post by ulao » Thu Aug 04, 2011 12:09 am

Hi, I used many of his projects, I's say start with usbLyzer and print or save what it shows. See if its the descriptor, device, or config that gives the issues. You can use the hot plug feature to get the negotiations. You say it compiles and the usb does not work, then its in the configs. Your on linux or windows?

Gizmoomzig
Posts: 5
Joined: Wed Aug 03, 2011 11:06 pm

Re: USB communication problems with ATmega8 (4nes4snes-adapter)

Post by Gizmoomzig » Fri Aug 05, 2011 1:09 am

Thanks for the reply.
Im normally using Linux but also have a Windows system at hand to try it out.

usbLyzer tells me that the enumeration of the device failed.
PnP properties:

Code: Select all

Description:   Unbekanntes Gerät
Instance Status:   01806000h    DN_DISABLEABLE
                               DN_REMOVABLE
                               DN_NT_ENUMERATOR
                               DN_NT_DRIVER
Instance ID:                   USB\VID_0000&PID_0000\5&2F2EFA25&0&2
Hardware IDs:                   USB\UNKNOWN
Compatible IDs:                   USB\UNKNOWN
Service Name:   
Setup Class:                   USB
Setup Class Description:   USB-Controller
Setup Class GUID:           {36fc9e60-c465-11cf-8056-444553540000}
Software Key:                   {36fc9e60-c465-11cf-8056-444553540000}\0037
Manufacturer:                   (Standard-USB-Hostcontroller)
Friendly Name:   
Hardware Location:           Port_#0002.Hub_#0005
PDO Name:                     \Device\USBPDO-12


As Windows reports an unknown device to PnP, it seems that its timed out on the port reset. (http://blogs.msdn.com/b/usbcoreblog/archive/2009/10/31/how-does-usb-stack-enumerate-a-device.aspx). I dont know why it isnt responding nor how to resolve the issue.

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

Re: USB communication problems with ATmega8 (4nes4snes-adapter)

Post by ulao » Fri Aug 05, 2011 6:49 am

Have you tried to burn his exact hex file? Do you have the exact bill of parts ( any differences, out side the caps you mentioned )

Gizmoomzig
Posts: 5
Joined: Wed Aug 03, 2011 11:06 pm

Re: USB communication problems with ATmega8 (4nes4snes-adapter)

Post by Gizmoomzig » Mon Aug 08, 2011 9:17 pm

I started with the exact hex-file but it too does not work.
The parts are exactly the same. In the documentation it says
C2, C3: 27 pf capacitors. If the crystal datasheet recommends another value, use it instead."
but the datasheet of the Crystal refers to a load capacitance ranging from 5pF ~ 50pF and a shunt capacitance of max. 7pF. I acutally dont know if the capacitors are choosen correct or if I should take different ones.

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

Re: USB communication problems with ATmega8 (4nes4snes-adapter)

Post by ulao » Tue Aug 09, 2011 3:32 pm

Is the Cristal 12mhz on the dot, the simplest deviation will cause your issue. I would certainly try another, i use HC-49S.

Gizmoomzig
Posts: 5
Joined: Wed Aug 03, 2011 11:06 pm

Re: USB communication problems with ATmega8 (4nes4snes-adapter)

Post by Gizmoomzig » Thu Aug 11, 2011 10:56 pm

The crystal is 12 MHz on the dot. If I choose a crystal with 16 MHz, wouldnt it too have deviations? A higher clock than 16 MHz is not supported by the ATmega8-16, is there a way to slow a faster clock down to 12 MHz?

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

Re: USB communication problems with ATmega8 (4nes4snes-adapter)

Post by ulao » Thu Aug 11, 2011 11:30 pm

not with the (s)nes, it uses _dealys no "nop" operations so setting your clock in the project is all you need to do. V-usb will work on a 16 ( later versions only ) I was referring to a 12.1 or so. The usb timing is critical. Slowing down a cock IMO is silly, just use the right crystal...

Are you using 1 or 1/2 watt diodes?
For atmeg8 you can use either but atmeg168 needs to be 1/2 watt.


FYI: I know many people use a 16,mhz on a 168 chip, so I dont know why or where you read that. ( though this is not your issue, you dont need a 16 )

Tim_BandTech.Com
Posts: 6
Joined: Mon Aug 15, 2011 2:31 pm

Re: USB communication problems with ATmega8 (4nes4snes-adapter)

Post by Tim_BandTech.Com » Mon Aug 15, 2011 3:30 pm

When you say that your crystal is 12 MHz on the dot, this may be true as it is written on the face of the crystal, but the capacitors that must be ganged to the crystal are specified by the manufacturer to reach that frequency on the dot, and even then true on the dot requires calibration of those capacitors.

This means that if you have an unusual crystal that the schematic capacitor values are not necessarily correct. Beyond this the AVR chips spec capacitance at the terminals of the xtal in, which should be added to the schematic values (capacitance to ground means parallel capacitors) when assessing the match to any specific crystal. I have dug in pretty deep here for RF work, and the parameters are quite confusing.

This is fairly esoteric stuff, and it may not be your problem at all, since there should be some tolerance, and your frequency is likely very close to 12MHz.
In reality the amount of variation that can be achieved away from 12MHz is only slight, but if you push beyond that variational limit then you could have a bogus oscillator, and this could be your problem. Because you are failing at the early side of things and you are reusing the existing firmware you may still have a hardware (e.g. clock) problem.

Capacitors come in various tolerances, and 20% is fairly common. The traces on the board could add capacitance if they are thick and over a ground plane. If you don't have test instruments then you are in the dark here, and the first method that I can think of would be to start with small capacitors and gang on more, but this is a kluge. If you can fit a small variable capacitor this could also get you in the range. 5 to 50 pF is in the range of some trimmer capacitors, and there are very small film trimmers that may fit nicely.

So is there a gadget that can get you a clean frequency measure? Since you do have a cpu it is possible that you could count your clock cycles out to some fairly long time (say one hour), and you can blink an led so you have a coarse frequency counter. This method could literally be you with a stopwatch coming back a bit before the hour interval and watching for a change of state in an LED. Even with 1 second accuracy this is .03% accurate, if your timepiece is perfectly accurate. I think practically this is a verification that you have a sane oscillator circuit, and an oscilloscope may be just as good for this step. Forgoing both a scope and a frequency counter; this is the ghetto method. I've been there, but I haven't done this. My first MPU at home projects are now and I am now equipped with a scope and frequency counter.

I may have gone off the deep end here, but this information is general and for people who lack a frequency counter but do have a MPU this yields a verification. Sorry to say that I am just digging into the USB thing myself so my own USB experience is bleak.

- Tim http://bandtech.com

newhero

Re: USB communication problems with ATmega8 (4nes4snes-adapter)

Post by newhero » Mon Sep 12, 2011 12:35 am

Probably you have same problem with me As I posted here later than you.

I made it and was susscessful.
But when I bought new atmega8 recently, I replaced it with older working good one.
Because I want to make another board to implement my own pinouts and firmware modifying existing one.
But failed again and again even with many of newly purchased chips.
While I'm trying that I found that the V-usb project's circuit is really simple and almost all the things are done by the atmega8 chips, so if you didn't solder wrong, there'll be no circuit design flaw.
Luckily I'm having some of old manufacutre dated atmega, too.
I tested many kinds of things as successful.

The Minimum Components I used are
2 68 Ohm Resistors for D+ and D-
1 1.5K Ohm Resistor for D-
2 zener diode limiting the voltage
Atmega 8 16 AU (acutally On conversion board from QTFP to DIP Pin heads)
raw 12Mhz Crystal without any a capacitor --> it looks stupid ^^;
I connected them all with small pinhead cables without soldering, sometimes it bent 90 degree.
It looks like whole strongly Not Recommeded looking. Either Chip fuse settings were not that much sensitive.
still working great.


With Newly manufactured chip, with all the recommended circuit design schemes it never worked.


Still I didn't find any a solution yet.

can you tell me what exactly chip model number? to compare with mine
.


My Email is newheronv@naver.com

Thank you.

newhero

Re: USB communication problems with ATmega8 (4nes4snes-adapter)

Post by newhero » Mon Sep 12, 2011 1:29 am

Oh, I forgot to add something.
With External Oscillator it was working sometime, but something unstable.

Gizmoomzig
Posts: 5
Joined: Wed Aug 03, 2011 11:06 pm

Re: USB communication problems with ATmega8 (4nes4snes-adapter)

Post by Gizmoomzig » Thu Sep 22, 2011 3:59 pm

Sorry for not posting for a long time. Lots of private stuff...

to newhero:
On the chip itself is
ATMEL 1051
ATMEGA8-16PU

written.
Or is there a different chip model number? I bought the chip on 12.07.2011 so it should not be too old.
Normally, it should work with that chip model.

to Tim_BandTech.Com:
Im trying to get my hands on an oscilloscope to check the frequency. Until then I will try the ghetto LED solution :)

to ulao:
Sorry, I misunderstood your post. I dont have another clock except the one I use for the adapter but I´ll get a slightly faster one like 12.288 MHz.
I use 1/2 watt zener-diodes.

Post Reply