Forums

PIC Micro SPI to SD Card Interface

Started by skhkrishna March 25, 2008
Hello All,
We are developing a project using PIC Microcontroller to communicate with
SD card using SPI interface. We are using 3M card slot for connecting the
microcontroller to the SD card.

In the initialization of SD card we are doing the following steps.
SPI is initialized to 62.5 KHz 
The SD card is provided with some dummy clocks by sending some data
through the SPI 
The SD card is selected by lowering its CS pin 
The Following sequence is given through SPI for setting the SD card to
IDLE state 
0x40 
0x00 
0x00 
0x00 
0x00 
0x95 
Then few dummy clock signals are provided through SPI send 
The response from the SD card is noted by reading the SPI buffer. 
 
With reference to the Sandisk Product manual it is given that the response
should be of r1 format (ie, a 1 byte data with 0 at the MSB)

But we are getting the response as 0xFF for any number of clock pulses.
The response is similar for both the Card is in the slot or not.

While analyzing the waveforms of the SPI lines it is observed that the
respective signals are flowing correctly. 

We couldn’t diagnose the problem as the pull-up resistors used for the
3M slot are working fine. 

Please advice on how to rectify this problem.

Your early reply is very much appriciated
Hari


On Mar 26, 4:58 am, "skhkrishna" <hari.kris...@hcl.in> wrote:
> Hello All, > We are developing a project using PIC Microcontroller to communicate with > SD card using SPI interface. We are using 3M card slot for connecting the > microcontroller to the SD card. > > In the initialization of SD card we are doing the following steps. > SPI is initialized to 62.5 KHz > The SD card is provided with some dummy clocks by sending some data > through the SPI > The SD card is selected by lowering its CS pin > The Following sequence is given through SPI for setting the SD card to > IDLE state > 0x40 > 0x00 > 0x00 > 0x00 > 0x00 > 0x95 > Then few dummy clock signals are provided through SPI send > The response from the SD card is noted by reading the SPI buffer. > > With reference to the Sandisk Product manual it is given that the response > should be of r1 format (ie, a 1 byte data with 0 at the MSB) > > But we are getting the response as 0xFF for any number of clock pulses. > The response is similar for both the Card is in the slot or not. > > While analyzing the waveforms of the SPI lines it is observed that the > respective signals are flowing correctly. > > We couldn't diagnose the problem as the pull-up resistors used for the > 3M slot are working fine. > > Please advice on how to rectify this problem. > > Your early reply is very much appriciated > Hari
I am not sure if it makes sense but the SD card should understand that the host is trying to communicate in SD-SPI mode and not SD mode. I would suggest you to look into SD protocol datasheets so as to move the SD card state to SD-SPI mode and not to SD mode. Cheers!! -dK
> We are developing a project using PIC Microcontroller to communicate with > SD card using SPI interface. We are using 3M card slot for connecting the > microcontroller to the SD card.
As far as I know, Microchip provide an SD card interface and FAT file system free of charge for use on their micros. Have you looked at using that? -- Regards, Richard. + http://www.FreeRTOS.org & http://www.FreeRTOS.org/shop 17 official architecture ports, more than 5000 downloads per month. + http://www.SafeRTOS.com Certified by T&#2013265948;V as meeting the requirements for safety related systems.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

skhkrishna wrote:
> Hello All, > We are developing a project using PIC Microcontroller to communicate with > SD card using SPI interface. We are using 3M card slot for connecting the > microcontroller to the SD card. > > In the initialization of SD card we are doing the following steps. > SPI is initialized to 62.5 KHz > The SD card is provided with some dummy clocks by sending some data > through the SPI > The SD card is selected by lowering its CS pin > The Following sequence is given through SPI for setting the SD card to > IDLE state > 0x40 > 0x00 > 0x00 > 0x00 > 0x00 > 0x95 > Then few dummy clock signals are provided through SPI send > The response from the SD card is noted by reading the SPI buffer. > > With reference to the Sandisk Product manual it is given that the response > should be of r1 format (ie, a 1 byte data with 0 at the MSB) > > But we are getting the response as 0xFF for any number of clock pulses. > The response is similar for both the Card is in the slot or not. > > While analyzing the waveforms of the SPI lines it is observed that the > respective signals are flowing correctly. > > We couldn&acirc;&#65533;&#65533;t diagnose the problem as the pull-up resistors used for the > 3M slot are working fine. > > Please advice on how to rectify this problem. > > Your early reply is very much appriciated > Hari > >
The critical thing with the SPI -> SD interface is that you _MUST_ send 0xFF out on the SPI data line when clocking data back from the SD card. This is not what the C18 libraries do, so you have to write your own spi_get ( ); routine. It's subtle and I missed it for nearly two weeks before realising it. The fact that you are getting 0xFF back may also mean either the SPI module is set up to invert the data coming in or that there is an electrical problem. - -- Brendan Gillatt | GPG Key: 0xBF6A0D94 brendan {a} brendangillatt (dot) co (dot) uk http://www.brendangillatt.co.uk -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.7 (MingW32) iD8DBQFH6o77uv4tpb9qDZQRAh8sAJ9BZYHqNemY4s0SM5u1oQy1Wj93twCfVPBy lk/AXoh4uKwdLhUWTbIuh+A= =nGCU -----END PGP SIGNATURE-----