1

I'm trying to start a connection from my Arduino Mega ADK to my Android but I keep getting the error below whenever I try to acc.powerOn()

Error: OSCOKIRQ failed to assert

This is the firmware that I'm trying to run:

#include <Wire.h>
#include <Servo.h>

#include <Max3421e.h>
#include <Usb.h>
#include <AndroidAccessory.h>

int led = 13;

int EnableMotors = 22;

int Motor1FW = 24;
int Motor1RW = 26;

int Motor2FW = 28;
int Motor2RW = 30;


AndroidAccessory acc("FRBB",
             "UgvBr",
             "DemoKit Arduino Board",
             "1.0",
             "http://www.android.com",
             "0000000012345678");



// the setup routine runs once when you press reset:
void setup() {

  // Setting Serial at 115200 bps
  Serial.begin(115200);

  // initialize the digital pin as an output.
  pinMode(led, OUTPUT);

  // Set up motor configs
  pinMode(EnableMotors, OUTPUT);
  pinMode(Motor1FW, OUTPUT);
  pinMode(Motor1RW, OUTPUT);
  pinMode(Motor2FW, OUTPUT);
  pinMode(Motor2RW, OUTPUT);

  // Powering the accessory
  acc.powerOn();             ///// <<<<<<<<<<< ERROR

}

// the loop routine runs over and over again forever:
void loop() {

  if(acc.isConnected()){

    digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
    digitalWrite(EnableMotors, HIGH);
    digitalWrite(Motor1FW, HIGH);
    digitalWrite(Motor2FW, HIGH);

    delay(2000);

    digitalWrite(led, LOW);   // turn the LED on (HIGH is the voltage level)
    digitalWrite(EnableMotors, LOW);
    digitalWrite(Motor1FW, LOW);
    digitalWrite(Motor2FW, LOW);

    delay(2000);
  }

}

I've been looking everywhere and I couldn't find a solution to this problem yet. I also tried the DemoKit with Arduino.app on 1.0.1, but still the same issue. I'm developing it using Mac, but I don't think that it is a problem.

For testing purposes, I uploaded a code to blink the LED, and it worked just fine.

4 Answers 4

9

Spent a good 8 hours having the exact same problem. Seems like the Max3421e.cpp is faulty. Try replacing:

boolean MAX3421E::reset()
{
  byte tmp = 0;
    regWr( rUSBCTL, bmCHIPRES );                        //Chip reset. This stops the oscillator
    regWr( rUSBCTL, 0x00 );                             //Remove the reset
    while(!(regRd( rUSBIRQ ) & bmOSCOKIRQ )) {          //wait until the PLL is stable
        tmp++;                                          //timeout after 256 attempts
        if( tmp == 0 ) {
            return( false );
        }
    }
    return( true );
}

with

boolean MAX3421E::reset()
{
    regWr( rUSBCTL, bmCHIPRES );                        //Chip reset. This stops the   oscillator
    regWr( rUSBCTL, 0x00 );                             //Remove the reset
    while(!(regRd(rUSBIRQ) & bmOSCOKIRQ)) ;
}

In Max3421e.cpp located in the USB_Host_Shield library (in your Arduino IDE library folder). Basically the change does not allow an exit until the PLL is really stabilized.

Worked for me at least, good luck (Original hints and more about the fix here: http://arduino.cc/forum/index.php?topic=68205.0)

3
  • 1
    .. or you can use the latest version (v2.0) of the USB Host library available at github.com/felis/USB_Host_Shield_2.0
    – Sudar
    Jun 29, 2012 at 4:40
  • Thank @Sudar the only problem is that the library Google packages from their ADK documentation does not seem to contain this version but the buggy one :-/
    – domguinard
    Jul 6, 2012 at 12:17
  • This is an ugly workaound! An endless loop forever? Better would be a for() loop with a delay(1) inside and a timeout of 100ms until the chip is reset.
    – Elmue
    Jan 14, 2021 at 21:09
4

Use USB_Host_Shield_2.0 library with Arduino Mega ADK.

https://github.com/felis/USB_Host_Shield_2.0

IMPORTANT!!!

To use this library with the official Arduino ADK uncomment the following line in avrpins.h:

#define BOARD_MEGA_ADK
1
  • This should just be compiled into a list haha, I've had this problem a few times and all but the selected answer seems to have worked at least once. I'm sure I'll run into that one someday as well... Mar 20, 2013 at 15:16
2

"OSCOKIRQ failed to assert" generally happens when the Max IC inside the board is not working properly. This can happen in two scenarios

  • The Maxim IC is not getting enough power. (In this case, try connecting an external power source to your board)
  • There is some problem in the circuit around Maxim IC. If this is the case, then you might have to replace the board.

So first try connecting an external power source and see if this solves it. Otherwise you might have to replace the board.

1

Super simple for me (with the same issue), just add a delay before acc.powerOn()

the example I saw added 100, but I decided boot up is fast enough for 500. i.e.

void setup()
{
  // set communiation speed
  Serial.begin(9600);
  pinMode(LED_PIN, OUTPUT);
  delay(500);
  acc.powerOn();
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.