Posts

Updated USB Host library uploaded to gitHub

No SPI

No SPI

New version of USB Host library has been uploaded to gitHub. I managed to find a couple of bugs and solve some compatibility issues. The biggest change, however, has been made on the very lowest level of the library – SPI transfers between Arduino and MAX3421E registers.

From the beginning, USB Host firmware relied on Arduino Playground SPI library. Starting from version 0018 of Arduino IDE, this library became part of the distro. Two versions after that, Arduino team decided to re-write SPI library, among other things changing function names. As a result, USB Host code became incompatible with “stock” SPI library. To remedy the situation, I incorporated SPI routines directly into MAX3421E support code. The new code is independent of Arduino SPI library and builds correctly on “old” (i.e. 0017) and “new” (0021) versions of Arduino IDE. In addition to that, new code accounts for SPI pinout difference between Arduino variants and works on both Atmega 328 and Atmega 1280/2560 based boards. ( Note: the current rev1.x USB Host Shield still needs to be modified to work with Megas )

The new library can be downloaded from USB Host Shield gitHub repository. If you are upgrading existing installation of the library, please make a backup copy before downoading! I checked it against all code examples and USB devices in my possession and everything works without a hitch. However, code written with tight timing may stop working because of speed difference since new SPI routines are slightly faster.

As you can see in the title picture ( click on it to enlarge ), the line #include "Spi.h" is no longer needed. In next several days I’m going to update all USB examples on this site to match the new code. If you have any any problems with the library, please let me know!

Oleg.

52 comments to Updated USB Host library uploaded to gitHub

  • Einar

    I get “Error: OSCOKIRQ failed to assert” when I plug in my Logitech LX710 combo with the new library :S

  • Einar

    hold on, link didn’t work… this one -> http://www.sparkfun.com/products/9947

    • I haven’t checked the code against Sparkfun shield, it can be incompatible. Try this: in Max3421e_h comment out line 41, which reads ‘SPSR = 0x01;’, then recompile and see if an error persists.

      • Einar

        yep, still error.

        • I can’t replicate the error on my shields, could be specific to SF variant. Try to run board test from the examples and see where it breaks – you should be able to continue past OSCOKIRQ error.

          • Einar

            turns out the 5v regulator blew, found out because my computer shut down when I connected the usb cable when Vin was connected to 8v. I’m pretty sure that’s the culprit 😛

  • Harry

    In which way the hostshield must be modified to work with Arduino Mega (Atmeaga 2560)? I read the hardware-troubleshootig and searched for it, but couldnt find anything.

    • Look at the schematic of say Duemilanove and Mega. The SPI pins – SCK, MISO, MOSI are on pins outside the shield when you connect it to Mega. You need to solder wires to SPI pins on the shield and connect them to SPI pins on Mega.

  • Harry

    I want to to connect a WiiMote-Controller with the Arduino. I allready have the rev1.21 USB Host shield and a Arduino Mega (Atmega2560). I tried to Upload the wiiblue.pde with the updated header-files, but i have erros while compiling.(I deleted the line including SPI.h; in arduino0020)
    The error while compiling is:
    arduino-0020\libraries\Wiiblue/ch9.h:102: error: ‘byte’ does not name a type
    and many of the same but in different lines.

  • Harry

    tryed to fix the error with

    typedef unsigned char byte;

    ind the ch9.h

    Uploading file to Arduino worked.

  • Harry

    now i am getting the “OSCOKIRQ failed to assert” error.

  • Martin

    Hello Oleg,

    in your examples you often use “qep_port.h”. Which library must I include to get the required files?

    Thank you
    Martin

  • Einar

    btw for those of you who have sparkfun board will need to edit the max3421e_constsnts.h file to have.

    #define MAX_GPX 7
    #define MAX_RESET 8

    • Jeff

      The fix to the Max3421e_constants.h file worked for me. I was previously getting the ‘OSCOKIRQ failed to assert’ error message.

      Thanks

  • Harry

    Hy,

    I connected the Arduino mega now with the USB_Host shield.
    But I am getting the “OSCOKIRQ failed to assert” error.
    I mesured the crystal and the signal was ok. (sinewave with 4V peak to peak).
    I do not undaerstand what the errornotice means.
    Any ideas?

  • Harry

    I managed to get a Arduino328.
    I had to change the includes to run the USB_Desc sketch.
    Now i have the descriptors.
    Is it right, that i have to change something in the Wiiblue.pde
    after /* CSR Bluetooth data taken from descriptors */ ?
    The only difference to your example is the
    VendorID
    ProductID
    RevisionID

    What are they called in the Wiiblue sketch?
    I guess VID is VendorID but what is CSR_VID_HI and _LO ?

    • Tomo

      You’re right.
      Vendor ID –> CSR_VID_LO, CSR_VID_HI
      Product ID –> CSR_PID_LO, CSR_PID_HI
      Where the IDs are 2Bytes long, so high byte need to be set to _HI and low byte will be set to _LO.
      Eg. when you got “Vendor ID: 0A12”, you set CSR_VID_LO=0x12 and CSR_VID_HI=0x0a.

  • Harry

    thank you!!,
    the programm “blueutils” worked now, and i was abel to connect my wiimote as hci device.
    I tested the programm “wiiblue” to get sensor information from the wiimote.
    But my programm makes no progress after “CSR Initialised”.
    I actuelle wasnt able to get the same CSR BT-Stick as described on the website. So i bought any cheap dongl which has Rfcomm protocol aviable too.
    Is that a problem in any way?, because in that programm only L2CAP layer is used.

  • yvest

    Any idea why I can get the descriptors for any high speed device I plug in ( flash drives, etc), but nothing for any lower speed devices like a mouse?

    I’m using the descriptor parser example and all I get is ‘Start’ when I plug in my mouse.

    Thanks!

    • I double-checked descriptor parser with my usual set of devices, low and full-speed (one of them being USB 1.0) – everything seems to work fine. Which shield/Arduino variants are you using?

      • yvest

        I’m using a sparkfun shield (the updated version) with a UNO. Any suggestion of what I should be looking for?

        • yvest

          I verified the the power supplied by the shield to the USB devices and I noticed that it was only 3.3V… Connecting a 9V power supply to the Arduino (as opposed to powering the Arduino from USB) took care of this issue. I can now get the descriptor for my mouse!

          Thanks for all the work on the design and libraries!

          Regards!

  • andrew

    I have an arduino nano v3, and the mini usb host board from circuits@home. I am using 3.3v-5v logic converters. It is wired exactly how the coding in max3421e_constrants.h calls for. powered via regulated 3.3v.

    running board_test results in “Error: OSCOKIRQ failed to assert”

    all wires checked – new code downloaded – no spi library, as instructed. compiles with out errors. error persists.

    Ideas? Thanks in advance!
    -andy

  • andrew

    I was testing in arduino IDE – and commented out some of the tests to isolate the SPI long test.

    still fails

  • Hi, I have a SparkFun USB shield with arduino duemilanove, I get the error: <> , I tried to change #define MAX_GPX 7
    #define MAX_RESET 8, and nothing happens. The arduino is external powered, If I try to make many resets, sometimes it works without error, and I was able to see that touching pins near gnd,5V,3.3v if I push in that zone with a finger, it works and start without errors (quite weird, no?). At this point I thing it might be something related the power I egt into? I run the arduino with external 12V power… am I doing it wrong?

  • I menat I get the Error: OSCOKIRQ failed to assert

  • I meant I get the Error: OSCOKIRQ failed to assert

  • sri

    Hi, I have the latest Circuits@Home host shield and I am running the board_test program on a Duemilanove (328p). I have a 9v supply from an AC adaptor and I am able to check that the 5v and 3.3v are present on the headers with the USB jack not plugged in (so it is clearly getting the power from the adaptor).

    I can’t get past the OSCOKIRQ assert error when the line Max.powerOn() is executed. After that the board hangs. I am running with the stock settings and I downloaded the library recently (file dates show Feb 24).

    Any help greatly appreciated!

    • Do you have all included headers soldered in place? Also check that they mate with Duemilanove connectors properly.

      • sri

        I’ve soldered all the headers. Eyeballing it and feeling the headers, it seems the connections are good. I tested for continuity for the ICSP pins and digital pins 9 and 10 with the Arduino solder joints. What else should I test for? I am running on Arduino 22 IDE on a Max OS X. The shield version is dated Dec 2010. Thanks for your help.

        • What kind of testing equipment do you have access to? Also, how far does the board_test go – can you see anything past “OSCOKIRQ failed to assert” message?

          • sri

            I could borrow a friend’s scope. The board_test doesn’t go further than the assert message. I could add prints to see where it stops within the powerOn method if that will help. When I commented the powerOn call, it failed with a “Reading REVISION register…Die revision invalid. Value returned: 00”.

          • if you comment out powerOn(), you’ll break MAX3421E initialization – by default, it operates in half-duplex SPI and SPI routines in the code are written fro full-duplex SPI. There is only one place in powerON() which may loop forever – it is line 215, while(!(regRd( rHCTL ) & bmSAMPLEBUS )); . Comment out this line and see what happens.

            Most likely, SPI is not working correctly. If you can get a scope, take a look at this article -> http://www.circuitsathome.com/mcu/arduino/usb-shield/troubleshooting-arduino-usb-host-shield to see how proper SPI signals should look like. Also, if you can, check the shield with another Arduino board.

  • sri

    I am going to check the soldering again. I suspect there is a bad connection. It can’t read anything, basically regRd() is reading 0 when I try printing the output of regRd(rPINCTL). I’ll let you know. Thanks again.

    • sri

      That was it!! A bad connection (actually my miserable soldering skills). The board test passed. Thanks for the help, Oleg! On to making the Duemilanove talk to a Nook using ADB.

  • daf

    Hi,

    I just bought the SF USB Host Shield (http://www.sparkfun.com/products/9947)

    When I tried to execute the board test sample I got the following error :

    Error: OSCOKIRQ failed to assert

    Circuits At Home 2010
    USB Host Shield QC test routine

    Press any key to continue…
    Reading REVISION register…Die revision invalid. Value returned: 00
    Test FAILED*!*
    Test Halted.
    0x55 pattern is being transmitted via SPI to aid in troubleshooting
    Press RESET to restart test

    I’am using USB Host library downloaded with the name felis-USBHostShield-a59ba5b.zip.

    I tried to change MAX_GPX and MAX_RESET to #define MAX_GPX 7 #define MAX_RESET 8 but problem still persists.
    I use an ATMEGA 2560 + USB and an external +9V power supply.
    (SPI pins are correctly connected according to atmega2560 specification)

    Thanks for your help !

  • dimitri

    I get this error:

    Circuits At Home 2011
    USB Host Shield Quality Control Routine
    Reading REVISION register… Die revision invalid. Value returned: 00
    Unrecoverable error – test halted!!
    0x55 pattern is transmitted via SPI
    Press RESET to restart test

    I am using the Circuits@Home USB Host Shield Rev. 2 date 07 Dec 2010 with an Uno

    Any Thoughts on what it maybe?

  • dimitri

    No I have just the “Shield” headers attached… the my brain just went….. Ahhhhhhhh…

    Thanks!

  • dimitri

    it is up thanks!

  • Michael

    Whenever I try to upload the PS3BT sketch to my Mega2560, I get an error that says “‘USB’ does not name a type”. What’s happening here?

  • CHulla

    I am getting an error on running board_qc. Using Sparkfun latest USB HOST Shield and Code from USB_Host_Shield_2.0 by felis.
    https://www.sparkfun.com/products/9947#comment-54086d7bce395f62358b456c
    https://github.com/felis/USB_Host_Shield_2.0

    Circuits At Home 2011
    USB Host Shield Quality Control Routine
    Reading REVISION register… Die revision invalid. Value returned: 00
    Unrecoverable error – test halted!!
    0×55 pattern is transmitted via SPI
    Press RESET to restart test

    I dont have 2*3 ICSP connector on the board. What should i do next?
    Thanks

  • usdoz

    i’m using example from USB host library and get this error

    In file included from C:\Users\firdauz\Documents\Arduino\libraries\generic_storage-master\FAT.c:4:0:
    C:\Users\firdauz\Documents\Arduino\libraries\generic_storage-master/FAT/FatFS/src/ff.c: In function ‘f_write’:
    C:\Users\firdauz\Documents\Arduino\libraries\generic_storage-master/FAT/FatFS/src/ff.c:2873:1: error: unable to find a register to spill in class ‘POINTER_REGS’
    }
    ^
    C:\Users\firdauz\Documents\Arduino\libraries\generic_storage-master/FAT/FatFS/src/ff.c:2873:1: error: this is the insn:
    (insn 212 211 213 33 (set (reg:HI 26 r26)
    (reg/f:HI 194)) C:\Users\firdauz\Documents\Arduino\libraries\generic_storage-master/FAT/FatFS/src/ff.c:2830 82 {*movhi}
    (nil))
    C:\Users\firdauz\Documents\Arduino\libraries\generic_storage-master/FAT/FatFS/src/ff.c:2873: confused by earlier errors, bailing out

    would you like help me to solve this ?
    please