Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

SD Card Initialization failed. Help.

Status
Not open for further replies.
Hi,

I´ve tried but failed to explain.
Sadly I´m not patient enough to go on.

I really hope that others can explain more clearly and have more patience.

Klaus
Hi,
I got the value display on monitor using :;
void UART_Write_Ascii(char data){
char buf[5];
unsigned char i;

sprintf(buf,"%x",data);

i = 0;
while (buf!='\0')
{ while(!PIR1bits.TXIF);
TXREG = buf[i++];
}
}

But still not getting 0x01 as response. I am getting 0 as response.

--- Updated ---

I really have no idea why I am not getting 0x01 response. I have invested 15+ days on only sdcard initializing. I am attaching a project. If any of the experienced one can tell me my silly mistake, than I am eager to learn it. I also attached a proteus file. Please find.
 

Attachments

  • cartao1.X.rar
    299.4 KB · Views: 79
Last edited:

I feel like, problem is detected. Spi_send and spi_receive is not right I guess. As, the terminal displaying 0b 1111 1111 i.e. FF which is in form of byte not in form of bit reception and than display i.e. 0b 0000 0001 i.e. 01

This is what my terminal display:
1605011270771.png


Code:
do
    {
    dummy_clock(10);
   
    UART_Write_Text("Sending CMD0");
    // transmit command 0
    SDcommand[0] = 0x40; // start bit | host bit | command
    delay(1);
    SDcommand[1] = 0x00; // no arguments
    delay(1);
    SDcommand[2] = 0x00;
    delay(1);
    SDcommand[3] = 0x00;
    delay(1);
    SDcommand[4] = 0x00;
    delay(1);
    SDcommand[5] = 0x95; // pre-calculated CRC
    delay(1);
    spi_send(SDcommand, 6);
    proceed();
   
    buff[0] = spi_single_receive();
    UART_Write_Text("Buff[0] =");
    UART_Write_Ascii(buff[0]);
      
    buff[1] = spi_single_receive();
    UART_Write_Text("Buff[1] =");
    UART_Write_Ascii(buff[1]);
   
    buff[2] = spi_single_receive();
    UART_Write_Text("Buff[2] =");
    UART_Write_Ascii(buff[2]);
   
    buff[3] = spi_single_receive();
    UART_Write_Text("Buff[3] =");
    UART_Write_Ascii(buff[3]);
   
    buff[4] = spi_single_receive();
    UART_Write_Text("Buff[4] =");
    UART_Write_Ascii(buff[4]);
   
    buff[5] = spi_single_receive();
    UART_Write_Text("Buff[5] =");
    UART_Write_Ascii(buff[5]);
   
    buff[6] = spi_single_receive();
    UART_Write_Text("Buff[6] =");
    UART_Write_Ascii(buff[6]);
   
    buff[7] = spi_single_receive();
    UART_Write_Text("Buff[7] =");
    UART_Write_Ascii(buff[7]);
   
     }while(buff[count]!=0X01);

Please suggest me the changes. Thanks
 
Last edited by a moderator:

hello,


what ugly presentation !!!
How to read this result !

a better way :

Code:
int i;

................
spi_send(SDcommand, 6);
proceed();

for (i=0;i<7;i++)
{
UART_Write_Text("Buff[");
UART_Write(i+48);  // ascii char '0' to '7'
UART_Write_Text("]=";
buff[i] = spi_single_receive();
UART_Write_Ascii(buff[i]);
UART1_Write(13);  // CR LF to do next line
UART1_Write(10);
}


Nota:
to reduce RAM space consumption
for PIC with few RAM ( as 16F .. to avoid IRP_bit alarm)
or when the program grow up, you can get problems ( even with 18F !)

Code:
// for TEXT direct  written inside the  code
void CPrint(const char *txt)
{
   while (*txt)
      UART1_Write(*txt++);
}
// for TEXT into RAM space
void Print(char *txt)
{
   while (*txt)
      UART1_Write(*txt++);
}
===============

for (i=0;i<7;i++)
{
CPrint("Buff[");
UART_Write(i+48);
CPrint("]=");
buff = spi_single_receive();
UART_Write_Ascii(buff);
UART1_Write(13); // next line
UART1_Write(10);
}

could you show your hardware ?
SDcard support ?
schematic ?
 

I read that you received 00H from the SD card instead of 01H. If you really did read 00H (check this by removing the SD card and tying the data out pin high) this indicates that the SD card is busy. When you send the reset command to the SD card and read data back you will get 00H, 01H, FFH.....

There is always a one byte busy byte between the end of the command and the response data.
 

As far as I see, the SPI mode setting is incorrect
C:
SSPCON1bits.CKP = 0; // Idle state for clock is a low level
SSPSTATbits.CKE = 0; // Transmit occurs on transition from active to Idle clock state
SSPSTATbits.SMP = 1; // Input data sampled at end of data output time (took me 5 friggin' hours)
With Microchip, CKP=0 and CKE=0 refers to mode 1, not intended mode 0. SMP = 1 won't be normally used for SD-card.

Code:
  Standard SPI Mode | Microchip PIC
     Terminology    | Control Bits
   Using CPOL,CPHA  |   CKP CKE
 -------------------+--------------
       0,0 (0)      |    0   1
       0,1 (1)      |    0   0
       1,0 (2)      |    1   1
       1,1 (3)      |    1   0
 
hello,

with a SDCARD 2GB , with cluster 1024 bytes ,
MCU 18F26K22 at 64MHz SPI Hardware RC0,RC3,RC4,RC5 Lib FAT32 MikroC
i have a working program (MikroC) with successfull file Write and file read functions
Even posssible to use long file name ...

i use this SPI init :

Code:
 CPrint(" Init SPI faible Vitesse OSC_DIV64  \r\n");
 SPI1_Init_Advanced(_SPI_MASTER_OSC_DIV64, _SPI_DATA_SAMPLE_MIDDLE, _SPI_CLK_IDLE_LOW, _SPI_LOW_2_HIGH);

lower speed for the FAT32 init
then i can increase SPI speed x 4
Code:
 CPrint(" Init SPI Moyenne Vitesse OSC_DIV16 ! (donc  vitesse x 4 ) \r\n");
   SPI1_Init_Advanced(_SPI_MASTER_OSC_DIV16, _SPI_DATA_SAMPLE_MIDDLE, _SPI_CLK_IDLE_LOW, _SPI_LOW_2_HIGH);
   CRLF1();

if higher SPI speed => bad results...
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top