Mega pin53, where does it go?

Hello everybody,

I can see from the enet shield v3 schematic that mega IDE pin4, on JLOW 5, drives (via an inverter) the SD select and that IDE pin10, on JHIGH 3, drives the sel pins of the w5100; but I see no connection of IDE pin 53 with the shield and physically the shield does not plug to the big connector of the mega; I am sure I am missing something but what?

Thanks for any help

Pin 53 on the Mega is Slave Select (SS) for the ATmega2560. Even though that pin is not connected to the Ethernet Shield, you still need to be careful with the SS pin when you are using SPI. From https://www.arduino.cc/en/Reference/SPI:

this pin should be set always as OUTPUT otherwise the SPI interface could be put automatically into slave mode by hardware, rendering the library inoperative.

For this reason, it's common to use SS for the CS pin with SPI devices, since you're limited what you can do with that pin anyway. The reason this is not done with the Ethernet Shield is to make the shield compatible with both the Mega and the Uno form factor boards. In order to make the shield use pin 53 it would need to be a Mega specific shield.

First thanks for your reply

If I understand you well, this pin, when asserted low will cause the atmega itself to listen to the spi data? e.g. to access it's internal resources?

And if so, in order to flash it with a firmware one has to reset and drive low IDE 53 while operating the spi?

So setting it as an output and high will prevent it from listening to what is going on the spi bus, usually data the atmega drives himself to talk to the sd/enet chip?

But then, what if my program never touched this pin nor to set it as output neither to set it high? since upon reset pins are tristated, i.e. undefined, can it be that while accessing the enet/sd I corrupted stuff in the atmega chip?

guy_c:
If I understand you well, this pin, when asserted low will cause the atmega itself to listen to the spi data?

Correct. You want the Ethernet controller chip or the SD card to be in slave mode so the ATmega2560 can control it. You definitely don’t want the ATmega2560 in slave mode. If you had the Mega connected to a different Arduino that was controlling it over SPI then you would want to put it in slave mode but in the case of a Mega with an Ethernet shield allowing the Mega to go into slave mode will never be desirable.

guy_c:
And if so, in order to flash it with a firmware one has to reset and drive low IDE 53 while operating the spi?

No, the SS pin is not connected to the ICSP header, which is used to flash the firmware using an ISP programmer. I’m not sure of the exact details of how that process works.

guy_c:
So setting it as an output and high will prevent it from listening to what is going on the spi bus, usually data the atmega drives himself to talk to the sd/enet chip?

No, it prevents it from going into slave mode, it’s still communicating and listening on the SPI bus, it’s just not being controlled by it because it’s in master mode.

guy_c:
But then, what if my program never touched this pin nor to set it as output neither to set it high? since upon reset pins are tristated, i.e. undefined, can it be that while accessing the enet/sd I corrupted stuff in the atmega chip?

I don’t think corruption would happen. I just think your Arduino wouldn’t be running reliably. SPI.begin() sets the internal pull-up resistor on the SS pin if it’s not in OUTPUT mode to avoid the microcontroller going into slave mode from a floating pin but after calling SPI.begin() if you were to change the pin mode/state then it could go into slave mode.

Ok, thats what i understood even if not nicely formulated. Now two more questions

What is the connection of this pin 53 with the uno board?

And why would my board be unstable if pin 53 is set by the library code as input pullup upon 1st call to ethernet.begin and my code never addresses this pin?

... Facts are that my board IS unstable which is why i started this thread but from your explanations, the reason would be elsewhere

guy_c:
What is the connection of this pin 53 with the uno board?

It's not clear what you're asking. If you're asking which pin on the Uno is SS, it's pin 10 as I already told you.

guy_c:
And why would my board be unstable if pin 53 is set by the library code as input pullup upon 1st call to ethernet.begin and my code never addresses this pin?

Impossible to say without more information.

What do you mean by "unstable"?

Under what conditions is it unstable?

pert:
Impossible to say without more information.

I checked and found by measuring that the library code sets pin 53 from float to output and high. Since my code does not touch this pin as individual or member of port I can reasonably assume that there is no issue here.

I could not find the code itself with the definition of Ethernet.begin SD.begin and SPI.begin., can you tell where on a window system these are located?

My stability issues are around the ethernet communication. The code is lengthy and the hardware seems shaky:)

Thanks again

Here's the code:

You can find it on your computer by doing this:

  • File > Examples > SPI > select any example
  • Sketch > Show Sketch Folder
  • Navigate up two folder levels to the root of the SPI folder
  • Open the src subfolder
  • Open SPI.cpp

Thank you Pert for your patient help

I have difficulties understanding the code in Ethernet and SD folders in arduino\libraries. I must assume that there are means to correctly manage the selection of the sd and the w5100 without my intervention and under this assumption there should be nothing abnormal in my code, at least concerning accesses to these two things.