Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compatibility with USB Host Shield 2.0 library #7

Open
ymtoh opened this issue Jun 3, 2015 · 0 comments
Open

Compatibility with USB Host Shield 2.0 library #7

ymtoh opened this issue Jun 3, 2015 · 0 comments

Comments

@ymtoh
Copy link

ymtoh commented Jun 3, 2015

Hi,

Im facing some compatibility issue when I am using BLE Shield together with USB Host Shield 2.0

Whenever add codes to start the USB Host Shield, BLE shield will stop working.

Any idea where can i start to troubleshoot?

#include <RBL_nRF8001.h>
#include <boards.h>
#include <SPI.h>
#include <EEPROM.h>

// for USB Host
#include <adk.h>

// for BLE
static byte buf_len = 0;
byte queryDone = false;
uint32_t timer1;

// for USB Host
USB Usb;
ADK adk(&Usb, "TKJElectronics", // Manufacturer Name
              "ArduinoBlinkLED", // Model Name
              "Example sketch for the USB Host Shield", // Description (user-visible string)
              "1.0", // Version
              "http://www.tkjelectronics.dk/uploads/ArduinoBlinkLED.apk", // URL (web page to visit if no installed apps support the accessory)
              "123456789"); // Serial Number (optional)
uint32_t counter;
uint32_t sendcounter;
uint32_t timer;
bool connected;

void setup() {
  Serial.begin(57600);

  Serial.print("\r\nArduino Blink LED Started");
  if (Usb.Init() == -1) {
    Serial.print("\r\nOSCOKIRQ failed to assert");
    while (1); // halt
  }

  // Init. and start BLE library.
  ble_begin();
}

static unsigned char spi_old;

void loop()
{


  spi_old = SPCR;
    SPI.setBitOrder(LSBFIRST);
    SPI.setClockDivider(SPI_CLOCK_DIV8);
    SPI.setDataMode(SPI_MODE0);

  if(ble_available())
  {
    byte cmd;
    cmd = ble_read();

    Serial.print(cmd, HEX);

    // send out any outstanding data
    ble_do_events();
    buf_len = 0;
  }
  else {
      ble_do_events();

      if (millis() - timer1 >= 1000) { // Send data every 1s
      timer1 = millis();
      Serial.println(F("\nBLE not available"));
     }
  }

  ble_do_events();

  SPCR = spi_old;
  SPI.begin();

  buf_len = 0;

  Usb.Task();
  if (adk.isReady())
  {
    if (!connected) 
    {
      connected = true;
      Serial.println(F("\r\nConnected to accessory"));
    }
  }
  else 
  {  
   if (millis() - timer >= 1000) { // Send data every 1s
      timer = millis();
      Serial.println(F("adk not ready"));
   }
   if (connected) 
   {
      connected = false;
      Serial.print(F("\r\nDisconnected from accessory"));
    }
  } 
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant