[SOLVED] ATmega32 is failing to receive the address

General discussions about V-USB, our firmware-only implementation of a low speed USB device on Atmel's AVR microcontrollers
Post Reply
epsilon_da
Rank 1
Rank 1
Posts: 29
Joined: Mon Oct 13, 2008 7:11 pm

[SOLVED] ATmega32 is failing to receive the address

Post by epsilon_da » Mon Oct 13, 2008 7:29 pm

Hi i am making a test circuit with an ATmega32 based on the code of HIDKeys.

I am getting this errors on linux debian:
usb 2-3: new low speed USB device using ohci_hcd and address 59
usb 2-3: device descriptor read/64, error -62
usb 2-3: device descriptor read/64, error -62
usb 2-3: new low speed USB device using ohci_hcd and address 60
usb 2-3: device descriptor read/64, error -62
usb 2-3: device descriptor read/64, error -62
usb 2-3: new low speed USB device using ohci_hcd and address 61
usb 2-3: device not accepting address 61, error -62
usb 2-3: new low speed USB device using ohci_hcd and address 62
usb 2-3: device not accepting address 62, error -62


And lsusb doesnt list the device.

The programmer is USBasp and it works fine.
I have used the FUSE calcultor of http://www.engbedded.com/cgi-bin/fc.cgi/

For a 16 Mhz crystal oscilator.

Initialization is as follow:

DDRD = 0; // PortD: inputs
PORTD = 0; // No PullUps on USB pins

#define F_CPU 16000000L
#define USB_CFG_IOPORTNAME D
#define USB_CFG_DMINUS_BIT 2
#define USB_CFG_DPLUS_BIT 6

D- is connected to INT0.
I have only some buttons with internal pullups on portb and leds on port C.

The HID Descriptor is copyed from HIDKeys:

Code: Select all

PROGMEM char usbHidReportDescriptor[35] = { /* USB report descriptor */
    0x05, 0x01,                    // USAGE_PAGE (Generic Desktop)
    0x09, 0x06,                    // USAGE (Keyboard)
    0xa1, 0x01,                    // COLLECTION (Application)
    0x05, 0x07,                    //   USAGE_PAGE (Keyboard)
    0x19, 0xe0,                    //   USAGE_MINIMUM (Keyboard LeftControl)
    0x29, 0xe7,                    //   USAGE_MAXIMUM (Keyboard Right GUI)
    0x15, 0x00,                    //   LOGICAL_MINIMUM (0)
    0x25, 0x01,                    //   LOGICAL_MAXIMUM (1)
    0x75, 0x01,                    //   REPORT_SIZE (1)
    0x95, 0x08,                    //   REPORT_COUNT (8)
    0x81, 0x02,                    //   INPUT (Data,Var,Abs)
    0x95, 0x01,                    //   REPORT_COUNT (1)
    0x75, 0x08,                    //   REPORT_SIZE (8)
    0x25, 0x65,                    //   LOGICAL_MAXIMUM (101)
    0x19, 0x00,                    //   USAGE_MINIMUM (Reserved (no event indicated))
    0x29, 0x65,                    //   USAGE_MAXIMUM (Keyboard Application)
    0x81, 0x00,                    //   INPUT (Data,Ary,Abs)
    0xc0                           // END_COLLECTION
};



When i click a button it should send a letter and change one led status to see that it was processed.

After i connect the device i can play around with buttons and leds but none are written on the opened text editor.

Doing lsusb seems to try to comunicate with the device because it slows down when the circuit is connected.

"dmesg | grep usb" show the above lines.

And checking for the usb cable, i have continuity with the 4 lines.
In D- Messuring with a normal tester it shows 2.9 V on iddle state, but on D+ i have a plain 0 V which i dont know if it is correct, i think that 0 V means no activity at all.
I can force some activity by running "lsusb".

Zenners are 3.6V and are both new.

Any idea?.
Last edited by epsilon_da on Wed Oct 15, 2008 5:14 pm, edited 1 time in total.

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

Post by epsilon_da » Mon Oct 13, 2008 8:12 pm

My USBasp have also -0.02V and 2.9V on D- and D+ respectively and it works, so the cable is fine.

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

Post by epsilon_da » Wed Oct 15, 2008 4:48 am

Seems like ATmega32 is incompatible with AVRusb

I have shrinked it down a LOT, to the tiniest possible expression of AVRusb for ATmega32.

Image


Code: Select all

/* 
** FUSE Calculator: http://www.engbedded.com/cgi-bin/fc.cgi/
** FUSEs:  H:0xC9  L:0xEF
**     avrdude -c usbasp -p atmega32 -u -U hfuse:w:0xC9:m -U lfuse:w:0xEF:m
** For burnning:
**   avrdude -c usbasp -p atmega32 -U flash:w:default/USBLogger.hex
*/


#define F_CPU   12000000L

#include "usbconfig.h"

//=============================================================================
// USB interface port and bits
#define USB_MASK ((1<<USB_CFG_DPLUS_BIT) | (1<<USB_CFG_DMINUS_BIT)) // mask for USB I/O bits

#define USB_CFG_CLOCK_KHZ       12000//(F_CPU/1000)
#define USB_CFG_DEVICE_NAME     'H', 'I', 'D', 'K', 'e', 'y', 's'
#define USB_CFG_DEVICE_NAME_LEN 7
//#define USB_PULLUP_CONTROL
#ifndef USB_PULLUP_CONTROL
 #define USB_CFG_IOPORTNAME          D
 //#define USB_CFG_DMINUS_BIT          6
 //#define USB_CFG_DPLUS_BIT           2
 #define USB_CFG_DMINUS_BIT          3
 #define USB_CFG_DPLUS_BIT           2

 #define usbDeviceConnect()
 #define usbDeviceDisconnect()
#else
 #define USB_CFG_IOPORTNAME          D
 #define USB_CFG_DMINUS_BIT          6
 #define USB_CFG_DPLUS_BIT           2
 #define USB_CFG_PULLUP_IOPORTNAME   D
 #define USB_CFG_PULLUP_BIT          7
#endif


#include <avr/interrupt.h>
#include <avr/pgmspace.h>
#include <avr/wdt.h>            // WatchDog
#include <util/delay.h>         // _delay_ms()

#include "usbdrv.h"            // AVR-USB driver
#include "oddebug.h"         // AVR-USB driver DEBUG

//==========================================================================
//=========================== AVR-USB Configuration (HID Descriptor) =======
//==========================================================================
PROGMEM char usbHidReportDescriptor[35] = { /* USB report descriptor */
    0x05, 0x01,                    // USAGE_PAGE (Generic Desktop)
    0x09, 0x06,                    // USAGE (Keyboard)
    0xa1, 0x01,                    // COLLECTION (Application)
    0x05, 0x07,                    //   USAGE_PAGE (Keyboard)
    0x19, 0xe0,                    //   USAGE_MINIMUM (Keyboard LeftControl)
    0x29, 0xe7,                    //   USAGE_MAXIMUM (Keyboard Right GUI)
    0x15, 0x00,                    //   LOGICAL_MINIMUM (0)
    0x25, 0x01,                    //   LOGICAL_MAXIMUM (1)
    0x75, 0x01,                    //   REPORT_SIZE (1)
    0x95, 0x08,                    //   REPORT_COUNT (8)
    0x81, 0x02,                    //   INPUT (Data,Var,Abs)
    0x95, 0x01,                    //   REPORT_COUNT (1)
    0x75, 0x08,                    //   REPORT_SIZE (8)
    0x25, 0x65,                    //   LOGICAL_MAXIMUM (101)
    0x19, 0x00,                    //   USAGE_MINIMUM (Reserved (no event indicated))
    0x29, 0x65,                    //   USAGE_MAXIMUM (Keyboard Application)
    0x81, 0x00,                    //   INPUT (Data,Ary,Abs)
    0xc0                           // END_COLLECTION
};

uchar usbFunctionSetup(uchar setupData[8])
{
    return 0;   /* default for not implemented requests: return no data back to host */
}

int main(void)
{
    uint8_t i;

    wdt_enable(WDTO_1S);
   
    DDRD  = 0;      // all USB and ISP pins inputs
    PORTD = 0;      // No Pullups

    DDRC = 0xFC;    // PortC (LEDs): outputs 1111 1100
    PORTC = 0xF0;   // Turn on LEDs

    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();

   for(;;){                /* main event loop */
       wdt_reset();
       usbPoll();
   }
}



And also the vector table:

USBLogger.elf: file format elf32-avr

Disassembly of section .text:

00000000 <__vectors>:
0: 0c 94 69 00 jmp 0xd2 ; 0xd2 <__ctors_end>
4: 0c 94 0d 02 jmp 0x41a ; 0x41a <__vector_1>
8: 0c 94 86 00 jmp 0x10c ; 0x10c <__bad_interrupt>
c: 0c 94 86 00 jmp 0x10c ; 0x10c <__bad_interrupt>
10: 0c 94 86 00 jmp 0x10c ; 0x10c <__bad_interrupt>
14: 0c 94 86 00 jmp 0x10c ; 0x10c <__bad_interrupt>
18: 0c 94 86 00 jmp 0x10c ; 0x10c <__bad_interrupt>
1c: 0c 94 86 00 jmp 0x10c ; 0x10c <__bad_interrupt>
20: 0c 94 86 00 jmp 0x10c ; 0x10c <__bad_interrupt>
24: 0c 94 86 00 jmp 0x10c ; 0x10c <__bad_interrupt>
28: 0c 94 86 00 jmp 0x10c ; 0x10c <__bad_interrupt>
2c: 0c 94 86 00 jmp 0x10c ; 0x10c <__bad_interrupt>
30: 0c 94 86 00 jmp 0x10c ; 0x10c <__bad_interrupt>
34: 0c 94 86 00 jmp 0x10c ; 0x10c <__bad_interrupt>
38: 0c 94 86 00 jmp 0x10c ; 0x10c <__bad_interrupt>
3c: 0c 94 86 00 jmp 0x10c ; 0x10c <__bad_interrupt>
40: 0c 94 86 00 jmp 0x10c ; 0x10c <__bad_interrupt>
44: 0c 94 86 00 jmp 0x10c ; 0x10c <__bad_interrupt>
48: 0c 94 86 00 jmp 0x10c ; 0x10c <__bad_interrupt>
4c: 0c 94 86 00 jmp 0x10c ; 0x10c <__bad_interrupt>
50: 0c 94 86 00 jmp 0x10c ; 0x10c <__bad_interrupt>



Al seems perfect to me.
The circuit is made in a protoboard with a premade usb cable with the resistors and zenners soldered.
I have eliminated the a possible failure with the cable by connecting the ATmega8 of my programmer to the protoboard and the USB cable, and it logged perfectly.

I have used a crystal of 16 Mhz at the beginning but now i have a 12 Mhz crystal and is also not working.

If somebody have any idea, please shoot quickly before i deside to buy another atmega8. (none are cheap in my country).

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

Post by epsilon_da » Wed Oct 15, 2008 5:06 am

Please note that i am new to atmel products and the FUSEs concept is very new to me. It is possible that i am burnning wrong the fuses, but i dont think so:

FUSE Calculator: http://www.engbedded.com/cgi-bin/fc.cgi/
FUSEs: H:0xC9 L:0xEF




I have read in this forum about a serial debugging method.
But i dont know how to do it.
Can somebody point me to some instructions?

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

Post by epsilon_da » Wed Oct 15, 2008 5:14 pm

Finally after a good night of sleeping, i have solved the problem.

It was that i was using an updated version of the driver (usbdrv folder) with an old version of usbconfig copied from HIDKeys.

I discovered that by copying the usbconfig template and setting a minimalitic vendor hardware. (the same as above but without the report).

Now it worked perfectly with 12 Mhz and with 16 Mhz.



Now i would like to know why a so minimalistic code gives 1600 bytes of programm memory. I am using ATmega32 and i have already 2.5k used.

Can it be the compiler? or is the natural size of AVR-USB?

gert
Rank 1
Rank 1
Posts: 27
Joined: Sat Oct 20, 2007 5:58 pm

Post by gert » Wed Oct 15, 2008 7:49 pm

Hi epsilon_da

what do you mean with "minimalistic code"? Could it be that you never opened the folder usbdrv?

/Gert

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

Post by epsilon_da » Wed Oct 15, 2008 8:35 pm

jajajjaja.

I mean that to test AVR-USB with certain uC, "minimalistic" is the minimum code required, or at least not bloated.

Grendel
Rank 4
Rank 4
Posts: 167
Joined: Sat Dec 16, 2006 9:53 pm
Location: Oregon, USA
Contact:

Post by Grendel » Thu Oct 16, 2008 12:10 am

A plain 1N4729A seems to be a 1W diode, these have proven in the past to cause problems. Try using a 1N5227B-T or any 3.6V Z diode w/ 500mW max. power spec.

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

Post by epsilon_da » Thu Oct 16, 2008 2:55 am

Good to know for future designs.
I have read somewhere here in this forum about the low responde and big current with 1 W zenners.

But the zenners in the schematics are not what i used i just picked the first 3.6V zenner that i found, i should remove the partid from the schematic.

The zenners that i have actually buyed are
BZX55C 3.6V
in the same 1N4148 package. and should be 500mW because i asked for it, jeje. And thoose in the schematics are not selled here.

apollononnno
Rank 1
Rank 1
Posts: 25
Joined: Wed Jul 23, 2008 5:31 am
Location: JAPAN

About the resistance of the pulling up

Post by apollononnno » Thu Oct 16, 2008 1:21 pm

I tried it about 5V and the resistance value of the pulling up how many it was.
A method to join LED and 1.5kohm with a voltage descent of 1.7v together in series from 5v in that.
Pass 2.2kohm from 5v, and connect 5.1kohm to GND; and a method to connect to D- through 1.2kohm from a point pushed by just that much.
They got a good result.

If there is it only about pulling up, it is settled by a comparatively simple method.

However, there is zener diode of 3.6V to clamp it to 3.3V when I consider an avr drive signal of 5v.

However, the part cannot expect the normal movement if I clamp it with the lower voltage in a low current domain when, for example, it is lower than 2.7v.

Is the arrangement of 2 and 3 of USBCONN in the circuit of "circuit.jpg" right?

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

Re: About the resistance of the pulling up

Post by epsilon_da » Fri Oct 17, 2008 2:49 am

apollononnno wrote:Is the arrangement of 2 and 3 of USBCONN in the circuit of "circuit.jpg" right?


It just works. :P

Esmeralda
Posts: 1
Joined: Thu Jun 11, 2009 8:55 am

Re: [SOLVED] ATmega32 is failing to receive the address

Post by Esmeralda » Thu Jun 11, 2009 9:06 am

thanks a lot...u people really solved my problem

Post Reply