Comments (26)
Hi
I was stuck since a few hours with an ethernet shield on a MEGA board.
The problem is that I can't use pin 53 for CS since my shield is hard-wired to pin 10.
I've tried to set CS pin on BEGIN function with no success...
Then, I've found an interresting thing in arduino wiki (https://www.arduino.cc/en/Main/ArduinoEthernetShield) . It says :
"On the Mega, the hardware SS pin, 53, is not used to select either the W5100 or the SD card, but it must be kept as an output or the SPI interface won't work. "
So, even if the CS pin is 10, you MUST set pin 53 to OUTPUT !
I've tried, and... IT WORKS !!!
Hope this can help, and perhaps some modification to code should be done ?
from ethercard.
It would be nice to put those pins constants in header file in a form dependent of Arduino type, like this:
https://github.com/thiseldo/EtherShield/blob/master/enc28j60.h#L33
from ethercard.
@levicm why don't you create a fork, make changes, and submit a pull request...?
from ethercard.
Just applied a change, but more is probably needed. The point is that SPI_SS needs to be a fixed hardware-specific pin, regardless of which pin is actually used to control the EtherCard's slave select.
from ethercard.
@jcw, @thiseldo ... in response to "more is probably needed" ... I'm thinking about gutting references to selectBit in enc28j60.cpp and adopting a new variable called selectPin and using pinMode/digitalWrite with that variable instead... do you know why it wasn't done that way to begin with rather than directly manipulating PORTB and restricting to D8, D9, and D10 for the chip select?
SPI_SS is a different beast, representing the ATMega's chip select for slave mode, right? Basically that should not be set to an input under any circumstances in the context of EtherCard (or more generally cases where the ATMega is intended to behave as an SPI master). As long as it remains set to an output, my impression is that it is viable for users to do with as they wish without impacting EtherCard functionality.
from ethercard.
Might be a good idea - digitalWrite() is a lot slower, but it probably won't affect things much in this context.
Yes, SPI_SS needs to be an output to use the SPI hardware in master mode, Don't have to use it as select, but it does need to be defined as an output pin.
from ethercard.
@jcw OK, I'll start working this change, but would rather separate it from my current pull request which I think is good to go now
from ethercard.
@jcw I think the arduino core also provides some definitions that we can use instead of defining / managing our own definitions SPI pins, by way of the hardware/arduino/variants/standard/pins_arduino.h file...
from ethercard.
@jcw I've got an update that refers to the SPI pins with arduino defines and uses digitalWrite / pinMode to manipulate the ENC28J60 chipSelect. I can push to my fork's master and submit a pull request for it once my previous pull request is integrated and closed.
from ethercard.
I have the same problem. If I use ether.begin(xxx,xxx,other_cs_pin),the program isnt work. I use 2560Mega.
from ethercard.
@pizzro please elaborate. Are you saying it doesn't work with the current version (i.e. commit 0c4c1a6 or later)? Are you using the Arduino 1.0.1 IDE? If you have selected a variant board that points to the mega, the SPI definitions should come from the variants/mega folder:
static const uint8_t SS = 53;
static const uint8_t MOSI = 51;
static const uint8_t MISO = 50;
static const uint8_t SCK = 52;
Are you sure whatever Ethernet shield you are using is hardware compatible with the Mega in this regard?
from ethercard.
I just download the newest version of jcw.
from ethercard.
my IDE is 1.0 ,not 1.0.1
from ethercard.
pinMode(15, OUTPUT);
pinMode(4, OUTPUT); //SD 's CS_PIN
digitalWrite(4, HIGH);
Serial.begin(57600);
Serial.println("\n[getStaticIP]");
if (ether.begin(sizeof Ethernet::buffer, mymac,15) == 0)
Serial.println( "Failed to access Ethernet controller");
ether.staticSetup(myip, gwip);
result 1# :
[getStaticIP]
sometime.
result 2#:
[getStaticIP]
Failed to access Ethernet controller
Server: 96.46.10.64
from ethercard.
it don't work .
from ethercard.
@pizzro did you know you can edit an existing comment rather than adding new ones?
Can you try any of the library examples and confirm you get this hanging behavior? Also please can you download the latest Arduino IDE and confirm the problem is not in the IDE? Finally please can provide a reference to the shield that you are using and how you are attaching it to your Arduino Mega?
from ethercard.
it has two results.
so I comment in two comments.
from ethercard.
attaching it to my Arduino Mega:
enc28j60 <-> arduino2560
mosi <-> 51
miso <-> 50
sck <-> 52
ss <-> 15
rst <-> reset
int <->
CLK <->
Vcc <-> 5v
gnd <-> gnd
if I attach the 'SS' of enc28j69 to mega's 53 pin. everything is ok.
from ethercard.
Can anyone else confirm this with Mega hardware? I haven't got one to try.
from ethercard.
Hi, I have Arduino Mega and ENC28J60 board (http://www.geeetech.com/wiki/index.php/Arduino_ENC28J60_Ethernet_Module) and can confirm an issue with CS. It's wired according to the wiki link...
I am consistently having this line hang / freeze operation:
ether.begin(sizeof Ethernet::buffer, mymac) == 0)
In Arduino IDE v1.0.1, no EtherCard examples would work out-of-the-box, so I had to really play around. After much experimenting, I finally had to add the 3rd option to "ether.begin" routine, namely for the CS pin. I had read everywhere that I could put "8" (default), "9", or "10" only, but on a whim I put "53" and it FINALLY worked.
The end result:
ether.begin(sizeof Ethernet::buffer, mymac, 53) == 0)
Needless to say, this wasted quite a few hours of my time so hopefully it can be made more clear in a later revision of JCW EtherCard, as it's a fantastic library.
from ethercard.
I use 8pin as CS. it 's OK.
2012/10/19 absorbingtechnologies [email protected]
Hi, I have Arduino Mega and ENC28J60 board (
http://www.geeetech.com/wiki/index.php/Arduino_ENC28J60_Ethernet_Module)
and can confirm an issue with CS. It's wired according to the wiki link...I am consistently having this line hang / freeze operation:
ether.begin(sizeof Ethernet::buffer, mymac) == 0)In Arduino IDE v1.0.1, no EtherCard examples would work out-of-the-box, so
I had to really play around. After much experimenting, I finally had to add
the 3rd option to "ether.begin" routine, namely for the CS pin. I had read
everywhere that I could put "8" (default), "9", or "10" only, but on a whim
I put "53" and it FINALLY worked.The end result:
ether.begin(sizeof Ethernet::buffer, mymac, 53) == 0)Needless to say, this wasted quite a few hours of my time so hopefully it
can be made more clear in a later revision of JCW EtherCard, as it's a
fantastic library.¡ª
Reply to this email directly or view it on GitHubhttps://github.com//issues/19#issuecomment-9586528.
Ïæ³ÈÍøÂç
×ܾÀí Åíìã
Tel:15675293071
email: [email protected] Email%[email protected]
web:www.suncent.com.cn
from ethercard.
@vicatcu: On my Mega shield there is an SD card reader. I need to disable it to allow access to the enc28j60, if this is not done it will indeed loop at bootup. I'm using:
diff EtherCard.cpp
349,357d348
<
< /Disabling SD card on the MEGA shield/
< #if defined(AVR_ATmega1280) || defined(AVR_ATmega2560)
< pinMode(4, OUTPUT);
< digitalWrite(4, HIGH);
< #endif
<
With this code in EtherCard::begin, the lib is working just fine after I pass 53 as csPin in the begin function.
On a side not, I had to add an include for pins_arduino.h, but I guess if this is an issue with my environment?
from ethercard.
@RaphYot I'm glad to hear you have found a solution, but this does not belong in the library in my opinion. It sounds like a hardware compatibility issue with a particular class of boards. If you have SPI devices that is not in use, you still have to ensure their chip select pins are properly controlled or they will interfere with the SPI bus. That should be handled in the sketch, or with a board specific library / initialization routine.
from ethercard.
Agreed - adjusting I/O pins for other devices is not a task for the EtherCard library, so I'm closing the issue for now.
from ethercard.
Indeed, and I just realized pizzro did the same.
So, I can confirm this works on Mega for me, thanks!
from ethercard.
So glad I found this:
ether.begin(sizeof Ethernet::buffer, mymac, 53) == 0)
This is still an issue with the latest git version. By adding the 53 my board started working immediately.
from ethercard.
Related Issues (20)
- ATMega1284p not working HOT 1
- esp8266 HOT 1
- FINE ADJUSTMENTS
- Example ether.browseUrl(PSTR("/foo/"), "bar", website, my_callback); not working HOT 6
- UDP Multicast MAC not correct? HOT 5
- facing problem while using with SD card
- Concurrent requests possible?
- Custom host name while setting Static IP HOT 1
- Multicast listening HOT 1
- Rename 'master' branch to 'main'
- Reading response only 512 bytes chunk of tcpsend
- Hide response header from HTTP response
- Is there any way to use other serial port for ether.printIp()?
- UDP packet is not sent - NOT STATIC IP HOT 1
- Incorrect session id returned
- DHCP client + browse url with specific port HOT 1
- Wrong Ethernet II destination MAC address. HOT 6
- Error initializing library on Arduino Nano HOT 5
- How to handle multiple sessions?
- Sending UDP datagrams from Arduino with EtherCard library to concrete IP
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ethercard.