ATMEL Mega1284P evaluation board avalible

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.

I wish I could remove the definition for SD_CHIP_SELECT_PIN and require users to call

Why is that not possible?

..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);

.. so you have to touch a lot of files then..
P.

Ok. I think I understand.

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 :cold_sweat:)...

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.. :stuck_out_tongue:

.. 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.. :roll_eyes:

Forget you ever knew about

uint8_t const SD_CHIP_SELECT_PIN = SS_PIN;

Don't edit any files except Sd2PinMap.h !!!!!!!!!

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() {}

pito,

Sd2PinMap.h has nothing to do with chip select.

You don't need to edit any files for chip select.

It is set in the init call. See the sketch I posted.

@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..) :wink:

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. :smiley:

@fat16lib;

"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.

"PB4 is physical pin 5 ..mapped to arduino D10" - this is like "at four o'clock the five o'clock tea will be served.." :~

You use the Arduino pin number for SS_PIN.

So this will set the SS pin high in output mode.

pinMode(SS_PIN, OUTPUT);
digitalWrite(SS_PIN, HIGH);

Same for SCK_PIN, MISO_PIN, and MOSI_PIN.

Hello World works!

// Two Wire (aka I2C) ports
uint8_t const SDA_PIN = 23; // C1 23
uint8_t const SCL_PIN = 22; // C0 22

// SPI port
uint8_t const SS_PIN = 10; // physical 5, D 10 SS
uint8_t const MOSI_PIN = 11; // physical 6, D 11 MOSI
uint8_t const MISO_PIN = 12; // physical 7, D 12 MISO
uint8_t const SCK_PIN = 13; // physical 8, D 13 SCK

Thanks very much for all the help :slight_smile: :slight_smile:
Going to try some of the other example now...

Congratulation! :slight_smile:
That's one small step for you, one giant leap for arduino community!
What the bench.pde says?

The thread title has been annoying me for ages - if people now reply to this one then it's spelt right :smiley:

Still nice work on it all.

Full speed Bench test:
Card is 16 GB Sandisk Ultra SDHC, 15 MB/S

Settings: SPI_FULL_SPEED

How do these results look? I have nothing to compare to.
Need to get a uSD card to test the other socket.

Type any character to start
Free RAM: 15252
Type is FAT32
File size 5MB
Starting write test. Please wait up to a minute
Write 150.37 KB/sec

Starting read test. Please wait up to a minute
Read 280.82 KB/sec
Done

Can't run Quickstart - it won't accept a 2 digit ChipSelect entry, it tries using 3 instead of 30.

QuickStart expects line at a time input like the Arduino IDE. If no characters are available after 10 ms it assumes it has read the line.

So I need to type 3-enter-0-enter really quick? :wink:

No, your terminal emulator needs to send line at a time.

The Arduino IDE collects the line in the PC as you type it. When you hit send it sends the characters with no delay between characters. By default it does not send a new line so I just wait for no characters available for 10 ms.

I first waited for a new line but you never see one.

I made QuickStart work with the Arduino defaults so it would be easy for new users.

What are you using for a terminal?