Pages: 1 ... 23 24 [25] 26 27 ... 32   Go Down
Author Topic: ATMEL Mega1284P evaluation board avalible  (Read 74575 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Edison Member
*
Karma: 67
Posts: 1675
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
 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 Offline
Shannon Member
*****
Karma: 212
Posts: 13085
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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 Offline
Edison Member
*
Karma: 60
Posts: 2086
Pukao hats cleaning services
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

..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 Offline
Brattain Member
*****
Karma: 549
Posts: 27427
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Rapa Nui
Offline Offline
Edison Member
*
Karma: 60
Posts: 2086
Pukao hats cleaning services
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

.. 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
« Last Edit: July 29, 2011, 01:55:57 pm by pito » Logged

0
Offline Offline
Edison Member
*
Karma: 67
Posts: 1675
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Forget you ever knew about
Code:
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:
#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 Offline
Edison Member
*
Karma: 67
Posts: 1675
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 Offline
Edison Member
*
Karma: 60
Posts: 2086
Pukao hats cleaning services
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

@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..) smiley-wink
« Last Edit: July 29, 2011, 03:04:47 pm by pito » Logged

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 362
Posts: 17307
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.  smiley-grin
Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 549
Posts: 27427
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

@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

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Rapa Nui
Offline Offline
Edison Member
*
Karma: 60
Posts: 2086
Pukao hats cleaning services
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

0
Offline Offline
Edison Member
*
Karma: 67
Posts: 1675
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You use the Arduino pin number for SS_PIN. 

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

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

Same for SCK_PIN, MISO_PIN, and MOSI_PIN.

Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 549
Posts: 27427
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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 smiley smiley
Going to try some of the other example now...



* Hello_SD_Card.jpg (73.68 KB, 960x720 - viewed 39 times.)
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Rapa Nui
Offline Offline
Edison Member
*
Karma: 60
Posts: 2086
Pukao hats cleaning services
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

North Yorkshire, UK
Offline Offline
Faraday Member
**
Karma: 104
Posts: 5531
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Still nice work on it all.
Logged

Pages: 1 ... 23 24 [25] 26 27 ... 32   Go Up
Jump to: