I have successfully wired an ENC28J60 to an Arduino Nano with CS - D10 , MOSI – D11 , MISO – D12 , SCK - D13, and all works fine: my sketch is able to connect to a web server and download several initialization parameters.
HOWEVER, after this initialization, I do not need anymore the ENC28J60 card and I have other devices connected to Pins D11 and D13, but after I have done "ether.begin(sizeof Ethernet::buffer, mymac, 10)" the pinMode() and digitalWrite() functions do not work anymore on the Pins used by the library.
Can anyone help me in how to uninitialize the library to revert and have back the normal pin usage ? The standard SPI library has a SPI.begin() and a SPI.end() function. The ethercard library has an ether.begin() but I could not find an ether.end() function.
In practice I need to control pin 13. In my case:
ether.begin(sizeof Ethernet::buffer, mymac, 10);
pinMode( 13, OUTPUT);
digitalWrite( 13, HIGH);
simply does not work and pin 13 remains low (even if I do not use the library anymore).
Any suggestion would be appreciated !
Can anyone help me in how to uninitialize the library to revert and have back the normal pin usage ? The standard SPI library has a SPI.begin() and a SPI.end() function. The ethercard library has an ether.begin() but I could not find an ether.end() function.
Have you looked at the source code for ether.begin()? If it calls SPI.begin(), as I suspect that it does, you could add an ether.end() method that calls SPI.end(). Simpler, though, would be just to call SPI.end() when you are done using the ethernet shield.
I have looked into the code of ether.begin() but unfortunately there is no call to the standard SPI library. Only direct registers manipulation.
Maybe someone could help by telling me how I could reset the arduino registers and timers to their default value at start time so that digitalWrite on pin 13 would work again?
you have to disable SPI in SPCR to free the SPI-pins for other use. like so:
SPCR &= ~(1<<SPE);
Keep in mind to keep CS configured as output/high for all the time you use the SPI-pins as reguler i/0 while the ENC28J60 is physically connected to the SPI-pins. If CS happens to be driven low the enc28j60 will start to respond to whatever changes happen on the spi-pins, regardless of spi being configured on the Arduino or not.