Micro sd module working on uno but not on mega

Arduino Mega
HW-125, micro SD card module
8 gb micro SD card FAT 32 formatted

GND to GND
VCC to 5v
MISO TO 50
MOSI TO 51
SCK TO 52
CS TO 53

Program used

#include <SPI.h>

#include <SD.h>

const int chipSelect = 53;  // Ensure this matches your CS pin connection

void setup() {
  Serial.begin(9600);
  pinMode(53, OUTPUT); // For the Mega, ensure pin 53 is set to OUTPUT
  digitalWrite(53, HIGH); // Ensure this pin is not interfering with SPI communication

  Serial.print("Initializing SD card...");

  if (!SD.begin(chipSelect)) {
    Serial.println("initialization failed!");
    return;
  }
  Serial.println("initialization done.");
}

void loop() {
  // Nothing in loop for basic initialization check
}

INITIALISATION FAILED!!

same program, sd card, and sd card reader I connected to a uno, it is working... but not working on mega,

tried changing the jumper wires, still not working.
i also tried with a different mega board, still not working

I found D53 doesn't work as a CS for remote devices. D53 determine whether the SPI is a master or slave.

Connect SD CS to pin 4. Then use this code:

#include <SPI.h>

#include <SD.h>

const int chipSelect = 4;  // Ensure this matches your CS pin connection

void setup() {
  Serial.begin(9600);
  pinMode(chipSelect, OUTPUT); // For the Mega, ensure pin 53 is set to OUTPUT
  digitalWrite(chipSelect, HIGH); // Ensure this pin is not interfering with SPI communication

  Serial.print("Initializing SD card...");

  if (!SD.begin(chipSelect)) {
    Serial.println("initialization failed!");
    return;
  }
  Serial.println("initialization done.");
}

void loop() {
  // Nothing in loop for basi


tried it, not working :frowning:

Check the other wires.
MISO TO 50
MOSI TO 51
SCK TO 52

@aaron_eipe_123
The big (8gig) SD cards can draw a lot of current. Do you have a smaller capacity card you could try?
Also, do you have the card power connected to the 5V output pin on the Mega?
Do you have anything else on the SPI bus?

wiring checked, jumpper wires changed, mega board changed, no luck! :frowning:

@ jim, the issue is 8GB is the smallest SD card available locally as well as online :frowning:
@ yes card VCC to 5V
@ i was troubleshooting with only the SD module connected to the Mega board. so NO, i didn't have anything else on the SPI bus

so i tried using the ICSP pins and it worked!!
YAYEH!!


thanks @SurferTim & @jim-p for your time :slight_smile: :nerd_face:

Exactly which pins did you have it connected to previously on the Mega ?

I guessed the wrong ones in post#4.

Edit: I make this same mistake. I get MOSI and MISO on wrong pins.

The ones quoted in the original post look right

They are, but were they actually connected like that?

Edit: I'm currently testing a TFT display with SD. It is connected as the OP described, and it works.

Edit2: I got tired of dealing with this, so I ordered a proto shield with an ICSP connector. I plan on clipping off pins 11-13 on the shield and rewiring the ICSP pins to those.

I'll plug the shield into the Mega, and the Uno-type SD shield onto it. Done.

That was the point of my question

Is it not possible to use your multimeter to find what module pins the ICSP pins are connected to? For future reference, I'd like to know that if it's different from the original connections.

Should be able to.
Uno should be 11-13.
Mega should be 50-52

I tried these initially
then ICSP pins as in post#8

GND to GND
VCC to 5v
MISO TO 50
MOSI TO 51
SCK TO 52
CS TO 53

i tried cs to 4, 8 & 10, each time making changes in the program.
i pulled out all the jumpers and rewired multiple times to make sure the wiring is as mentioned in post #1