0
Offline
Edison Member
Karma: 30
Posts: 1098
Arduino rocks
|
 |
« Reply #360 on: July 29, 2011, 10:30:53 am » |
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.
|
|
|
|
« Last Edit: July 29, 2011, 10:33:35 am by fat16lib »
|
Logged
|
|
|
|
|
Global Moderator
Dallas
Offline
Shannon Member
Karma: 129
Posts: 10373
|
 |
« Reply #361 on: July 29, 2011, 11:46:58 am » |
I wish I could remove the definition for SD_CHIP_SELECT_PIN and require users to call Why is that not possible?
|
|
|
|
|
Logged
|
|
|
|
|
Rapa Nui
Offline
Edison Member
Karma: 30
Posts: 1171
Pukao hats cleaning services
|
 |
« Reply #362 on: July 29, 2011, 12:35:52 pm » |
..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.
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
Boston area, metrowest
Offline
Brattain Member
Karma: 269
Posts: 17031
Available for Design & Build services
|
 |
« Reply #363 on: July 29, 2011, 01:16:31 pm » |
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.
|
|
|
|
|
Logged
|
|
|
|
|
Rapa Nui
Offline
Edison Member
Karma: 30
Posts: 1171
Pukao hats cleaning services
|
 |
« Reply #364 on: July 29, 2011, 01:38:25 pm » |
..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.. 
|
|
|
|
« Last Edit: July 29, 2011, 01:55:57 pm by pito »
|
Logged
|
|
|
|
|
0
Offline
Edison Member
Karma: 30
Posts: 1098
Arduino rocks
|
 |
« Reply #365 on: July 29, 2011, 02:11:40 pm » |
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() {}
|
|
|
|
« Last Edit: July 29, 2011, 02:27:38 pm by fat16lib »
|
Logged
|
|
|
|
|
0
Offline
Edison Member
Karma: 30
Posts: 1098
Arduino rocks
|
 |
« Reply #366 on: July 29, 2011, 02:46:49 pm » |
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.
|
|
|
|
« Last Edit: July 29, 2011, 02:50:39 pm by fat16lib »
|
Logged
|
|
|
|
|
Rapa Nui
Offline
Edison Member
Karma: 30
Posts: 1171
Pukao hats cleaning services
|
 |
« Reply #367 on: July 29, 2011, 03:01:03 pm » |
@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..) 
|
|
|
|
« Last Edit: July 29, 2011, 03:04:47 pm by pito »
|
Logged
|
|
|
|
|
Left Coast, CA (USA)
Offline
Brattain Member
Karma: 282
Posts: 15435
Measurement changes behavior
|
 |
« Reply #368 on: July 29, 2011, 03:06:00 pm » |
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. 
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
Boston area, metrowest
Offline
Brattain Member
Karma: 269
Posts: 17031
Available for Design & Build services
|
 |
« Reply #369 on: July 29, 2011, 03:50:43 pm » |
@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.
|
|
|
|
|
Logged
|
|
|
|
|
Rapa Nui
Offline
Edison Member
Karma: 30
Posts: 1171
Pukao hats cleaning services
|
 |
« Reply #370 on: July 29, 2011, 04:00:53 pm » |
"PB4 is physical pin 5 ..mapped to arduino D10" - this is like "at four o'clock the five o'clock tea will be served.." 
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Edison Member
Karma: 30
Posts: 1098
Arduino rocks
|
 |
« Reply #371 on: July 29, 2011, 04:18:24 pm » |
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.
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
Boston area, metrowest
Offline
Brattain Member
Karma: 269
Posts: 17031
Available for Design & Build services
|
 |
« Reply #372 on: July 29, 2011, 05:44:20 pm » |
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  Going to try some of the other example now...
|
|
|
|
|
Logged
|
|
|
|
|
Rapa Nui
Offline
Edison Member
Karma: 30
Posts: 1171
Pukao hats cleaning services
|
 |
« Reply #373 on: July 29, 2011, 05:49:20 pm » |
Congratulation! That's one small step for you, one giant leap for arduino community! What the bench.pde says?
|
|
|
|
|
Logged
|
|
|
|
|
North Yorkshire, UK
Offline
Faraday Member
Karma: 104
Posts: 5531
|
 |
« Reply #374 on: July 29, 2011, 05:51:46 pm » |
The thread title has been annoying me for ages - if people now reply to this one then it's spelt right  Still nice work on it all.
|
|
|
|
|
Logged
|
|
|
|
|
|