Go Down

Topic: ATMEL Mega1284P evaluation board avalible (Read 81349 times) previous topic - next topic

fat16lib

#360
Jul 29, 2011, 05:30 pm Last Edit: Jul 29, 2011, 05:33 pm by fat16lib Reason: 1
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
Code: [Select]
 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.

Coding Badly

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


Why is that not possible?

pito

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

CrossRoads

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.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

pito

#364
Jul 29, 2011, 08:38 pm Last Edit: Jul 29, 2011, 08:55 pm by pito Reason: 1
..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  :smiley-roll-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..  :P

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

fat16lib

#365
Jul 29, 2011, 09:11 pm Last Edit: Jul 29, 2011, 09:27 pm by fat16lib Reason: 1
Forget you ever knew about
Code: [Select]

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.
Code: [Select]

#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

#366
Jul 29, 2011, 09:46 pm Last Edit: Jul 29, 2011, 09:50 pm by fat16lib Reason: 1
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.

pito

#367
Jul 29, 2011, 10:01 pm Last Edit: Jul 29, 2011, 10:04 pm by pito Reason: 1
@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..) ;)

retrolefty

Quote
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.  :D

CrossRoads

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

Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

pito

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

fat16lib

You use the Arduino pin number for SS_PIN. 

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

Code: [Select]

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


Same for SCK_PIN, MISO_PIN, and MOSI_PIN.


CrossRoads

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

Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

pito

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

mowcius

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

Still nice work on it all.

Go Up