Atmega1284p sd card

Hi, i have an atmega1284p with the mightycore bootloader (GitHub - MCUdude/MightyCore: Arduino hardware package for ATmega1284, ATmega644, ATmega324, ATmega324PB, ATmega164, ATmega32, ATmega16 and ATmega8535).
For a project a need an sd-card reader, but what pins do i need to use and what code? I tried pins 10-13 and also pins 4-7, but both didn't work.

Whether you use 10-13 or 4-7 depends on which pinout yoou have selected. I use the Bobino, and for sure the SD card works, when properly wired and used with good code.

You might want to read the 'How to use this Forum' post at the top of the posts list, it will tell you the information you should provide to enable people to help you.

For instance, you have not posted any code, or explained what 'didnt work' means.

// include the SD library:
#include <SPI.h>
#include <SD.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:
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only

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

  pinMode(10, OUTPUT);

  // 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?");
    while (1);
  } else {
    Serial.println("Wiring is correct and a card is present.");

  // print the type of card
  Serial.print("Card type:         ");
  switch (card.type()) {
    case SD_CARD_TYPE_SD1:
    case SD_CARD_TYPE_SD2:

  // 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");
    while (1);

  Serial.print("Clusters:          ");
  Serial.print("Blocks x Cluster:  ");

  Serial.print("Total Blocks:      ");
  Serial.println(volume.blocksPerCluster() * volume.clusterCount());

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

  volumesize = volume.blocksPerCluster();    // clusters are collections of blocks
  volumesize *= volume.clusterCount();       // we'll have a lot of clusters
  volumesize /= 2;                           // SD card blocks are always 512 bytes (2 blocks are 1KB)
  Serial.print("Volume size (Kb):  ");
  Serial.print("Volume size (Mb):  ");
  volumesize /= 1024;
  Serial.print("Volume size (Gb):  ");
  Serial.println((float)volumesize / 1024.0);

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

  // list all files in the card with date and size | LS_DATE | LS_SIZE);

void loop(void) {

This is the code I tried. I use the standard pinout. The sd card reader works with an normal arduino. At first he only worked occasionally, but after I installed version 1.8.9 of the arduino ide it worked well. The atmega1284p is also working correctly for every other program without an sd card.

Nice diag program for SD cards.

Works here on Mightycore and IDE 1.8.10.

Which pins did you use?

Pin 10 for the SD_CS.

an ATmega1284p MCU can be on any board with any pin numbering and the bootloader used doesn't say anything about pins

I have the same problem. Does it stop at SD.Begin or does it return failed?

10-13 are bobuino pins but I see that MightyCores SD library covers both. It limit’s possible issues a little.