Page 1 of 1

Connection fails periodically, worse with EEPROM

Posted: Fri Oct 02, 2009 6:14 am
by Alan Chatham
So I'm building a guitar-controller thing (a USB version of the http://www.OpenChord.org controller), and I'm trying to use V-USB to do it. I've got it working about halfway... Basically, things work fine, the controller is noticed by Windows, you can access it just fine.
I'm using an ATMega168 with the zener diode setup, implementing the controller as an HID device.

I'm not going to include my whole code, since it's super long, but it basically goes like

Code: Select all

 
main()
{
    Setup stuff for the guitar controller itself
    Setup the USB communication stuff
    while(1)  // during this, I'm doing a bunch of USBPoll()'s throughout
    {
          Figure out what the person is pressing on the guitar
          Translate that into a data structure that holds values for which virtual controller buttons are pressed
          Using that struct, setup and send the proper USB packet
    }
}


I have two problems:

1, not so horrible, after 10 to 30 minutes, it loses connectivity, but the microcontroller is NOT experiencing a reset. I think this is an EMI problem, but I'm not sure. I'm working on that part. If anyone has had similar experience/good insights on why a USB HID device loses connectivity from time to time, and how to deal with it, if they could please share their experience, I would greatly appreciate it. Also, I'm kinda a beginner to all this stuff, so if someone could briefly explain what USBPoll() does in plain English, as well as maybe a brief explination of what usbSetInterrupt does?

However, number 2, what I really can't figure out and need some help on, is this:
I'm storing patterns (like chords, so you play a chord, the guitar reads that, and registers it as one button press) in the EEPROM so you can reprogram the patterns in the guitar itself and store that over power-down. That part all works more or less fine. However, I also need to check a control block to make sure that there is good data in the EEPROM during the guitar initialization part of the code. This is where I run into problems...
During the guitar initializing sequence, before starting anything with USB, I've got the following code

Code: Select all

   // Make sure we have sensible data in our EEPROM for our buttonStringPressed arrays
   // So we check if our checkString has been set correctly -
   char localCheckBlock[4];
   // this next line is the problem...
***   eeprom_read_block( (void*)&localCheckBlock, (void*)&globalCheckString, 4);

   char testBlock[4] = {0xA, 0xB, 0xA, 0xC};

   if (memcmp( (void*)&localCheckBlock, (void*)&testBlock, 4))
   {
      // set the test block for next time
      eeprom_write_block( (void*)&testBlock, (void*)&globalCheckString, 4);

      setEepromToDefault(); // This function loads in a default button pattern configuration
   }

If I comment out that starred line in the code, things run fine. However, include that line, and all the sudden, the USB connectivity becomes extremely unstable. Most of the time, it won't connect, or connects briefly, or connects but doesn't register any button presses. Any ideas of why this one EEPROM read, BEFORE any USB connection is established, could break things this way?

Sorry this post is so long, but thanks for reading it, and thanks so much for any response!

Re: Connection fails periodically, worse with EEPROM

Posted: Wed Oct 07, 2009 2:12 am
by Alan Chatham
So, I figured out I don't need that part of the code. I'm just giving those EEPROM stored arrays default values so they can be programmed during programming anyhow. Since the controller gives you a way to re-program itself internally, if the EEPROM is uninitialized, it's not a problem since the user can just program it themselves. Thanks, though, Christian; reading the connectivity issues with other people, I'm glad to know about that half-reset state the AVR can slip into...