Atmega32 with USB (Bad Signal Problem???)

General discussions about V-USB, our firmware-only implementation of a low speed USB device on Atmel's AVR microcontrollers
Post Reply
Krieger

Atmega32 with USB (Bad Signal Problem???)

Post by Krieger » Mon Sep 01, 2008 3:49 pm

Hi,

i try to get AVR USB Work with an Atmega32 and uses the Software from PowerSwitch
Example with modified usbconfig.h

My Circuit is:

Image

When i connect to Windows Vista nothing happens. When i connect it to my Linux PC i mostly get:

[14632.335397] usb 1-7: new low speed USB device using ohci_hcd and address 6
[14632.519367] usb 1-7: device descriptor read/64, error -62
[14632.807387] usb 1-7: device descriptor read/64, error -62

But every fourth or third connection my linux get it:

[14320.700161] usb 1-7: new low speed USB device using ohci_hcd and address 114
[14320.916267] usb 1-7: configuration #1 chosen from 1 choice

And lsusb gives me than:

Bus 001 Device 009: ID 16c0:05dc

The correct device and vendor id but no description seems to be available.
My only idea is to connect an pull down resistor to D+ with 1M. Ordered the 1M and some other parts today. But propably one of you have some more ideas, why it gets not every time a connection.

For the completion my main function is:

Code: Select all

usbMsgLen_t usbFunctionSetup(uchar data[8])
{
usbRequest_t    *rq = (void *)data;
static uchar    dataBuffer[4];  /* buffer must stay valid when usbFunctionSetup returns */

    return 0;   /* default for not implemented requests: return no data back to host */
}

int main(void)
{
   uint8_t i;


   // Init Seriellen Schnittstelle
   //initSerial();
   
    wdt_enable(WDTO_1S);
   
   DDRD  = ~(1 << 2);
   PORTD = 0;

   usbDeviceDisconnect();  /* enforce re-enumeration, do this while interrupts are disabled! */

   i = 150;
   while(--i){             /* fake USB disconnect for > 250 ms */
       wdt_reset();
      _delay_ms(1);
    }

    usbDeviceConnect();
   
   usbInit();
   
    sei();
   
    serial_puts("connected");
    serial_return();
   
    for(;;){                /* main event loop */
        wdt_reset();
        usbPoll();
    }
}


For what is the usbFunctionSetup ?

Will have more looks into the documentation but happy about every hint.

Greetings

Krieger

Krieger

Some changes for circuit

Post by Krieger » Mon Sep 01, 2008 5:05 pm

Hi,

i changed my 1k5 Resistor on D+ to 2k2 in cause of the 5V supply (not 3.3V). Now it seems to connect fine but i get no endpoint to communicate. lsusb -v gives me:

Code: Select all

Bus 001 Device 034: ID 16c0:05dc  
Device Descriptor:
  bLength                18
  bDescriptorType         1
  bcdUSB               1.10
  bDeviceClass          255 Vendor Specific Class
  bDeviceSubClass         0
  bDeviceProtocol         0
  bMaxPacketSize0         8
  idVendor           0x16c0
  idProduct          0x05dc
  bcdDevice            1.00
  iManufacturer           1
  iProduct                2
  iSerial                 0
  bNumConfigurations      1
  Configuration Descriptor:
    bLength                 9
    bDescriptorType         2
    wTotalLength           18
    bNumInterfaces          1
    bConfigurationValue     1
    iConfiguration          0
    bmAttributes         0x80
      (Bus Powered)
    MaxPower              100mA
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        0
      bAlternateSetting       0
      bNumEndpoints           0
      bInterfaceClass         0 (Defined at Interface level)
      bInterfaceSubClass      0
      bInterfaceProtocol      0
      iInterface              0
cannot read device status, Operation not permitted (1)


Propably i have to code something but in the PowerSwitch example i see no endpoint configuration or something else.

Greetings

Thomas

henni
Posts: 16
Joined: Mon Sep 08, 2008 4:17 pm

Re: Some changes for circuit

Post by henni » Tue Sep 09, 2008 9:08 am

> i changed my 1k5 Resistor on D+ to 2k2 in cause of the 5V supply (not 3.3V).

The right resistor value for such a pull-up is 10 kΩ:
UH(3.3V) = 3.3V * 15kΩ / (1.5kΩ + 15kΩ) = 3.0V
UH(5.0V) = 5.0V * 15kΩ / (10kΩ + 15kΩ) = 3.0V
15kΩ is the host-side internal pull-down that forms the voltage divider.

However, if you run your AVR with 5V supply, you should use a bit smaller value to pull the D- pin to a higher voltage, especially for less USB stand-by current.

gniibe
Posts: 1
Joined: Thu Sep 11, 2008 2:22 pm

usbPoll problem, perhaps

Post by gniibe » Thu Sep 11, 2008 2:33 pm

I have encounter similar problem when I test AVR-USB at 20MHz, when
main loop just call usbPoll and no other things.

If you put some delay in the loop, say, _delay_us(200),
and it works fine, usbPoll might be the cause of problem.

For my case, following change fixed my problem.

Could you please try it out?
I have submitted this as a bug report [USB#1413316].

Code: Select all

--- avrusb-20080513/usbdrv/usbdrv.c~   2008-05-14 01:00:11.000000000 +0900
+++ avrusb-20080513/usbdrv/usbdrv.c   2008-09-11 20:36:30.000000000 +0900
@@ -592,7 +592,7 @@
             usbBuildTxBlock();
         }
     }
-    for(i = 10; i > 0; i--){
+    for(i = 20; i > 0; i--){
         uchar usbLineStatus = USBIN & USBMASK;
         if(usbLineStatus != 0)  /* SE0 has ended */
             break;


epsilon_da
Rank 1
Rank 1
Posts: 29
Joined: Mon Oct 13, 2008 7:11 pm

Post by epsilon_da » Tue Oct 14, 2008 7:16 pm

Hello Krieger.

I have a similar problem:
http://forums.obdev.at/viewtopic.php?t=1803

I think that it is relate to the cyrstal oscilator or maybe not.

I have tryed the circuit that you posted with that code but it also doesnt work for me, so maybe it is my FUSE bits.
Right now i have:
FUSEs: H:0xC9 L:0xEF

I am new with atmel devices, so i dont understand too much of fuse flags.
I need to set it to a 16Mhz crystal oscilator, but the device is getting recogniced.

If you have the ATmega32 at 16Mhz working with usb, can you please send me it as an example? jacobidiego ( at ) gmail.com

christian
Objective Development
Objective Development
Posts: 1443
Joined: Thu Nov 09, 2006 11:46 am

Post by christian » Wed Oct 22, 2008 5:59 pm

Regarding the pull-up: I use 1.5 kOhm usually, but it all depends on the zener diodes. The voltage should be between 3 and 3.3 V in idle mode.

Regarding the endpoint: Endpoint 0 is always there and is a control endpoint. You don't need to declare it.

Post Reply