Atmega1284 microsd card

I have installed the Mightycore and I have spent a considerable amount of time trying to get an Atmega1284p to work with a microsd card using the cardinfo sketch. I have used both the standard pinout and bobuino pinout. I modified the code from CS(4) to CS(10), with pinout VCC GND CS(10) MOSI(11) MISO(12) SCK(13) when I open the serial monitor I get no message at all, but the strange part is when I touch the reset wire to SCK it reads the data off of my card with no problem. I have tried using all 4 SPI SCK modes using the

SPI.beginTransaction(SPISettings(14000000, MSBFIRST, SPI_MODE0));

function call for this chip with the same result. I have a 10k ohm pull-up resistor on the reset to +VCC. I have triple checked my wiring.
Here is the code I am using:

#include <SD.h>
#include <SPI.h>

// set up variables using the SD utility library functions:
Sd2Card card;
SdVolume volume;
SdFile root;

// change this to match your SD shield or module;
// Arduino Ethernet shield: pin 4
// Adafruit SD shields and modules: pin 10
// Sparkfun SD shield: pin 8
const int chipSelect = 10;

void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
}// wait for serial port to connect. Needed for native USB port only

Serial.print("\nInitializing SD card…");

// we’ll use the initialization code from the utility libraries
// since we’re just testing if the card is working!
if (!card.init(SPI_HALF_SPEED, chipSelect)) {
Serial.println(“initialization failed. Things to check:”);
Serial.println("* is a card inserted?");
Serial.println("* is your wiring correct?");
Serial.println("* did you change the chipSelect pin to match your shield or module?");
return;
} else {
Serial.println(“Wiring is correct and a card is present.”);
}
}
// print the type of card
Serial.print("\nCard type: ");
switch (card.type()) {
case SD_CARD_TYPE_SD1:
Serial.println(“SD1”);
break;
case SD_CARD_TYPE_SD2:
Serial.println(“SD2”);
break;
case SD_CARD_TYPE_SDHC:
Serial.println(“SDHC”);
break;
default:
Serial.println(“Unknown”);
}

// Now we will try to open the ‘volume’/‘partition’ - it should be FAT16 or FAT32
if (!volume.init(card)) {
Serial.println(“Could not find FAT16/FAT32 partition.\nMake sure you’ve formatted the card”);
return;
}

// print the type and size of the first FAT-type volume
uint32_t volumesize;
Serial.print("\nVolume type is FAT");
Serial.println(volume.fatType(), DEC);
Serial.println();

volumesize = volume.blocksPerCluster(); // clusters are collections of blocks
volumesize *= volume.clusterCount(); // we’ll have a lot of clusters
volumesize *= 512; // SD card blocks are always 512 bytes
Serial.print("Volume size (bytes): ");
Serial.println(volumesize);
Serial.print("Volume size (Kbytes): ");
volumesize /= 1024;
Serial.println(volumesize);
Serial.print("Volume size (Mbytes): ");
volumesize /= 1024;
Serial.println(volumesize);

Serial.println("\nFiles found on the card (name, date and size in bytes): ");
root.openRoot(volume);

// list all files in the card with date and size
root.ls(LS_R | LS_DATE | LS_SIZE);
}

void loop(void) {

}

I am using an Atmel Ice ISP to program the chip without a bootloader. I have also tried reducing from half speed to quarter speed with no luck. I am using an FTDI friend from Adafruit (COM8) as my USB to Serial device. I have used the Atmel Studio device programming feature to ensure the device signature is being read and my chip target voltage is a constant 5.0V. I am using and external 16MHZ crystal oscillator with 22nf capacitors and have set the correct fuses for the chip. My next step would be trying to use an oscilloscope on the SCK line. Any help would be greatly appreciated!

  1. take this out
    while (!Serial) {
    }// wait for serial port to connect. Needed for native USB port only
    The 1284P does not have native USB.

  2. This is not correct
    SPI.beginTransaction(SPISettings(14000000, MSBFIRST, SPI_MODE0));

With 16 MHz crystel, SPI speeds are 8 MHz, 4 MHz, 2 MHz, 1 MHz. 1.4 MHz is not an option.

I would just use SPI.begin(); with the defaults of 4 MHz, MSBFIRST, SPI_MODE0 used.

  1. Reset to SCK, I don't know what's going on there. Do you have 5V to 3.3V adapters on the SCK, MOSI, and CS lines, and a good 3.3V supply at the SD card?

Try this sketch. Note the connections needed.

//LarryD
//Changes made for this sketch to work with Atmega1284 
//If there is no card detect switch connected to D9 then pin D9 must be grounded.
//If you are using the 1284 Logger theat has D7 as SS, connect D7 to D10
//Make sure you stop logging before you remove SD card i.e. LED on D8 should be
//quick flashes before removing SD card.




/*-----------*
   Serial Data Logger by Jack Christensen
 *                                                                             *
   02Jul2014 v1 for Arduino Uno and Adafruit MicroSD card breakout
                board (product #254).
   05Nov2014 v2 for custom PC board.
 *                                                                             *
   A logger that writes all serial data input on digital pin 0 (RXD) to
   a micro SD card. Serial input is interrupt-driven and double-buffered
   for maximum throughput. Input baud rate is selected by a rotary switch.
 *                                                                             *
   The heartbeat LED blinks in various patterns:
     Short blink: Idle mode.
     Steady blink on/off: Logging.
     Fast blink on/off: Error.
     Slow on/off: No SD card inserted (Reset the MCU after inserting card).
 *                                                                             *
   Press the button to start or stop logging. Each time logging is started,
   a new file is created.
 *                                                                             *
   If a buffer overrun occurs, the overrun LED stays on until logging is
   stopped or the MCU is reset.
 *                                                                             *
   Serial Data Logger by Jack Christensen is licensed under CC BY-SA 4.0,
   http://creativecommons.org/licenses/by-sa/4.0/
  ---------------*/


#include <Button.h>             //http://github.com/JChristensen/Button
#include <SdFat.h>              //http://github.com/greiman/SdFat
#include <SPI.h>                //http://arduino.cc/en/Reference/SPI
#include "buffer.h"
#include "heartbeat.h"


//pin assignments
//0, 1 USART
const uint8_t SD_LED      = 4;  //SD activity LED
const uint8_t BUTTON_PIN  = 5;  //start/stop button
const uint8_t OVR_LED     = 6;  //buffer overrun LED
const uint8_t SSlogger    = 7;  //on the 1284 Logger PCB pin D7 is SS therefore please connect D10 to D7
const uint8_t HB_LED      = 8;  //heartbeat LED
const uint8_t CARD_DETECT = 9;  //Connected to GND if there is no card detect switch on the SD socket
// Note Pin D10 is used as the SS SD pin and connected to D7 on the 1284 Logger PCB


bufferPool bp(SD_LED);
SdFat sd;
SdFile logFile;
heartbeat hbLED(HB_LED);


const bool PULLUP = true;
const bool INVERT = true;
const unsigned long DEBOUNCE_MS = 25;
Button btn(BUTTON_PIN, PULLUP, INVERT, DEBOUNCE_MS);
Button cardDetect(CARD_DETECT, PULLUP, INVERT, DEBOUNCE_MS);


enum STATES_t {IDLE, LOGGING, STOP, NO_CARD, ERROR} STATE;


//**************
void setup(void)
{
  //inits
  pinMode(OVR_LED,  OUTPUT);
  pinMode(SD_LED,   OUTPUT);
  pinMode(HB_LED,   OUTPUT);
  //Note: the 1284 Logger, D7 is connected to D10, therefore D7 is lost
  pinMode(SSlogger,  INPUT);


  //Power up LED test
  boolean ledState = false;
  for (uint8_t i = 0; i < 4; i++)
  {
    digitalWrite(OVR_LED, ledState = !ledState);
    digitalWrite(SD_LED, ledState);
    digitalWrite(HB_LED, ledState);
    delay(100);
  }


  hbLED.begin(BLINK_IDLE);


  cardDetect.read();
  if ( cardDetect.isReleased() )
  {
    STATE = NO_CARD;
    hbLED.mode(BLINK_NO_CARD);
  }
  //initialize SD card
  else if ( !sd.begin(SS, SPI_FULL_SPEED) )
  {
    STATE = ERROR;
    hbLED.mode(BLINK_ERROR);
  }


  //*************
  //baud rates 1200, 2400, 4800, 9600, 14400, 19200, 28800, 38400, 57600, 115200
  //change to match the baud rate as needed
  uint32_t USART0_BAUDRATE = 9600;


  //set up USART0
  uint32_t DIVISOR = 8;
  if ( USART0_BAUDRATE == 115200 )
  {
    UCSR0A |= _BV(U2X0);
  }
  else
  {
    DIVISOR = 16;
  }
  const uint16_t UBRR0_VALUE = ( (float)(F_CPU / DIVISOR) / (float)(USART0_BAUDRATE) + 0.5 ) - 1;
  //enable tx
  UCSR0B = _BV(TXEN0);
  //8-bit chars, async, 1 stop bit, no parity
  UCSR0C = _BV(UCSZ01) | _BV(UCSZ00);
  //baud rate setting
  UBRR0  = UBRR0_VALUE;
  //***********




} //                           E N D   o f   s e t u p ( )


//**************
void loop(void)
{
  switch (STATE)
  {
      int sdStat;


    case IDLE:
      //released == no card detected
      if ( cardDetect.wasReleased() )
      {
        STATE = NO_CARD;
        hbLED.mode(BLINK_NO_CARD);
      }
      if ( btn.wasReleased() )
      {
        if ( !openFile() )
        {
          STATE = ERROR;
          hbLED.mode(BLINK_ERROR);
        }
        else
        {
          STATE = LOGGING;
          hbLED.mode(BLINK_RUN);
          //initialize the buffer pool
          bp.init();
          //enable rx, tx & rx complete interrupt
          UCSR0B = _BV(RXCIE0) | _BV(RXEN0) | _BV(TXEN0);
        }
      }
      break;


    case LOGGING:
      //released == no card detected
      if ( cardDetect.wasReleased() )
      {
        STATE = NO_CARD;
        hbLED.mode(BLINK_NO_CARD);
      }
      //user wants to stop
      if ( btn.wasReleased() )        
      {
        //disable usart rx & rx complete interrupt, enable tx
        UCSR0B = _BV(TXEN0);          
        STATE = STOP;
      }
      //watch for buffers that need to be written
      else                            
      {
        //write buffers if needed
        sdStat = bp.write(&logFile);  
        if (sdStat < 0)
        {
          logFile.close();
          STATE = ERROR;
          //SD error              
          hbLED.mode(BLINK_ERROR);
        }
        if (bp.overrun) digitalWrite(OVR_LED, HIGH);
      }
      break;


    //stop logging, flush buffers, etc.
    case STOP:                        
      STATE = IDLE;
      hbLED.mode(BLINK_IDLE);
      //flush buffers if needed
      sdStat = bp.flush(&logFile);    
      logFile.close();
      if (sdStat < 0)
      {
        //SD error
        STATE = ERROR;                
        hbLED.mode(BLINK_ERROR);
      }
      bp.init();
      digitalWrite(OVR_LED, LOW);
      break;


    case NO_CARD:


      break;


    //All hope abandon, ye who enter here (reset required)
    case ERROR:                       
      break;
  }


  btn.read();
  cardDetect.read();
  hbLED.run();


} //                            E N D   o f   l o o p ( )


//********
//ISR, handle the incoming characters
//For Atmega1284 RX channel one (USART_RX_vect for Atmega328)
ISR(USART0_RX_vect)  
{
  //get the received character
  uint8_t c = UDR0;
  //put it into the buffer  
  bp.putch(c);       
}


//**********
//create a new file and open for write.
bool openFile(void)
{
  char filename[] = "LOGnnn.TXT";


  for (int i = 1; i < 1000; i++)
  {
    filename[3] = i / 100 + '0';
    filename[4] = ( i / 10 ) % 10 + '0';
    filename[5] = i % 10 + '0';
    //can we create this file LOGXXX.TXT?
    if (logFile.open(filename, O_CREAT | O_EXCL | O_WRITE))
    {
      break;
    }
  }
  //return true if successful, else false.
  return logFile.isOpen();
}
//

Figured it out. Adding a nice 10 second delay in the setup works great. SMH.