when the SS is not being used as the CS (but must be set to output or the input pulled high), and the SS shall be then set properly inside the sdfat as well..
@crossroads - then you have to set SS to output when not used as the CS, and it may work..
Most users don't need to know about SS, SCK, MOSI, and MISO. I set SS to output and set it high in init(). That makes SdFat work with boards that don't use SS as chip select for the SD. If another SPI device uses SS as chip select this disables it.
The only time you need to worry about another SPI devices is if it uses a pin other than SS for chip select. You must set chip select high on that device before calling SdFat::init().
I don't want users to edit Sd2PinMap.h It is generated by a program that I run.
You are an exception since you are making your own board. You will always need to edit Sd2PinMap.h since the 1284P is defined to be a Sanguino in Sd2PinMap.h.
Early versions of SdFat had SD_CHIP_SELECT_PIN in the same file as SS_PIN, SCK_PIN, MOSI_PIN, and MISO_PIN. Users thought they could change the pin numbers any way they wanted. That caused a lot of problems.
I wish I could remove the definition for SD_CHIP_SELECT_PIN and require users to call
 sd.init(SPI_FULL_SPEED, chipSelect);
if chip select is not SS.
I plan to move the definition of SD_CHIP_SELECT_PIN to SdFatConfig.h and have a policy that users should only edit SdFatConfig.h.
..if you track "chipselect" in the sdfat you may see it has udergone an evolution:
..
uint8_t const SS_PIN = 53;
uint8_t const SD_CHIP_SELECT_PIN = SS_PIN;
bool init(uint8_t sckRateID = SPI_FULL_SPEED,
uint8_t chipSelectPin = SD_CHIP_SELECT_PIN);
chipSelectPin_ = chipSelectPin;
digitalWrite(chipSelectPin_, LOW);
In Sd2PinMap.h I need to set these 4 pins as SS, MOSI, MISO, SCK
// PWM (D 10) PB4 5
// MOSI (D 11) PB5 6
// MISO (D 12) PB6 7
// SCK (D 13) PB7 8
Then in any SdFat sketch I run I need to set the PB4 pin as an output.
Then somewhere else this gets called
uint8_t const SD_CHIP_SELECT_PIN = SS_PIN;
Does that need to go in the sketch as well?
Or does this go into Sd2PinMap.h also, with SS_PIN replaced by the physical pin # (18) or by the mapped name (30)?
I have PB4 connected to the shield header so that a user can have 'normal' SPI operations to an external device and not impact the SD card.
Thanks for the additional clarifications. Didn't realize what I had gotten myself into software-wise with my desire to implement increased hardware flexibility.
..the easiest way to test yor sdcard-hw "today" is to go with my setup (see my post, sanguino like) and to use pb4 as the chipselect (take it from the jumper J3-pin3 and apply accordingly )...
sw trap - the biggest issue with arduino is the attempt to make everything "automated" so in the near future the wrappers will be 99% of an application volume... fortunately sw-wise is everything doable..
.. I'm currently working with pic32mx so I am observing carefully those guys with chipkit (arduino "clone" based on pic32mx).. they are in much worse situation than you..
I think you had SS_PIN wrong. It looks like it should be pin 10 if that is PB4.
If you get Sd2PinMap.h setup correctly, this sketch will write "Hello World!" to the file HELLO.TXT.
#include <SdFat.h>
SdFat sd;
SdFile file;
// set 30 to whatever your chip select pin is
uint8_t chipSelect = 30;
//------------------------------------------------------------------------------
void setup() {
 Serial.begin(9600);
 if (!sd.init(SPI_FULL_SPEED, chipSelect)) sd.initErrorHalt();
 if (!file.open("HELLO.TXT", O_WRITE | O_CREAT | O_TRUNC)) {
  sd.errorHalt("open");
 }
 file.println("Hello World!");
 file.close();
Â
 Serial.println("Done!");
}
//------------------------------------------------------------------------------
void loop() {}
@fat16lib: nope, I am not going to edit any file!! One year ago I spent so much time/effort/stress to get my atmega32 and atmega1284p running arduino (bootloader, pinmappings, etc) that I am still under medication (post traumatic stress disorder symptoms..)
I am not going to edit any file!! One year ago I spent so much time to get my atmega32 and atmega1284p running arduino (bootloader, pinmappings, etc) that I am still under medication (post traumatic stress disorder symptoms..)
I hope this Bobuino project doesn't suffer such a outcome.
"I think you had SS_PIN wrong. It looks like it should be pin 10 if that is PB4."
PB4 is physical pin 5 (part of SPI group of pins 5-6-7-8), mapped to arduino D10.
Do I use the physical pin, or the mapped pin?
I am leaving work in a couple minutes, hope to try this around 6PM (east coast).
I have not changed other files (undid changes in SD2card.h I think it was), am using stock files with only changes in Sd2PinMap.h.
@lefty, I think I am close! After getting this to work, will get the uSD to work on its own chip select line.
Then will ask about how to select one or the other in a sketch.