Question

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.

Was it helpful?

Solution

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)

OTHER TIPS

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

"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.

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();
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top