I am working with a music shield, I have got my code from this site https://www.waveshare.com/Music-Shield.htm it works fine with arduino UNO but when I try to use it on MEGA it give me errors, Well I found that the problem is with this line


in uno SD_CS_PIN=10 I tried to change it to 53 based on this map

SPI   Uno   Mega
SS   10   53
MOSI   11   51
MISO   12   50
SCK   13   52

which is available on https://forum.arduino.cc/index.php?topic=165170.30 but still it returns false. What other options do I have to make it work on MEGA?

Thing that I am trying

#define SD_CS_PIN=10
#define VS_XRESET A0
#define VS_DREQ   A1
#define VS_XDCS   A2
#define VS_XCS    A3
void VS10XX::init(void)
  pinMode(53, OUTPUT);

  pinMode(VS_DREQ, INPUT);
  pinMode(VS_XDCS, OUTPUT);
  pinMode(VS_XCS, OUTPUT);
  digitalWrite(VS_XDCS, HIGH);
  digitalWrite(VS_XCS, HIGH);


In setup I added used this code but still does not work

void setup()
  pinMode(53, OUTPUT);//setting pin 53 to input

the error code when I attempt to init sd card is 0 which says

/** timeout error for command CMD0 */
  • did you try the examples of the shields library? 'your' code is from insides of the library
    – Juraj
    Feb 22, 2018 at 13:29
  • @Juraj yes it is exactly that code, I am just changing parametrs to find out where is the problem Feb 22, 2018 at 13:36
  • I think nothing needs to be changed for Mega. only set the pin 53 mode to output in .ino
    – Juraj
    Feb 22, 2018 at 13:58
  • @Juraj I removed all modifications from library and added` pinMode(53, OUTPUT);//setting pin 53 to input` to setup() but still does not work Feb 22, 2018 at 14:02
  • from SD library comment of card.init: "The value one, true, is returned for success and the value zero, false, is returned for failure. The reason for failure can be determined by calling errorCode() and errorData()."
    – Juraj
    Feb 22, 2018 at 14:27

1 Answer 1


53 is a SS pin if the Mega is SPI slave. Pin 10 is connected to shield to select it as a listening slave. So let the parameter set to pin 10. Additionally on Mega set pin 53 to output, otherwise the Mega can 'fall' into SPI slave mode.

SPI pins 50, 51 and 52 are connected to the ICSP header too. The 6 pin ICSP header is on the same place relative to Uno an Mega common pin headers.

enter image description here

  • thanks very much, Sorry for my noob question, I am new to arduino, So you mean I must set SD_CS_PIN to 10 and only add pinMode(53, OUTPUT); after SPI.begin(); ? I updated the question Feb 22, 2018 at 13:12
  • if it worked with 10 on Uno, then let it 10. for the shield the pin 10 is on the same place on Mega and Uno. 10 is a logical choice for SS on Uno. it must be an output (for the same reason 53 must be output on Mega) if SPI library is used
    – Juraj
    Feb 22, 2018 at 13:17
  • I tried based on what you said but it still returns false. I showed my code in question Feb 22, 2018 at 13:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.