Can CuHead WiFi Shield be used with Arduino Mega?

From LinkSprite Playgound
Revision as of 13:40, 12 February 2013 by Jingfeng (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

First of all, LinkSprite does have a dedicated WiFi shield for Arduino Mega, CuHead WiFi Shield for Arduino Mega.

But if you want to use Cuhead WiFi for Arduino on Arduino Mega. It's a little bit involved. Please read the following:

To make the WiShield work on mega follow the NKC tutorial on wiring up the Ethernet shield http://mcukits.com/2009/04/06/arduino-ethernet-shield-mega-hack/ and make the following changes to spi.h (in hardware\libraries\wishield):


<syntaxhighlight lang="c">

  1. define SPI0_SS_BIT BIT0

...

  1. define SPI0_SCLK_BIT BIT1

...

  1. define SPI0_MOSI_BIT BIT2

...

  1. define SPI0_MISO_BIT BIT3

...

  1. define SPI0_Init() PRR0 = 0x00;\
                                                    DDRB  |= SPI0_SS_BIT|SPI0_SCLK_BIT|SPI0_MOSI_BIT|LEDConn_BIT;\
                                                    DDRB  &= ~SPI0_MISO_BIT;\
                                                    PORTB = SPI0_SS_BIT;\
                                                    SPCR  = 0x50;\
                                                    SPSR  = 0x01

...

  1. define ZG2100_CS_BIT BIT0

...

  1. define LEDConn_BIT BIT5

</syntaxhighlight>


The Mega not only remapped the SPI pins, it also remapped the interrupt pins. The ZeroG board triggers an interrupt when it needs the host to do something. This is why the WiShield would init, and then nothing else. If you attach a scope or a LED to the WiShield interrupt pin (pin2/int0), you can see it going low but never getting serviced.

On the Duemilanove, Arduino Pin 2 goes to INT0/PD2 on the ATMega328. On the Mega, Arduino Pin 2 goes to PE4, which is not an interrupt at all.

(1) Bend out pin 2 on the WiShield similar to how pins 10,11,12,13 are bent out. (2) Jumper this pin on the WiShield to pin 21 on the Arduino Mega. (3) In "WiServer.cpp" and "WiShield.cpp" change "attachInterrupt(0, zg_isr, LOW);" to "attachInterrupt(2, zg_isr, LOW);". This may be counterintutive, but from the documentation, it seems the Arduino development environment maps interrupt pin 2 to 21. See http://www.arduino.cc/en/Reference/AttachInterrupt for details.

For extra credit, if you don't like mangling the pins on your beautiful WiShield, connect the jumpers and turn pins 2,10,11,12,13 into high-impedance inputs. Note this means you can't use them for other purposes but they can remain electrically connected.


<syntaxhighlight lang="c"> pinMode(2, INPUT); pinMode(10, INPUT); pinMode(11, INPUT); pinMode(12, INPUT); pinMode(13, INPUT); </syntaxhighlight>