Ethernet Library Variable Chip Select/Reset

capricorn one

Well-known member
Been wanting this for a long time, curious if there's a reason why it hasn't been implemented. Same way the SD library allows you to specify the chip select pin (which can be done from and DIO pin), would be great if this same pin could be changed in the Ethernet library. In addition, for people using the W5200 ethernet chip, the reset pin as well.

Currently, you can do this somewhat easily by changing the #define W5200_RESET_PIN 9 and #define W5200_SS_PIN 10 in the W5100.cpp file, however, I really hate having to make changes in the core libraries, especially when I don't use the same reset and chip select pins for every design. Means having to edit the core every time I switch a sketch to a different or download updates.

Seems like it would be an easy function to implement, similar to the setSCK(), setMOSI() etc. function of the SPI library.

Oh... also, #define MAX_SOCK_NUM 4 ?? This isn't quite as important to me, but I do have a project that uses all 8 sockets available on the W5200.

Happy to write the code if that helps!
 
Last edited:
Unfortunately, many add-on boards with SPI memory or other SPI based things lack a jumper to choose between, say, 3 different pins for chip select. And Interrupt.
Becomes a problem when there are 2+ SPI peripherals and if they conflict with chip select or interrupt pins.
 
That should be no problem if the default SS pin is 10 and only changes when the user explicitly defines another pin in their sketch.

The Ethernet lib is hopelessly outdated. No non-blocking DHCP or DNS, no SS pin select, no support for the W5300, ... I'm using three different versions of the Ethernet lib depending on the target Ethernet chip.

To me the Ethernet lib is the perfect example of what is wrong with Arduino. They invest tons of time and money into things that, frankly, not a lot of people are interested in. Their Zero, Yun or Intel boards aren't exactly the success they were hoping for. Meanwhile they neglect fixing some of the core issues the enthusiast community is dealing with, despite a lot of pull requests from said community. The most useful contributions for most of my projects are actually coming from Paul/Teensyduino, so that's why I'm sticking with them :D .
 
Unfortunately, many add-on boards with SPI memory or other SPI based things lack a jumper to choose between, say, 3 different pins for chip select.

Thanks Steve, not really sure I understand what your points are though? I get that not all boards let you choose which pin is the CS pin, but that's kind of the point, they're not all 10. And none of the libraries use the hardware SS pin control anyways, it just needs to be a digital IO pin. So yeah, you'd need to do the physical jumper yourself, but that's what I'm already doing.

And Interrupt. Becomes a problem when there are 2+ SPI peripherals and if they conflict with chip select or interrupt pins.

I'm not sure what you mean by this? You can use multiple SPI peripherals, I do it all the time. If they are conflicting, that's probably a software issue of when you are calling the correct functions to start and end a SPI transaction. Any hardware conflict would most likely render all SPI interfaces useless. Obviously, you can't use the same CS pin or interrupt pins for different SPI peripherals, which is why I would like to be able to define them in my sketch without having to rely on a #define value in a library.

A simple example (and the one that comes up the most in my projects) is using the Teensy Audio Adapter and the Wiz820io shield at the same time. The Audio board needs pins 9 for the SGTL500 chip, and pin 10 for the SD card chip select. So you can't use the ethernet board without going into the core wiz5100.cpp file and changing the #defines for the reset and CS pin.

The SD library does allow you to specify the CS pin in the begin(int chip select) function. That's what I'm wanting for the Ethernet library. And really, to me any library that depends on the SPI interface should have this as well IMHO.
 
Last edited:
That should be no problem if the default SS pin is 10 and only changes when the user explicitly defines another pin in their sketch.

The Ethernet lib is hopelessly outdated. No non-blocking DHCP or DNS, no SS pin select, no support for the W5300, ... I'm using three different versions of the Ethernet lib depending on the target Ethernet chip.

I'm thinking you've got the right idea here.. Since they don't seem to update the library much anyway, maybe I just make a fork of what they've got for my own purposes. Just thought maybe other people have been running into this issue and would want the feature, but maybe it's not that important.
 
Back
Top