-
Notifications
You must be signed in to change notification settings - Fork 455
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SPI_SS Pins in Arduino MEGA #19
Comments
It would be nice to put those pins constants in header file in a form dependent of Arduino type, like this: |
@levicm why don't you create a fork, make changes, and submit a pull request...? |
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. |
@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. |
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. |
@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 |
@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... |
@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. |
I have the same problem. If I use ether.begin(xxx,xxx,other_cs_pin),the program isnt work. I use 2560Mega. |
@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:
Are you sure whatever Ethernet shield you are using is hardware compatible with the Mega in this regard? |
I just download the newest version of jcw. |
my IDE is 1.0 ,not 1.0.1 |
pinMode(15, OUTPUT); if (ether.begin(sizeof Ethernet::buffer, mymac,15) == 0) ether.staticSetup(myip, gwip); result 1# : [getStaticIP] sometime. |
it don't work . |
@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? |
it has two results. |
attaching it to my Arduino Mega: if I attach the 'SS' of enc28j69 to mega's 53 pin. everything is ok. |
Can anyone else confirm this with Mega hardware? I haven't got one to try. |
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: 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: 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. |
I use 8pin as CS. it 's OK. 2012/10/19 absorbingtechnologies notifications@github.com
Ïæ³ÈÍøÂç |
@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 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? |
@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. |
Agreed - adjusting I/O pins for other devices is not a task for the EtherCard library, so I'm closing the issue for now. |
Indeed, and I just realized pizzro did the same. |
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. |
Hi I was stuck since a few hours with an ethernet shield on a MEGA board. Hope this can help, and perhaps some modification to code should be done ? |
I use Arduino MEGA1280, who has SPI pins in: 50, 51, 52 (and 53 as CS).
I changed manually the code in enc28j60.cpp at lines 247 to use these pins, but if I change the CS pin (SPI_SS) to another, like 49, because I have the SD card module, they don't work.
I see recently the ether.begin support a third parameter, but it is limited at pins 8, 9, and 10, so this not help-me.
Is possible expand the CS pin to all digital pins, for who use Arduino MEGA can use this library too?
Best Regards
The text was updated successfully, but these errors were encountered: