Pages: [1]   Go Down
Author Topic: Bug:SD library examples don't work with Mega board  (Read 3038 times)
0 Members and 1 Guest are viewing this topic.
Left Coast, USA
Offline Offline
Sr. Member
****
Karma: 5
Posts: 499
Sometimes I just can't help myself.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The SD examples work with the new Ethernet shield on Duemilanove and Uno boards, but not with Mega boards.

In the init() functions there is the following statement:
Code:
 // make sure that the default chip select pin is set to
  // output, even if you don't use it:
  pinMode(10, OUTPUT);
  
The Ethernet shield uses Arduino Pin 10 as the Wiznet chip select.

That statement is redundant for '328 boards, since the card.init() function in the SD library sets the SS_PIN high, and the SS_PIN is Arduino pin 10 for these MCUs.  This is a slight modification of (and an improvement over) the original SdFat card.init() function, which did not set SS_PIN high.

However, for Mega boards, SS_PIN is not pin 10, a digitalWrite statement to make Pin 10 go HIGH is required (somewhere) in order to disable the Wiznet chip.

I suggest the following:

Putting a digitalWrite(10, HIGH); statement after the pinMode statement in setup() of each of the example sketches makes them work with Mega boards as well as the '328 boards.  You could even use a conditional directive so that the two statements are only compiled for '1280 and '2560 boards.

Note that my tests were with Duemilanove, Uno, and Mega1280 boards.  I do not have a Mega2560, but I believe the issues are the same (assuming that everything else works on a '2560 board).

Regards,

Dave

Footnote:
This confusion between SS_PIN and the device chip select has been the source of much frustration on the part of users with whom I have interacted.  In addition to adding the digitalWrite statement, a more informative comment might be in order.
« Last Edit: January 22, 2011, 02:09:05 pm by davekw7x » Logged

Pages: [1]   Go Up
Jump to: