[SOLVED] Using Ethernet & ADK's USB Host in same SPI interface...

Hello friends,

I have Mega ADK (for Android) with WIZ820io (Ethernet shield) in hand.
What i want to do is to connect it with Android device via USB for sending controlling command, then passing data from ADK via ethernet shield (TCP/IP) to external device.

Android device <--------> Mega ADK (+Ethernet shield) <----------> External device
usb (send command) tcp/ip (send data)

Problem:
Both ethernet shield and the ADK’s USB Host use the same SPI interface
50 (MISO), 51 (MOSI), 52 (SCK), and 53 (SS)
, so without bus arbitration it doesn’t seem to work :frowning:

Anyone has idea? Is bus arbitration possible in my case?
Or what’s the best solution i should go?

Newbie

The Ethernet shield is not using SS on pin 53 but on pin 10. The rest of the SPI pins are shared and made to be used by more than one device. As you're not using a standard Ethernet shield but not providing a link to the product page or datasheet, your situation may differ but we cannot help you any further. I cannot find a shield but only a breakout board called WIZ820io. For the breakout board your free to set the SS to any pin you like.

Thank you for your reply pylon!!

The reason why i use those pins are already mentioned here; (not in ICSP header)
http://forums.adafruit.com/viewtopic.php?f=31&t=22175

and schematic i’m using as reference is;

My Ethernet shield - WIZ820io
http://www.wiznet.co.kr/sub_modules/kr/product/product_detail.asp?cate1=5&cate2=42&cate3=0&pid=1160#tab

For SS pin of USB host interface issue, it was programmatically set by Max3421e libarary,
which you may see it in /libraries/USB_Host_Shield/Max3421e_constants.h

#if defined(__AVR_ATmega1280__) || (__AVR_ATmega2560__)
  #define SCK_PIN   52
  #define MISO_PIN  50
  #define MOSI_PIN  51
  #define SS_PIN    53
#endif

Pls let me know if my understanding is not correct :frowning:

You're correct that the MAX3421e is connected internally to the SS pin 53, that's why the software is using that too. But the standard Ethernet library is expecting the SS of the ethernet chip (WIZ5100, although in your case it's a WIZ5200, the chips seems to be similar enough to use the same software) at pin 10.

The original Arduino Ethernet Shield in the newer revisions use the ICSP header to connect SCLK, MISO and MOSI because on the ICSP header these signals are always available on the UNO and on the MEGA2560 series. On the pin rows the position of these signals vary on the different models. But SS is not on the ICSP header so it's fixed on pin 10 and used in the software accordingly.

As you don't have a shield but a breakout board, just connect your SS pin to pin 10 of the Arduino and everything will work.

OMG!!!!!

It's working now !!!!!!!!!!!!!! Thank you so much PYLON!!, you are really my pylon XD XD XD XD

Let me explain a bit why it had been not working. Previously, to make SS works on pin 53, i had modified W5200 library (new w5100.h) from

#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
  inline static void initSS()    { DDRB  |=  _BV(4); };
  inline static void setSS()     { PORTB &= ~_BV(4); };
  inline static void resetSS()   { PORTB |=  _BV(4); };

To

#if defined(__AVR_ATmega1280__)
  inline static void initSS()    { DDRB  |=  _BV(4); };
  inline static void setSS()     { PORTB &= ~_BV(4); };
  inline static void resetSS()   { PORTB |=  _BV(4); };
#elif defined(__AVR_ATmega2560__)
  inline static void initSS()    { DDRB  |=  _BV(0); };
  inline static void setSS()     { PORTB &= ~_BV(0); };
  inline static void resetSS()   { PORTB |=  _BV(0); };

ฺฺBy this change, i can use ethernet with no problem but...... when it comes to integrate with ADK USB Host, it will no longer work. So i follow your suggestion by changing it back and also apply SS to pin 10 instead of 53 as below.

[Arduino] Pin52 - SCLK [WIZnet820io] [Arduino] Pin50 - MISO [WIZnet820io] [Arduino] Pin51 - MOSI [WIZnet820io] [Arduino] Pin10 - nSS [WIZnet820io]

Now it works like a CHARM !! :stuck_out_tongue_closed_eyes: :stuck_out_tongue_closed_eyes: Thank you so much, i had been stuck on this problem for 2 days but with your help, i can solve it eventually :D :D

Newbie++