0

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

card.init(SPI_FULL_SPEED,SD_CS_PIN) 

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)
{
 SPI.begin();
 SPI.setClockDivider(SPI_CLOCK_DIV2);
 pinMode(53, OUTPUT);
 pinMode(VS_XRESET, OUTPUT);
 pinMode(VS_DREQ, INPUT);
 pinMode(VS_XDCS, OUTPUT);
 pinMode(VS_XCS, OUTPUT);
 digitalWrite(VS_XDCS, HIGH);
 digitalWrite(VS_XCS, HIGH);
 reset();
}

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

void setup()
{
 Serial.begin(115200);
 pinMode(53, OUTPUT);//setting pin 53 to input
 player.begin();
}

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

/** timeout error for command CMD0 */
asked Feb 22, 2018 at 13:00
6
  • did you try the examples of the shields library? 'your' code is from insides of the library Commented 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 Commented 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 Commented 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 Commented 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()." Commented Feb 22, 2018 at 14:27

1 Answer 1

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

answered Feb 22, 2018 at 13:07
3
  • 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 Commented 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 Commented Feb 22, 2018 at 13:17
  • I tried based on what you said but it still returns false. I showed my code in question Commented Feb 22, 2018 at 13:18

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.