Page 1 of 1

SOLVED! "device not recognized"

Posted: Fri Mar 12, 2010 4:56 pm
by vsovereign
I'm trying to implement hid-data example to ATtiny45.
My template project is easylogger since it uses the same controller, simple and I already made it.
It works fine. I modified the circuit a little bit.

Some datas:
frequency is 16500000 Hz
fuse high is 0xdd
fuse low is 0xe1
Note : these are the values used in the easylogger project which works.

Some mistakes I've made and corrected :

1. using usbconfig from easylogger project instead of modifying usbconfig from hid-data.
this made the device recognized...and then de-recognized after several seconds.
right now I'm using a modified (mostly port numbers) usbconfig from hid-data.

2. using the fuse values as written on the makefile of the hid-data example.
the values for ATtiny45 were the values for the tiny45 with crystal...
since my tiny45 is without crystal, I use the fuse values from the easylogger project.

Problems I have :

1. It doesn't work. 8 times out of 10, it gives the message: device not recognized.
2. two times out of 10 it works. it gives away enumeration and name.
Now, naturally I'm curious. I used a USB hub at the time. I disconnect it and tried to reconnect it.
it doesn't work : device not recognized again and again until it works again.
but it doesn't work again after I disconnect it. Very unstable and I don't know what I did wrong (or right)

My questions :

1. do you know what might have gone wrong?
2. should I modify the main.c ? because I left it alone, but this hid-data example uses ATmega168 instead of tiny45.
if yes, what should I modify?
3. I have a feeling the clocking is not correct...but I'm not really sure.
4. is there a possibility that my computer usb port is not working correctly?
5. is there a possibility that windows xp not working correctly?

Okay, that's all I can think of now. Naturally it worries me that the decive can't even be recognized.
Something very basic must've gone wrong. I just don't know what...

Thanks,

vsovereign

Re: "device not recognized"

Posted: Sat Mar 13, 2010 10:15 pm
by maxi
At a guess i'd say the calibration is not being done correctly. Take a closer look at usbconfig.h & osccal.h

Code: Select all

#if USB_CFG_CLOCK_KHZ==16500
#define USB_CFG_HAVE_MEASURE_FRAME_LENGTH   1
#include "osccal.h"
#else
#define USB_CFG_HAVE_MEASURE_FRAME_LENGTH   0
#endif
/* define this macro to 1 if you want the function usbMeasureFrameLength()
 * compiled in. This function can be used to calibrate the AVR's RC oscillator.
 */

Code: Select all

General Description:
This module contains a function which calibrates the AVR's internal RC
oscillator so that the CPU runs at F_CPU (F_CPU is a macro which must be
defined when the module is compiled, best passed in the compiler command
line). The time reference is the USB frame clock of 1 kHz available
immediately after a USB RESET condition. Timing is done by counting CPU
cycles, so all interrupts must be disabled while the calibration runs. For
low level timing measurements, usbMeasureFrameLength() is called. This
function must be enabled in usbconfig.h by defining
USB_CFG_HAVE_MEASURE_FRAME_LENGTH to 1. It is also recommended to call
calibrateOscillator() from the reset hook in usbconfig.h:
*/
#ifndef __ASSEMBLER__
#include <avr/interrupt.h>  /* for sei() */
extern void calibrateOscillator(void);
#define USB_RESET_HOOK(resetStarts)  if(!resetStarts){cli(); calibrateOscillator(); sei();}
/*
This routine is an alternative to the continuous synchronization described
in osctune.h.

Re: "device not recognized"

Posted: Sun Mar 14, 2010 1:42 am
by Osamu
If you connect other low-speed device(e.g. mouse, keyboard..) under the same hub controller, its downstream packets are broadcasted to your ATtiny45. This causes RC calibration to fail. I haven't found a clear solution yet, but there is a workaround in my code. See lib-device/osccal.c in
http://www.recursion.jp/avrcdc/cdc232.2010-02-28.zip

Re: "device not recognized"

Posted: Thu Apr 08, 2010 11:18 am
by vsovereign
hi, thanks for the answers.

I tried to put the OSCCAL into the main.c of HID_DATA and then to call it in the main program (int_main(void))
It doesn't work so far. But I maight have call it the wrong way.

The program below is how I put the OSCCAL into the main.c and how I call it in main.
Any ideas as to what might have gone wrong?

Code: Select all


/* -----------------------------------------------------------------------------*/
static void calibrateOscillator(void)
{
uchar       step = 128;
uchar       trialValue = 0, optimumValue;
int         x, optimumDev, targetValue = (unsigned)(1499 * (double)F_CPU / 10.5e6 + 0.5);
 
    /* do a binary search: */
    do{
        OSCCAL = trialValue + step;
        x = usbMeasureFrameLength();    // proportional to current real frequency
        if(x < targetValue)             // frequency still too low
            trialValue += step;
        step >>= 1;
    }while(step > 0);
    /* We have a precision of +/- 1 for optimum OSCCAL here */
    /* now do a neighborhood search for optimum value */
    optimumValue = trialValue;
    optimumDev = x; // this is certainly far away from optimum
    for(OSCCAL = trialValue - 1; OSCCAL <= trialValue + 1; OSCCAL++){
        x = usbMeasureFrameLength() - targetValue;
        if(x < 0)
            x = -x;
        if(x < optimumDev){
            optimumDev = x;
            optimumValue = OSCCAL;
        }
    }
    OSCCAL = optimumValue;
}
 
/* ------------------------------------------------------------------------- */

int main(void)
{
uchar   i;
uchar   calibrationValue;
   
   wdt_enable(WDTO_1S);
   


    calibrationValue = eeprom_read_byte(0); /* calibration value from last time */
    if(calibrationValue != 0xff){
        OSCCAL = calibrationValue;
    }
   
   /* Even if you don't use the watchdog, turn it off here. On newer devices,
     * the status of the watchdog (on/off, period) is PRESERVED OVER RESET!
     */
    //DBG1(0x00, 0, 0);       /* debug output: main starts */
    /* RESET status: all port bits are inputs without pull-up.
     * That's the way we need D+ and D-. Therefore we don't need any
     * additional hardware initialization.
     */
    //odDebugInit();
    usbInit();
    usbDeviceDisconnect();  /* enforce re-enumeration, do this while interrupts are disabled! */
    i = 250;
    while(--i){             /* fake USB disconnect for > 250 ms */
        wdt_reset();
        _delay_ms(1);
    }
   usbDeviceConnect();
    sei();
    //DBG1(0x01, 0, 0);       /* debug output: main loop starts */
    for(;;){                /* main event loop */
      //  DBG1(0x02, 0, 0);   /* debug output: main loop iterates */
        wdt_reset();
        usbPoll();
    }
    return 0;
}

/* ------------------------------------------------------------------------- */



Re: "device not recognized"

Posted: Thu Apr 08, 2010 1:18 pm
by Osamu
See usbconfig.h carefully. You have to define USB_CFG_HAVE_MEASURE_FRAME_LENGTH to 1 and include "osccal.h" here.

Re: "device not recognized"

Posted: Thu Apr 08, 2010 3:13 pm
by Guest
Osamu wrote:See usbconfig.h carefully. You have to define USB_CFG_HAVE_MEASURE_FRAME_LENGTH to 1 and include "osccal.h" here.


REALLY STRANGE! :?: :?:

I did what you said and now the device is recognized by the host!
Whatever happened?

I did not include osccal.h in the header folder.
There is nothing about calling osccal in the main program.
But now it seems to be working.

Oh I need to check if it can read/write data with hid-tool & hid-data commandline
I hope it's ok...

Re: "device not recognized"

Posted: Thu Apr 08, 2010 3:15 pm
by vsovereign
the above is written by me, lol! :D
didn't realize I was writing as a guest :mrgreen:

Re: "device not recognized"

Posted: Thu Apr 15, 2010 11:39 am
by vsovereign
Osamu wrote:See usbconfig.h carefully. You have to define USB_CFG_HAVE_MEASURE_FRAME_LENGTH to 1 and include "osccal.h" here.


hi Osamu, I managed to connect the device to the host.
I put #include "osccal.h" in the usbconfig.h just like you showed.
the device is now recognized by the host.

but now I have trouble trying to communicate with the device.
I built the host software according to the readme file with MinGW.

BUILDING THE HOST SOFTWARE
==========================
Make sure that you have libusb (on Unix) or the DDK (on Windows) installed.
We recommend MinGW on Windows since it includes a free version of the DDK.
Then change to directory "commandline" and run "make" on Unix or
"make -f Makefile.windows" on Windows.



but when I tried to create the makefile it says that in usbconfig.h the osccal.h file can't be found and failed.

I tried this before when the device was still couldn't be connected and that time everything worked fine.

any ideas how to test if any communication can be done between the device & the host?

thanks!
vsovereign

Re: "device not recognized"

Posted: Thu Apr 15, 2010 1:46 pm
by vsovereign
I managed to communicate with the device as well as sending and receiving bytes :-)

The trick is to get rid of include "osccal.h" before you compile the hidtool.
And then add it again after you finish compiling :-)

If anyone wanna know more, look at the hid-data on attiny 45 post

Re: SOLVED! "device not recognized"

Posted: Fri Jul 01, 2011 1:34 am
by CaCO3
Sorry to open an old thread again.

I am also looking to get the examples to work on an attiny85.
EasyLogger works fine, but none of the other examples.

I tried to follow the suggestions in this tread, but never got it working.

SO if one of you have a working example for a attiny, that would help me a lot.

Re: SOLVED! "device not recognized"

Posted: Fri Jul 01, 2011 3:16 pm
by CaCO3
All right, I got it working now.
As it was not a very obvious way, I documented it on my blog: http://www.ruinelli.ch/how-to-use-v-usb-on-an-attiny85
There is also patched version for download.