Abdellazizhammami / arduino

Automatically exported from code.google.com/p/arduino
Other
0 stars 0 forks source link

Document pin usage of Ethernet library. #662

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I am programming an Arduino Mega (ATmega1280) with the ether network module 
(WIZnet WIZ811MJ) (http://www.sparkfun.com/products/9473).
I am using the SPI and Ethernet libraries.
According to http://arduino.cc/en/Main/ArduinoBoardMega the Arduino MEGA's SPI 
pins are 50 (MISO), 51 (MOSI), 52 (SCK), 53 (SS). 
But if I look at the code that manipulates SS 
arduino-0022\libraries\Ethernet\utility\w5100.h (line 311):
#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); };
#else
  inline static void initSS()    { DDRB  |=  _BV(2); };
  inline static void setSS()     { PORTB &= ~_BV(2); };
  inline static void resetSS()   { PORTB |=  _BV(2); };
#endif
The code addresses PORT B pin 4 (PB4) which is Arduino MEGAs pin 10 (and NOT 
53).
For the Arduino MEGAs PORT B pin 0 (PB0) should be used to get pin 53.
I changed the code to 
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
  inline static void initSS()    { DDRB  |=  _BV(0); };
  inline static void setSS()     { PORTB &= ~_BV(0); };
  inline static void resetSS()   { PORTB |=  _BV(0); };
#else
  inline static void initSS()    { DDRB  |=  _BV(2); };
  inline static void setSS()     { PORTB &= ~_BV(2); };
  inline static void resetSS()   { PORTB |=  _BV(2); };
#endif
and now SPI works as advertised: 50 (MISO), 51 (MOSI), 52 (SCK), 53 (SS).

Original issue reported on code.google.com by go4s...@gmail.com on 1 Oct 2011 at 6:34

GoogleCodeExporter commented 9 years ago
This is intentional for compatibility with the Arduino Ethernet Shield, which 
has the W5100 SS pin connected to digital pin 10 of the Arduino board.  

Original comment by dmel...@gmail.com on 1 Oct 2011 at 6:50

GoogleCodeExporter commented 9 years ago
For a user’s perspective there is very little information that the ethenet 
library silently uses a different pin for SlaveSelect (SS) than in many other 
places documented for the Arduino Mega:

1.)
http://arduino.cc/en/Main/ArduinoBoardMega
SPI: 50 (MISO), 51 (MOSI), 52 (SCK), 53 (SS).

2.)
arduino-0022\hardware\arduino\cores\arduino\pins_arduino.h (52)
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
const static uint8_t SS   = 53;
const static uint8_t MOSI = 51;
const static uint8_t MISO = 50;
const static uint8_t SCK  = 52;
#else
const static uint8_t SS   = 10;
const static uint8_t MOSI = 11;
const static uint8_t MISO = 12;
const static uint8_t SCK  = 13;
#endif

3.)
arduino-0022\reference\SPI.html
Connections 
On the Arduino Duemilanove and other ATmega168 / 328-based boards, the SPI bus 
uses pins 10 (SS), 11 (MOSI), 12 (MISO), and 13 (SCK). On the Arduino Mega, 
this is 50 (MISO), 51 (MOSI), 52 (SCK), and 53 (SS).

You could consider documenting your inline functions in 
libraries\Ethernet\utility\w5100.h(311) initSS(), setSS() and resetSS().
Please mention in a more obvious place that the Ethernet library is using pin 
10 SS for the Arduino Mega.

Consider providing some sort of switch in w5100.h with the following options:
1.  SPI pins Ethernet compatible pin 10 SS
2.  SPI pins ‘regular’ ping 53 SS

Thanks
Markus.

Original comment by go4s...@gmail.com on 2 Oct 2011 at 1:45

GoogleCodeExporter commented 9 years ago
Tom: here's a request to document the pin usage of the Ethernet library, 
particularly for those users who are using it with hardware other than the 
Ethernet shield.  In particular, we should explain that the library always uses 
pin 10 for SS, even on the Mega, where that's not the default SS pin.

Original comment by dmel...@gmail.com on 2 Oct 2011 at 1:49

GoogleCodeExporter commented 9 years ago
This has been clarified: http://arduino.cc/en/Reference/Ethernet

Original comment by dmel...@gmail.com on 16 Dec 2011 at 10:30