Hi guys, i had a similar issue with the board freezing, and just wanted to add my feedback on what fixed it, (at least if someone google, they can get the information).
summary : removing the MicroSD card from the board fixed it. or bring Pin 4 to HIGH to disable SD card.
my code was written for a Freetronics EtherMega board, with the ATmega2560, Wiznet W5100 chip, and micro sd card slot.
my code is basically doing a webserver interface that pools the status of some variable and prints it in an HTML format. (i am not using the SDcard for anything)
the program will not crash at all if nothing was accessing the Network interface.
but once i try to access the webinterface, it works a few times, then after a few refresh (could be the 2nd time, or it cound be the 20th time). it will output "junk" (a lot of it, most of the junk is just a repeat of the status message itself in a random order) and the board will freeze. at this point i have to reset the board to make it work again.
while doing some troubleshooting, i wrote a much simpler code to just output text in my web browser. It was still freezing, but to my surprise , the "junk" was some of the output message of my previous code!!!!!!!!!!!!!.
did some research, and found that if i am not using the SD card, i need to explicitly disable it. p.s also read that if the SD library was in uses, it would have handle the pin mode.
Code: Select all
pinMode(53, OUTPUT); // set the SS pin as an output (necessary!)
digitalWrite(53, LOW); // ? (not sure)
pinMode(4, OUTPUT); // SD select pin
digitalWrite(4, HIGH); // Explicitly disable SD
pinMode(10, OUTPUT); // Ethernet select pin
digitalWrite(10, LOW); // Explicitly enable Network
Arduino communicates with both the W5100 and SD card using the SPI bus (through the ICSP header). This is on digital pins 11, 12, and 13 on the Duemilanove and pins 50, 51, and 52 on the Mega. On both boards, pin 10 is used to select the W5100 and pin 4 for the SD card. These pins cannot be used for general i/o. 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.
Note that because the W5100 and SD card share the SPI bus, only one can be active at a time. If you are using both peripherals in your program, this should be taken care of by the corresponding libraries. If you're not using one of the peripherals in your program, however, you'll need to explicitly deselect it. To do this with the SD card, set pin 4 as an output and write a high to it. For the W5100, set digital pin 10 as a high output.