ATMEL Mega1284P evaluation board avalible

..you have to add to the sd2pinmap.h (in the sdfat lib folder) the 1284p definitions..

...for example

//------------------------------------------------------------------------------
#elif defined(AVR_ATmega1284P)

// Two Wire (aka I2C) ports
uint8_t const SDA_PIN = 17;
uint8_t const SCL_PIN = 16;

// SPI port
uint8_t const SS_PIN = 4; //12;
uint8_t const MOSI_PIN = 5; //13;
uint8_t const MISO_PIN = 6; //14;
uint8_t const SCK_PIN = 7; //15;

static const pin_map_t digitalPinMap[] = {
{&DDRA, &PINA, &PORTA, 0}, // A0 0 ADC0
{&DDRA, &PINA,...................

@crossroads: maybe off the topic:

  1. which microsdcard socket you use (the TFP09-12-2B ?)
  2. the two positioning holes are large enough ?
    (looking for the eagle lib part so asking whether it worked fine..).P.

pito,
Thanks for #351, fat16lib wrote back to me also that sd2pinmap.h would need to change. Will check that out when I get home. Looks like I need to mimic the contents of what I put in pins_arduino.c (all 32 IO pins ? Or just the 4 pins used for SPI ?)

uSD connecter, I used the Molex connecter that dipmicro sells, they have a library symbol for it also.

"MicroSD/TransFlash push/push connector. This connector is designed for SMT PCB mount, extensive use without mounting may loosen the pins. The free Eagle library provided by Roman Vaughan from Auckland, New Zealand is with his permission available here. " (actual link shows up on page)

Mounted nicely, even tho it was hand soldered (by my wife, very nice touch). Haven't tried it with a card yet.

..put there everything as you may see with the other mcu's there..
the sdcard shall then work when connected properly.. those demos wait on "type any character to start" so you have to push the button :slight_smile:
Run sdinfo.pde and you may see then what is your card like. In the older sdfat versions there is sdfatbench.pde - it measures the r/w speeds.. I would recommend you to have a look on the examples from older versions of sdfat as well..

Thanks for sdcard socket info, I've seen tons of those sockets on ebay and it seems it is the one I'll order.
P.

Thanks pito, am looking forward to checking that out after work.
Robert

Okay, with fat16lib's & pito's help I was came up with the following change to Sd2PinMap.h

#elif defined(__AVR_ATmega1284P__)
// add this if use these other chips
// ||defined(__AVR_ATmega644P__) || defined(__AVR_ATmega324P__)

// ATMEL ATMEGA1284P / BOBUINO
//
// Make it agree with the as-built hardware & pins_arduino.c
//
//                    +---\/---+
//  INT0 (D 4)  PB0  1|        |40  PA0 (AI 0 / D14)
//  INT1 (D 5)  PB1  2|        |39  PA1 (AI 1 / D15)
//  INT2 (D 6)  PB2  3|        |38  PA2 (AI 2 / D16)
//   PWM (D 7)  PB3  4|        |37  PA3 (AI 3 / D17)
//   PWM (D 10) PB4  5|        |36  PA4 (AI 4 / D18)
//  MOSI (D 11) PB5  6|        |35  PA5 (AI 5 / D19)
//  MISO (D 12) PB6  7|        |34  PA6 (AI 6 / D21)
//   SCK (D 13) PB7  8|        |33  PA7 (AI 7 / D22)
//              RST  9|        |32  AREF
//              VCC 10|        |31  GND 
//              GND 11|        |30  AVCC
//            XTAL2 12|        |29  PC7 (D 29)
//            XTAL1 13|        |28  PC6 (D 28)
//  RX0 (D 0)   PD0 14|        |27  PC5 (D 27) TDI
//  TX0 (D 1)   PD1 15|        |26  PC4 (D 26) TDO
//  RX1 (D 2)   PD2 16|        |25  PC3 (D 25) TMS
//  TX1 (D 3)   PD3 17|        |24  PC2 (D 24) TCK
//  PWM (D 30)  PD4 18|        |23  PC1 (D 23) SDA
//  PWM (D 8 )  PD5 19|        |22  PC0 (D 22) SCL
//  PWM (D 9)   PD6 20|        |21  PD7 (D 31) PWM
//                    +--------+
//
//	NOT_ON_TIMER,	/* 0  - PD0 */  
//	NOT_ON_TIMER, 	/* 1  - PD1 */
//	NOT_ON_TIMER, 	/* 2  - PD2 */
//	NOT_ON_TIMER,   /* 3  - PD3 */  
//	NOT_ON_TIMER,	/* 4  - PB0 */ 
//	NOT_ON_TIMER, 	/* 5  - PB1 */
//	NOT_ON_TIMER, 	/* 6  - PB2 */
//	TIMER0A,	/* 7  - PB3, PWM */
//	TIMER1A,	/* 8  - PD5, PWM */
//	TIMER2B, 	/* 9  - PD6, PWM */
//	TIMER0B,	/* 10 - PB4, PWM */
//	NOT_ON_TIMER, 	/* 11 - PB5 */
//	NOT_ON_TIMER,   /* 12 - PB6 */ 
//	NOT_ON_TIMER,   /* 13 - PB7 */ 
//	NOT_ON_TIMER,   /* 14 - PA0 */ 
//	NOT_ON_TIMER,   /* 15 - PA1 */ 
//	NOT_ON_TIMER, 	/* 16 - PA2 */
//	NOT_ON_TIMER,	/* 17 - PA3 */
//	NOT_ON_TIMER,	/* 18 - PA4 */
//	NOT_ON_TIMER,	/* 19 - PA5 */
//	NOT_ON_TIMER,	/* 20 - PA6 */
//	NOT_ON_TIMER,	/* 21 - PA7 */
//	NOT_ON_TIMER,	/* 22 - PC0 */
//	NOT_ON_TIMER,	/* 23 - PC1 */
//	NOT_ON_TIMER,	/* 24 - PC2 */
//	NOT_ON_TIMER,	/* 25 - PC3 */
//	NOT_ON_TIMER,	/* 26 - PC4 */
//	NOT_ON_TIMER,	/* 27 - PC5 */
//	NOT_ON_TIMER,	/* 28 - PC6 */
//	NOT_ON_TIMER,	/* 29 - PC7 */
//	TIMER1B,	/* 30 - PD4, PWM */
//	TIMER2A		/* 31 - PD7, PWM */


// 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 = 18;   // D 30
// uint8_t const SS_PIN = 21;  // D 31 Swap when testing the other SD card

   uint8_t const MOSI_PIN = 6;  // D 11  MOSI
   uint8_t const MISO_PIN = 7;  // D 12  MISO
   uint8_t const SCK_PIN =  8;  // D 13  SCK

have also tried the SPI section above as:

// SPI port
   uint8_t const SS_PIN = 30;   // D 30
// uint8_t const SS_PIN = 31;  // D 31 Swap when testing the other SD card

   uint8_t const MOSI_PIN = 11;  // D 11  MOSI
   uint8_t const MISO_PIN = 12;  // D 12  MISO
   uint8_t const SCK_PIN =  13;  // D 13  SCK

and the actual port to pin mapping:

static const pin_map_t digitalPinMap[] = {
  {&DDRD, &PIND, &PORTD, 0},  // D0  0
  {&DDRD, &PIND, &PORTD, 1},  // D1  1
  {&DDRD, &PIND, &PORTD, 2},  // D2  2
  {&DDRD, &PIND, &PORTD, 3},  // D3  3
  {&DDRB, &PINB, &PORTB, 0},  // B0  4
  {&DDRB, &PINB, &PORTB, 1},  // B1  5
  {&DDRB, &PINB, &PORTB, 2},  // B2  6
  {&DDRB, &PINB, &PORTB, 3},  // B3  7
  {&DDRD, &PIND, &PORTD, 5},  // D5  8
  {&DDRD, &PIND, &PORTD, 6},  // D6  9
  {&DDRB, &PINB, &PORTB, 4},  // B4 10
  {&DDRB, &PINB, &PORTB, 5},  // B5 11
  {&DDRB, &PINB, &PORTB, 6},  // B6 12
  {&DDRB, &PINB, &PORTB, 7},  // B7 13
  {&DDRA, &PINA, &PORTA, 0},  // A0 14
  {&DDRA, &PINA, &PORTA, 1},  // A1 15
  {&DDRA, &PINA, &PORTA, 2},  // A2 16
  {&DDRA, &PINA, &PORTA, 3},  // A3 17
  {&DDRA, &PINA, &PORTA, 4},  // A4 18
  {&DDRA, &PINA, &PORTA, 5},  // A5 19
  {&DDRA, &PINA, &PORTA, 6},  // A6 20
  {&DDRA, &PINA, &PORTA, 7},  // A7 21
  {&DDRC, &PINC, &PORTC, 0},  // C0 22
  {&DDRC, &PINC, &PORTC, 1},  // C1 23
  {&DDRC, &PINC, &PORTC, 2},  // C2 24
  {&DDRC, &PINC, &PORTC, 3},  // C3 25
  {&DDRC, &PINC, &PORTC, 4},  // C4 26
  {&DDRC, &PINC, &PORTC, 5},  // C5 27
  {&DDRC, &PINC, &PORTC, 6},  // C6 28
  {&DDRC, &PINC, &PORTC, 7},  // C7 29
  {&DDRD, &PIND, &PORTD, 4},  // D4 30
  {&DDRD, &PIND, &PORTD, 7}   // D7 31

};

and commented out 1284 in the 644/1284 part:

#elif defined(__AVR_ATmega644P__)||\
      defined(__AVR_ATmega644__)
// || defined(__AVR_ATmega1284P__)
// Sanguino

Result with either set of SPI pins is the sketches (SdFormatter, Bench, QuickStart) get to this line

if (!card.init(spiSpeed, chipSelect)) {

and stop.

What am I missing still?

If I run "Blink" with D11, 12, 13, 30 I can see the lines toggling at the SD socket on the right pins, so I know the signals are getting there.

..this works with mine (my own board!):

PS: the evidence provided by the toggling the "arduino_lines" with a help of some arduino functions within the Blink demo may not necessarily mean the sdfat uses those "arduino_line" numbers internally.. I think the SPI is hardwired into the sdfat.. So as I've written in #351 do use 4,5,6,7 (the magic numbers :astonished:), and restart IDE..

PS1: with pin/lines mapping from (vanilla): #include "pins_duino644.cxx"

PS2: .. provided you are using the PB4 as the SS !!

As I can see from the schematics you are using PD4 for the top sdcard and PC6 for the bottom sdcard as the SS. Is that correct??
If yes, then based on above PS1 (double check the count,pls):
SS_top card: PD4 -> 12 (12,5,6,7)
SS_bottom card: PC6 -> 21 (21,5,6,7)

It may differ of course when using other pin mapping as in PS1: !

//------------------------------------------------------------------------------
#elif defined(__AVR_ATmega1284P__)
// ala BahBots & Sanguino

// Two Wire (aka I2C) ports
uint8_t const SDA_PIN = 17;
uint8_t const SCL_PIN = 16;

// SPI port
uint8_t const SS_PIN   = 4; //12;
uint8_t const MOSI_PIN = 5; //13;
uint8_t const MISO_PIN = 6; //14;
uint8_t const SCK_PIN  = 7; //15;

static const pin_map_t digitalPinMap[] = {
  {&DDRA, &PINA, &PORTA, 0},  // A0  0   ADC0
  {&DDRA, &PINA, &PORTA, 1},  // A1  1   ADC1
  {&DDRA, &PINA, &PORTA, 2},  // A2  2   ADC2
  {&DDRA, &PINA, &PORTA, 3},  // A3  3   ADC3
  {&DDRA, &PINA, &PORTA, 4},  // A4  4   ADC4
  {&DDRA, &PINA, &PORTA, 5},  // A5  5   ADC5
  {&DDRA, &PINA, &PORTA, 6},  // A6  6   ADC6
  {&DDRA, &PINA, &PORTA, 7},  // A7  7   ADC7
  {&DDRB, &PINB, &PORTB, 0},  // B0  8 
  {&DDRB, &PINB, &PORTB, 1},  // B1  9 
  {&DDRB, &PINB, &PORTB, 2},  // B2 10 AIN0 INT2
  {&DDRB, &PINB, &PORTB, 3},  // B3 11 AIN1 OC0A (PWM)
  {&DDRB, &PINB, &PORTB, 4},  // B4 12   SS   OC0B (PWM)
  {&DDRB, &PINB, &PORTB, 5},  // B5 13   MOSI ICP3
  {&DDRB, &PINB, &PORTB, 6},  // B6 14   MISO OC3A (PWM)
  {&DDRB, &PINB, &PORTB, 7},  // B7 15   SCK  OC3B (PWM)
  {&DDRC, &PINC, &PORTC, 0},  // C0 16 SCL
  {&DDRC, &PINC, &PORTC, 1},  // C1 17 SDA
  {&DDRC, &PINC, &PORTC, 2},  // C2 18 TCK
  {&DDRC, &PINC, &PORTC, 3},  // C3 19 TMS
  {&DDRC, &PINC, &PORTC, 4},  // C4 20 TDO
  {&DDRC, &PINC, &PORTC, 5},  // C5 21 TDI
  {&DDRC, &PINC, &PORTC, 6},  // C6 22 TOSC1
  {&DDRC, &PINC, &PORTC, 7},  // C7 23 TOSC2
  {&DDRD, &PIND, &PORTD, 0},  // D0 24 RXD0
  {&DDRD, &PIND, &PORTD, 1},  // D1 25 TXD0
  {&DDRD, &PIND, &PORTD, 2},  // D2 26 RXD1
  {&DDRD, &PIND, &PORTD, 3},  // D3 27 TXD1
  {&DDRD, &PIND, &PORTD, 4},  // D4 28 OC1B (PWM)
  {&DDRD, &PIND, &PORTD, 5},  // D5 29 OC1A (PWM)
  {&DDRD, &PIND, &PORTD, 6},  // D6 30 OC2B (PWM) ICP
  {&DDRD, &PIND, &PORTD, 7}   // D7 31 OC2A (PWM)
};
//------------------------------------------------------------------------------

There are five important pin types for SPI on an avr processor. These are SS, SCK, MISO, MOSI, and chip select.

On the 1284P these definitions must map like this

uint8_t const SS_PIN   = <pin number for PB4>;
uint8_t const MOSI_PIN = <pin number for PB5>;
uint8_t const MISO_PIN = <pin number for PB6>;
uint8_t const SCK_PIN  = <pin number for PB7>;

SS is not the same as chip select and must be defined as above. For SPI to work correctly on an avr, SS must be either set to output mode or held high in input mode http://atmel.com/dyn/resources/prod_documents/doc2585.pdf.

SdFat sets SS to output mode even if SS is not chip select.

Chip select for a SPI device can be any pin. SdFat uses SS by default:

/** The default chip select pin for the SD card is SS. */
uint8_t const  SD_CHIP_SELECT_PIN = SS_PIN;

The above definition is only used when the chip select pin is not specified in the init() call.

The definitions for this array must match the way you setup The Arduino pins_arduino.c and pins_arduino.h files.

static const pin_map_t digitalPinMap[] = {

These definitions are currently used for software SPI in SdFat and other libraries associated with SdFat.

.. can we somehow bitbang the SPI (softspi) to be used with sdfat?

and would not be better then to define everything at one place like :

#define SS_ISNOT_CS

uint8_t const CS1_PIN = ;
uint8_t const SS_PIN = ;
uint8_t const MOSI_PIN = ;
uint8_t const MISO_PIN = ;
uint8_t const SCK_PIN = ;
uint8_t const SD_CHIP_SELECT_PIN = CS1_PIN;

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.

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