Pages: [1]   Go Down
Author Topic: Arduino Ethernet Shield MEGA hack  (Read 11237 times)
0 Members and 1 Guest are viewing this topic.
USA
Offline Offline
Sr. Member
****
Karma: 0
Posts: 452
Freeduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi, I published a hack on how to use the current Arduino Ethernet Shield with the new Arduino MEGA board.

http://mcukits.com/2009/04/06/arduino-ethernet-shield-mega-hack/
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 6
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Well, I was on the right track but I couldn't figure out what to edit in the file:

http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1238295170/20

Thank you so much for this.
Logged

USA
Offline Offline
Sr. Member
****
Karma: 0
Posts: 452
Freeduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I tried to make the hack work with less pin switches, meaning trying to keep pin SS where it is, in digital 10... but for some reason (that was also discussed long time ago in this forum) it doesn't work.  SS is supposed to be used only when the ATmega is a slave.  In this case it is master, but still SS is hardcoded somewhere.
Logged

0
Offline Offline
Sr. Member
****
Karma: 0
Posts: 354
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Cool!

Quick Question.
What does this code do?
Code:
#define SPI0_SS_BIT BIT2
...
#define SPI0_SCLK_BIT BIT5
...
#define SPI0_MOSI_BIT BIT3
...
#define SPI0_MISO_BIT BIT4
...
#define IINCHIP_CS_BIT BIT2

and replace them with this code:


#define SPI0_SS_BIT BIT0
...
#define SPI0_SCLK_BIT BIT1
...
#define SPI0_MOSI_BIT BIT2
...
#define SPI0_MISO_BIT BIT3
...
#define IINCHIP_CS_BIT BIT0

What do the different Bit numbers signify?
Logged

USA
Offline Offline
Sr. Member
****
Karma: 0
Posts: 452
Freeduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

@darudude, the code is part of the pin definitions on the spi.h file, used by Ethernet library.  Each bit definition indicates which pin on the Arduino board is supposed to be wired to the Ethernet shield.  They seem like a small change (BIT2 to BIT0), but physically the pins moved from digital 13-10 on the Duemilanove type board to digital 50-53 on the MEGA board.

It is like each BIT definition, together with the PORT, indicates each physical port on the Arduino board.
Logged

0
Offline Offline
Sr. Member
****
Karma: 0
Posts: 354
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

ah okay. I actually dwelled a little bit into the Ethernet library but couldn't make head or tails of what was going on.

Another question:

Why do SPI0_SS_BIT and IINCHIP_CS_BIT share the same pin and port? whats the difference between the two? It seems as the IINchip has something to do with the Wiznet module and the SPI0 is for the Atmega, but why are they set to the same pin?
Logged

USA
Offline Offline
Sr. Member
****
Karma: 0
Posts: 452
Freeduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset


Both represented the same pin and it is how you activate the SPI mode on the W5100 chip.  I will try again to move it back to Digital port 10 and see if it works now.  This way, only 3 pins need to be moved for the MEGA hack to work.
« Last Edit: April 14, 2009, 10:22:02 pm by nkcelectronics » Logged

USA
Offline Offline
Sr. Member
****
Karma: 0
Posts: 452
Freeduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I fixed the SPI0_SS_BIT issue with the MEGA (and all SPI usage in general, when trying to move the SS bit to a different pin).

What happens is that the SS pin is used by AVR only when acting as a SLAVE, AND also when it is setting the SPCR register (SPI working mode definition register).  SS needs to be high before setting AVR in SPI master mode by setting SPCR bit 4 to HIGH.  If this pin is not high, then it doesn't go into Master mode.  Changing the following line in spi.h:

Code:
PORTB |= SPI0_SS_BIT; PORTB &= ~(SPI0_SCLK_BIT|SPI0_MOSI_BIT);\

to

Code:
PORTB |= SPI0_SS_BIT | BIT0; PORTB &= ~(SPI0_SCLK_BIT|SPI0_MOSI_BIT);\

solves the problem and now the Arduino Ethernet Shield can work with the MEGA board by moving only 3 pins, not 4.

The only drawback is that pin SS (IO port 53) will remain high, but any setting using digitalWrite() after Ethernet.begin() will change the value to a desired value, if you ever need to use this port.

I will edit my original hack posting to reflect this new change, that makes the hack simpler to perform.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 14
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

what if someone wants to use multiple ss pins for pultiple devices...
I want to use the sd on the ethernet shield...
It simply doesn't work with the mosi pin of the spi connected to both wiznet and sd...
is it possible to set the pi 10 hi in order to set arduino as slave and still use diferent pins for cselecting w5100 and sd?
Logged

USA
Offline Offline
Sr. Member
****
Karma: 0
Posts: 452
Freeduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

MOSI, MISO and SCK pins can be shared, SS or CS cannot be shared and you need a dedicated pin for each SPI slave device.

http://en.wikipedia.org/wiki/File:SPI_three_slaves.svg
Logged

Denmark
Offline Offline
Newbie
*
Karma: 0
Posts: 17
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

This seems a bit tricky.

Is anyone able to show some code to show how another SPI device is made to run alongside the ethernet shield.
Will it (apart from the fix explained early in this topic) be very different on the mega in relation to ie. a Duemilanove.

I have a SHT15 SPI temperature and moisture sensor that I would like to run along withe the ethernet-shield on a seeduino mega.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 10
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

This worked great for me.  Thank you.
Logged

Melbourne, Australia
Offline Offline
Full Member
***
Karma: 1
Posts: 226
Cyborg-in-progress
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
MOSI, MISO and SCK pins can be shared, SS or CS cannot be shared

That's quite correct as far as the SPI spec is concerned, but one problem with the Wiznet W5100 chipset used in the official Ethernet shield (and many others) is that it fails to release the bus properly when it's deselected. That's a real pain. One way around that is to slave the Wiznet's SEN line to the CS line using a MOSFET or similar, but unfortunately the official shield doesn't do that. The new Ethernet Shield I've been working on recently does though: http://www.freetronics.com/ethernet-shield

Cheers

Jon
Logged

0
Offline Offline
Newbie
*
Karma: 1
Posts: 41
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks (a lot) nkcelectronics.  smiley-wink

I was stuck trying to run multiple SPI modules! smiley-sad
Logged

Pages: [1]   Go Up
Jump to: