Giter Club home page Giter Club logo

Comments (26)

Adesin-fr avatar Adesin-fr commented on August 22, 2024 1

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.

levicm avatar levicm commented on August 22, 2024

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.

vicatcu avatar vicatcu commented on August 22, 2024

@levicm why don't you create a fork, make changes, and submit a pull request...?

from ethercard.

jcw avatar jcw commented on August 22, 2024

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.

vicatcu avatar vicatcu commented on August 22, 2024

@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.

jcw avatar jcw commented on August 22, 2024

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.

vicatcu avatar vicatcu commented on August 22, 2024

@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.

vicatcu avatar vicatcu commented on August 22, 2024

@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.

vicatcu avatar vicatcu commented on August 22, 2024

@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.

pizzro avatar pizzro commented on August 22, 2024

I have the same problem. If I use ether.begin(xxx,xxx,other_cs_pin),the program isnt work. I use 2560Mega.

from ethercard.

vicatcu avatar vicatcu commented on August 22, 2024

@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.

pizzro avatar pizzro commented on August 22, 2024

I just download the newest version of jcw.

from ethercard.

pizzro avatar pizzro commented on August 22, 2024

my IDE is 1.0 ,not 1.0.1

from ethercard.

pizzro avatar pizzro commented on August 22, 2024

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.

pizzro avatar pizzro commented on August 22, 2024

it don't work .

from ethercard.

vicatcu avatar vicatcu commented on August 22, 2024

@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.

pizzro avatar pizzro commented on August 22, 2024

it has two results.
so I comment in two comments.

from ethercard.

pizzro avatar pizzro commented on August 22, 2024

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.

vicatcu avatar vicatcu commented on August 22, 2024

Can anyone else confirm this with Mega hardware? I haven't got one to try.

from ethercard.

absorbingtechnologies avatar absorbingtechnologies commented on August 22, 2024

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.

pizzro avatar pizzro commented on August 22, 2024

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.

rawouter avatar rawouter commented on August 22, 2024

@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.

vicatcu avatar vicatcu commented on August 22, 2024

@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.

jcw avatar jcw commented on August 22, 2024

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.

rawouter avatar rawouter commented on August 22, 2024

Indeed, and I just realized pizzro did the same.
So, I can confirm this works on Mega for me, thanks!

from ethercard.

brunnels avatar brunnels commented on August 22, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.