This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Micro SD Card programming

Other Parts Discussed in Thread: MSP430F2012, CC2530, CSD

 

Hi this is srinat,

 

                  Ant body hlep me how to write read and how to read data from card to Host.

                 Here i am using the MSP430f2012 controller.

 

Thnks in advance,

srinath reddy.

 

  • There are lots of threads dealing with SD card access (micro SD card makes no differece) through SPI. Including pseudo-code and code snippets.
    Also, there is a TI applicaiton note about this (the threads are more advanced, btu the code that comes with this appnote has the basics)
    It only works up to 2GB size, however, since all cards with larger capacity have a different internal organization and usually do not support serial mode anymore.

  • Hi Michael,

     

    Can you please send me any example codes for read from and write to Micro SD Card.

    It is useful to my project.

     

    Thanks and Regards

    Srinath Reddy

     

     

  • Hi

     

    SD card Block writing and Reading is happening but the problem is Reading the data sometimes it is showing error values.I dont know why it is happening.

    code for Block read is like this

     

                                sending the CMD24 command frame ( 48 bits )

                                Dummy byte

                                Response is 0x00

                                Dummy byte

                                reading  byte here i wait untill the data is 0xFE                  do

                                                                                                                                      {            Data = Spi_Rcv_Byte();

                                                                                                                                       }while ( Data  != 0xFE);

                               Dummy byte

                               After that Reading the 512 bytes.

     

              Here data is reading some time error data is reading so can u please tell me where i am doing the mistake.

     

     

     

     

  • srinath reddy said:
    it is showing error values

    What, exactly, is showing error values?

    What error values, exactly, is it showing ?

    Have you looked-up what those error values mean ?

     

  • Error Data is coming in different places like

    case 1)  suppose i am writing 0x79 to first block means first 512 bytes i am writing 0x79 data only.

    in reading it will read up to 26 bytes 0x79 after that it is reading 0xB3,0xB6,0xFF,0xFF...............up to 512 bytes it is reading 0xFF only

    case 2)  Writing 0x09 data to all 512 bytes.

                    Reading all the values 0x09 but in 32 byte location it is reading 0x01.

    case 3) Writing 0xDD to 512 bytes

                   Reading  up to 7 bytes is 0xDD and 8th and 9th bytes is 0xDC,0x09 after that again from 10th byte to 22nd byte it is reading properly (0xDD).23rd and 24th bytes is 0xC0,0x1D after that it is reading properly.

     

    Here i am not getting why this unexpected data values  are come into picture.Can you please tell me the reason and how to solve that problem.

     

  • Hi srinath,

    You need to configure an USART port for syncronous operation (SPI) and then connect the card to this port.  May be you have a problem and you could need a pull-up resistor in this connection (you could observe this on the oscilloscope).  After this, try to send commands and read responses, the commands you can send to the card are specified in the memory datasheets. I can help you if you need more information.

    But before I could help you you need to start communicating with the card...

    Best regards

    ---

    www.javierlongares.com

  • Hi ,

    Communication is happening properly means card initialization is ok.Writing also ok with proper responses.

    After that i send read command response is  0x00.After that i read the data until wait up to first data byte is 0xFE,This data also i am getting .

    After that reading 512 bytes of data here up to some locations reading properly after that garbage values is reading.

     

    This is the problem in my case.

     

  • Hi srinath,

    Congratulations for your job! If you're communicating with the card, almost the half of your work is done.

    Garbage bytes... I remember I had the same problem, in my case it was because I was not working with the SD in protected mode, that means, using the CRCs.  So the problem appears because the SPI port is very sensible to interferences... I started to use the secure mode and the garbage bits dissappeared.

    Also I prevent you for another problem that may be you'll need to face.  When you're working writting blocks for long periods of time (several hours), the SD doesn't respond.  I found an application note of SanDisk in which they say that in these cases you need to restart the MMC... So you need to control Vcc of the SD card.

    I've just written in my blog a test about how to integrate SD cards in your electronic products, and I've included the functions prototype... Unfortunately it is in spanish but I hope it could be useful for you.  I'm ultimating the details of the next entry which will be about FAT file systems over the SD cards, and may be it could be also interesting for you.

    Best regards.

    ---

    www.javierlongares.com

  • Arte8bits When technology becomes art said:
    I remember I had the same problem, in my case it was because I was not working with the SD in protected mode, that means, using the CRCs.

    The serial mode (SPI) is without CRC. the only command that requires a checksum is the intial command that enters the serial mode. It is identical for sertial and parallel mode and the CRC is always the same. After this point, all future commands still need a CRC byte but it is a don't care.

    Arte8bits When technology becomes art said:
    So the problem appears because the SPI port is very sensible to interferences.

    I cannot confirm this. None of my SD projects (three different, two with MSP) never had any problems with data loss. In fact, SPI is very stable and reliable.

    But there are other parameters which can cause instabilities. One of them is the supply voltage. During an SD card write, a peak current is drawn from Vcc. If Vcc isn't sufficiently buffered, it may happen that writing fails. However, most SD card implementations never check whether writing was completed successfully. It is just assumed. But SD card manufacturers are only humans too and the firmware in the card controller is not perfect, nor is the hardware.
    Another possible cause of problems is the clock speed. The original SD specs demand that the initialization must be done with <400kHz SPI clock speed. If the clock speed is higher, the card seems to work at first, but soem calibrations done at init ma have failed and further operation may be flakey.
    In my driver, I init the card with ~350kHz and then switch to up to 16MHz and it works fine.

    Using the secure mode of an SD card has severe drawbacks. And many card readers are not able to read the content. So it is only useful if you are the only one who writes and reads the card. But OTOH, in secur emode, the internal algorithms are different, so it might well be that this has caused the shift from flakey writes to reliable writes (hiding the real problem)

    You're right about the problem of not responding cards after some time. Many others have reported this too. Yet during my own tests, I initialized the card once only and it was logging data all day (and night) long, one sector every 15 seconds (one year storage per GB).
    So it seems to happen only after a certain time of continuously sleeping in standby. Accessing it every now and then seems to keep it alive.

  • Arte8bits When technology becomes art said:
    the SPI port is very sensible to interferences.

    I see no reason to believe that SPI is any more susceptible to interference than any other logic-level signal. So, if you are seeing interference on your SPI, that suggests a more general problem...

    Jens-Michael Gross said:
    ... other parameters which can cause instabilities. One of them is the supply voltage

    Indeed.

    If you're powering the card up & down, I suspect that the sequencing and/or timing are also important...

     

  • Hi, I'm using CC2530 and I try to connect the SD Card with SPI interface.

    I read the pdf swra223a and set properly the comunication in SPI mode,master,... but the card not responding to my CMD.

    I try to init the card:

     SSN=0x01;
      {
        /* Init the card in SPI mode by sending 80 clks */
        for(i = 0; i < 20; i++)
          byte = spi_receive_byte();
      }
      SSN=0x00;

      do{
      /* Send CMD0 GO_IDLE_STATE */
      mmc_cmd[0] = 0x40;
      mmc_cmd[1] = 0x00;
      mmc_cmd[2] = 0x00;
      mmc_cmd[3] = 0x00;
      mmc_cmd[4] = 0x00;
      mmc_cmd[5] = 0x95;

     spi_send(mmc_cmd, 6);
     
      if (mmc_response(0x01))
      {
        resp=0xAA; // timeout
        return;
      }

    I think the procedure is correct. Doese anybody help me?

    thank you

    Regards,

    Emanuele

  • The card migh tneed more time to come up and go idle. In this case you might need to repeat the command.

  • Thank you for the answer!

    I try but nothing.. Do you know If there are some libraries or example with cc2530 or msp430 and SD card?

    Regards,

    Emanuele 

  • HI,

    SHREENATH JI,

    CAN YOU PLEASE SEND ME PROGRAMMING CODE OF SDCARD INTERFACING?? ACTUALLY  SIR I MADE RFID BASED ATTENDANCE SYSTEM SO I M ALSO WANT TO STORE EACH ATTENDANCE IN SD CARD FOR FURTHER USE.

    REGARDS

    MOHIT KINGER

  • hi,

    Actually i used following code  FOR SDCARD INTERFACING in microc software but some errors are coming so please solve it.. :-

    // MMC module connections
    sbit Mmc_Chip_Select at LATC0_bit; // for writing to output pin always use latch (PIC18 family)
    sbit Mmc_Chip_Select_Direction at TRISC0_bit;
    // eof MMC module connections

    int i;
    unsigned char Mmc_Init();
    // Variables for MMC routines
    unsigned char SectorData[512]; // Buffer for MMC sector reading/writing
    unsigned char data_for_registers[16];// buffer for CID and CSD registers

    void main() {
    ADCON1 |= 0x0F; // Configure AN pins as digital
    CMCON |= 7; // Turn off comparators
    trisa = 0x00;

    // Initialize SPI1 module
    SPI1_Init_Advanced(_SPI_MASTER_OSC_DIV64, _SPI_DATA_SAMPLE_MIDDLE, _SPI_CLK_IDLE_LOW, _SPI_LOW_2_HIGH);
    while (1)
    {
    i = Mmc_Fat_Init();
    switch (i)
    {
    case 0 : porta = 0b00000001; break;
    case 1 : porta = 0b00000010; break;
    case 255 : porta = 0b00000011; break;
    default: porta = 0xff; break;
    }
    delay_ms(50);
    }
    }}

    REGARDS

    MOHIT KINGER

**Attention** This is a public forum