Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 1 of 1

Thread: Teensy 3.1 with Felis USB Host library hub issue

  1. #1
    Senior Member
    Join Date
    Dec 2013
    Posts
    131

    Teensy 3.1 with Felis USB Host library hub issue

    Hi there,

    I'm trying to get Teensy 3.1 as a USB host communicating with multiple USB MIDI devices.

    I'm using the Mini USB Host shield based on the MAX3421E chip: http://duinopeak.com/store/index.php...&product_id=47

    Using the Felis USB Host Library 2.0: https://github.com/felis/USB_Host_Shield_2.0

    I also have the high speed SPI library installed and included as recommended: https://github.com/xxxajk/spi4teensy3

    I have a single USB MIDI device working perfectly and am receiving data as intended.

    However, when using the example of using multiple devices via a hub (Code below), I don't get anything from either device.
    I have 2 MIDI devices plugged into a hub, and the hub plugged into the Host shield. I have tried powering the hub, and I have tried multiple hubs.

    Here is the code I'm using:


    Code:
    /*
     *******************************************************************************
     * USB-MIDI to Legacy Serial MIDI converter
     * Copyright (C) 2012-2016 Yuuichi Akagawa
     *
     * Idea from LPK25 USB-MIDI to Serial MIDI converter
     *   by Collin Cunningham - makezine.com, narbotic.com
     *
     * This is sample program. Do not expect perfect behavior.
     *******************************************************************************
     */
    
    #include <usbh_midi.h>
    #include <usbhub.h>
    
    // Satisfy the IDE, which needs to see the include statment in the ino too.
    #ifdef dobogusinclude
    #include <spi4teensy3.h>
    #include <SPI.h>
    #endif
    
    //#ifdef USBCON
    //#define _MIDI_SERIAL_PORT Serial1
    //#else
    //#define _MIDI_SERIAL_PORT Serial
    //#endif
    //////////////////////////
    // MIDI Pin assign
    // 2 : GND
    // 4 : +5V(Vcc) with 220ohm
    // 5 : TX
    //////////////////////////
    
    USB Usb;
    USBHub  Hub1(&Usb);
    USBH_MIDI  Midi1(&Usb);
    USBH_MIDI  Midi2(&Usb);
    
    void MIDI_poll();
    void doDelay(unsigned long t1, unsigned long t2, unsigned long delayTime);
    
    void setup()
    {
      //_MIDI_SERIAL_PORT.begin(31250);
    
      if (Usb.Init() == -1) {
        while (1); //halt
      }//if (Usb.Init() == -1...
      delay( 200 );
    }
    
    void loop()
    {
      unsigned long t1;
    
      Usb.Task();
      t1 = micros();
      if ( Usb.getUsbTaskState() == USB_STATE_RUNNING )
      {
        MIDI_poll();
      }
      //delay(1ms)
      doDelay(t1, micros(), 1000);
    }
    
    // Poll USB MIDI Controler and send to serial MIDI
    void MIDI_poll()
    {
      uint8_t outBuf[ 3 ];
      uint8_t size;
    
      do {
        if ( (size = Midi1.RecvData(outBuf)) > 0 ) {
          //MIDI Output
          Serial.println(outBuf[0]);
          //_MIDI_SERIAL_PORT.write(outBuf[0], size);
        }
      } while (size > 0);
      do {
        if ( (size = Midi2.RecvData(outBuf)) > 0 ) {
          //MIDI Output
          Serial.println(outBuf[0]);
          //_MIDI_SERIAL_PORT.write(outBuf, size);
        }
      } while (size > 0);
    }
    
    // Delay time (max 16383 us)
    void doDelay(unsigned long t1, unsigned long t2, unsigned long delayTime)
    {
      unsigned long t3;
    
      if ( t1 > t2 ) {
        t3 = (0xFFFFFFFF - t1 + t2);
      } else {
        t3 = t2 - t1;
      }
    
      if ( t3 < delayTime ) {
        delayMicroseconds(delayTime - t3);
      }
    }

    Any help would be greatly appreciated.

    Thanks,

    Matt
    Last edited by mattomatto; 02-02-2017 at 02:46 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •