Plug the shield in. It only fits one way, in one place. The pins are then connected automatically, correctly.
The module should plug into the female headers of the Mega, and the SPI connections are made automatically through the ICSP pin block of the mega mating with some female headers on the bottom side of the shield.
But, you say
I connected:
1 VCC 5V/3V3 - to 5V
2 GND GND - to GND
3 D13/ICSP_SCK SD_SCK - to pin 52
4 D12/ICSP_MISO SD_OUT - to pin 50
5 D11/ICSP_MOSI SD_IN - to pin 51
6 D4 SD_CS - to pin 23, and i initialized pinMode(23, OUTPUT);
7 D0 RX - to RX0
8 D1 TX - to TX0
You should not have to make any special connections. Can you provide a photograph of how you have the shield hooked up to the mega?
SD Shield can be compatible with many Arduino mainboards and Arduino-derivative boards working under 3V3 or 5V level. When it works with boards of 3V3 logic level, the level switch needs to be slide to 5V. When it works with boards of 3V3 logic level, the level switch needs to be slide to 3V3. For some of the Arduino boards, SPI is on ICSP and D11 ~ D13, while for some main boards, D11 D12 / D13 are not defined as SPI. In order to improve the compatibility, we design an SPI JUMPER to make it compatible with mainboards of the two different types. For details, please find the table below.
For anyone out there, I have successfully got this shield working with a Teensy 3.2.
You can use any pin you want on your board for CS, as long as you set the correct number in SD.begin() BUT it MUST get connected on the shield's pin 4 in order for it to work.
The other connections are quite straight forward, SCK to shield 13, MISO to shield 12 and MOSI to shield 11.
Of course, you also need common ground between the board and the shield, any GND on your board to one of the GND pins next to the VIN on the shield will do.
Doing that you may be able to access the card information but no be able to read files of the SD card and get a failure at
SD.begin(CS_PIN);
The trick is to set the SPI rate to a lower value, I'm using 4000000 with the Teensy 3.2 so that's SPI_HALF_SPEED in Arduino SD library, but depending on the library it can vary. For example in Teensy's implementation SPI_HALF_SPEED is 24000000.