Go Down

Topic: USB Host Shield with Mega1280 (Read 1 time) previous topic - next topic


Hi guys,

Has anyone tried getting the Sparkfun USB Host Shield to work with Mega 1280?

Currently, my aim is to interface a 2D Unitech MS337 Barcode Scanner with the Mega 1280. I intend to use the code from Schogini but the USB Host shield is not working right. I am using Oleg's codes.

It keeps giving "Error: OSCOKIRQ failed to assert", though I have defined "define MAX_GPX 7 define MAX_RESET 8" and power the shield by external power supply.

I understand the SPI pins on Mega1280 are 50 (MISO), 51 (MOSI), 52 (SCK), 53 (SS). Do I need to connect these to pins 13,12,11,10 on USB Shield since:

#if defined(__AVR_ATmega1280__)
 #define SCK_PIN   52
 #define MISO_PIN  50
 #define MOSI_PIN  51
 #define SS_PIN    53
#if  defined(AVR_ATmega168) || defined(AVR_ATmega328P)
 #define SCK_PIN   13
 #define MISO_PIN  12
 #define MOSI_PIN  11
 #define SS_PIN    10

Am I missing something? Would greatly appreciate your help.


Jan 05, 2011, 07:42 pm Last Edit: Jan 05, 2011, 07:45 pm by niels.brouwers Reason: 1
Did you modify the shield? Since the SPI pins on the mega are in a different location, you need to either rewire the shield. From circuits@home:

If you are planning to use this shield with one of the "Big" Arduinos, like Mega or 2560, SPI signals would have to be rerouted, i.e., pins 13,12,11 of the shield should be connected to pins 50,52,51 of the Mega.

If you already did this, note that the code assumes that you rewire SS (slave select) to pin 53, but the above statement tells you to only rewire miso, mosi and clock. Therefore, if you followed this you are left with SS still connected to pin 10. The code should therefore be:

Code: [Select]

#if defined(__AVR_ATmega1280__)
 #define SCK_PIN   52
 #define MISO_PIN  50
 #define MOSI_PIN  51
 #define SS_PIN    10

note that last line.

Alternatively you can write some code to do software SPI by manually bit-banging pins 11-13, which should work too and isn't complicated. I used this to get an SPI-driven LCD shield working on the mega:


Let me know if this works for you.



The code in USB Host library supports soon to be released version 2.0 of the shield (see picture). It gets SPI via ICSP connector, which happens to be in the same place on all official Arduinos and also many clones. The rest of the signals are in the same place (pins 9 and 10) since these pins are on the same header on all Arduino variants also.




Hi Inopia & Felis,

Thank you for your replies and updates.

I left the SPI definition as per the original code, rerouted the wires but left 10 alone, and the examples worked alright now.

Though I am still trying to get the 2D barcode scanner to work. Probably need to look into the library.

Thx guys!!

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131