реклама на сайте
подробности

 
 
> Инициализация SD, SDHC
AleksBa
сообщение Dec 4 2008, 10:01
Сообщение #1


Участник
*

Группа: Новичок
Сообщений: 16
Регистрация: 7-03-07
Пользователь №: 25 952



Вот пробую инициализировать карту(microD) в SPI-режиме:
посылаю CMD0 - норм.(ответ 0x01)
посылаю CMD8 - норм.(ответ 0x01 0 0 0x01 0xaa)
т.е. карта версии 2.0 или выше. (?) Дальше посылаю ACMD41 - 0x69 0x00 0x40 0x00 0x00 0xff. (?) Получаю ILLEGAL COMMAND - 0x05 (ответ). Попробывал также вместо последней команды CMD5 (0x45 0x00 0xff 0x80 0x00 0xff) - аналогичный ответ. И лишь на команду CMD55(соотв. после CMD0 и CMD8) получаю ответ 0x01. Вопрос - что я делаю не так и какая все-таки верная последовательность инициализации microSD в SPI режиме. Спасибо.
Go to the top of the page
 
+Quote Post
 
Start new topic
Ответов
sergeeff
сообщение Jan 14 2009, 16:07
Сообщение #2


Профессионал
*****

Группа: Свой
Сообщений: 1 481
Регистрация: 10-04-05
Пользователь №: 4 007



Atmel в своих последних примерах делает так:

Код
//------------------------------------------------------------------------------
/// Run the SDcard SD Mode initialization sequence. This function runs the
/// initialisation procedure and the identification process, then it sets the
/// SD card in transfer state to set the block length and the bus width.
/// Returns 0 if successful; otherwise returns an SD_ERROR code.
/// \param pSd  Pointer to a SD card driver instance.
/// \param pSdDriver  Pointer to SD driver already initialized
//------------------------------------------------------------------------------
unsigned char SD_MCI_Init(SdCard *pSd, SdDriver *pSdDriver)
{
    unsigned int sdCid[4];
    unsigned char isCCSet;
    unsigned char error;
    unsigned int status;
    unsigned char cmd8Retries = 2;
    unsigned char cmd1Retries = 100;

    // The command GO_IDLE_STATE (CMD0) is the software reset command and sets card into Idle State
    // regardless of the current card state.
    error = Cmd0(pSd);
    if (error) {
        TRACE_ERROR("Error during initialization (%d)\n\r", error);
        return error;
    }

    // CMD8 is newly added in the Physical Layer Specification Version 2.00 to support multiple voltage
    // ranges and used to check whether the card supports supplied voltage. The version 2.00 host shall
    // issue CMD8 and verify voltage before card initialization.
    // The host that does not support CMD8 shall supply high voltage range...
    TRACE_DEBUG("Cmd8()\n\r");
    do {
        error = Cmd8(pSd, 1);
    }
    while ((error == SD_ERROR_NORESPONSE) && (cmd8Retries-- > 0));

    if (error == SD_ERROR_NORESPONSE) {
        // No response : Ver2.00 or later SD Memory Card(voltage mismatch)
        // or Ver1.X SD Memory Card
        // or not SD Memory Card

        TRACE_DEBUG("No response to Cmd8\n\r");

        // ACMD41 is a synchronization command used to negotiate the operation voltage range and to poll the
        // cards until they are out of their power-up sequence.
        error = Acmd41(pSd, 0, &isCCSet);
        if (error) {
            // Acmd41 failed : MMC card or unknown card
            error = Cmd0(pSd);
            if (error) {
                TRACE_ERROR("Error during initialization (%d)\n\r", error);
                return error;
            }
            do {
                error = Cmd1(pSd);
            }
            while ((error) && (cmd1Retries-- > 0));
            if (error) {
                TRACE_ERROR("Error during initialization (%d)\n\r", error);
                return error;
            }
            else {
                TRACE_DEBUG("CARD MMC\n\r");
                pSd->cardType = CARD_MMC;
            }
        }
        else {
            if(isCCSet == 0) {
                TRACE_DEBUG("CARD SD\n\r");
                pSd->cardType = CARD_SD;
            }
        }
    }
    else if (!error) {

        // Valid response : Ver2.00 or later SD Memory Card
        error = Acmd41(pSd, 1, &isCCSet);
        if (error) {
            TRACE_ERROR("Error during initialization (%d)\n\r", error);
            return error;
        }
        if (isCCSet) {
            TRACE_DEBUG("CARD SDHC\n\r");
            pSd->cardType = CARD_SDHC;
        }
        else {
            TRACE_DEBUG("CARD SD\n\r");
            pSd->cardType = CARD_SD;
        }
    }
    else {
        TRACE_ERROR("Error during initialization (%d)\n\r", error);
        return error;
    }

    // The host then issues the command ALL_SEND_CID (CMD2) to the card to get its unique card identification (CID) number.
    // Card that is unidentified (i.e. which is in Ready State) sends its CID number as the response (on the CMD line).
    error = Cmd2(pSd, sdCid);
    if (error) {
        TRACE_ERROR("Error during initialization (%d)\n\r", error);
        return error;
    }

    // Thereafter, the host issues CMD3 (SEND_RELATIVE_ADDR) asks the
    // card to publish a new relative card address (RCA), which is shorter than CID and which is used to
    // address the card in the future data transfer mode. Once the RCA is received the card state changes to
    // the Stand-by State. At this point, if the host wants to assign another RCA number, it can ask the card to
    // publish a new number by sending another CMD3 command to the card. The last published RCA is the
    // actual RCA number of the card.
    error = Cmd3(pSd);
    if (error) {
        TRACE_ERROR("Error during initialization (%d)\n\r", error);
        return error;
    }

    // The host issues SEND_CSD (CMD9) to obtain the Card Specific Data (CSD register),
    // e.g. block length, card storage capacity, etc...
    error = Cmd9(pSd);
    if (error) {
        TRACE_ERROR("Error during initialization (%d)\n\r", error);
        return error;
    }

    // At this stage the Initialization and identification process is achieved
    // The SD card is supposed to be in Stand-by State
    do {
        error = Cmd13(pSd, &status);
        if (error) {
            TRACE_ERROR("Error during initialization (%d)\n\r", error);
            return error;
        }
    }
    while ((status & STATUS_READY_FOR_DATA) == 0);

    // If the 4 bit bus transfer is supported switch to this mode
    // Select the current SD, goto transfer state
    error = Cmd7(pSd, pSd->cardAddress);
    if (error) {
        TRACE_ERROR("Error during initialization (%d)\n\r", error);
        return error;
    }

    if (pSd->cardType != CARD_MMC) {
        // Switch to 4 bits bus width (All SD Card shall support 1-bit, 4 bitswidth
        error = Acmd6(pSd, 4);
        if (error) {
            TRACE_ERROR("Error during initialization (%d)\n\r", error);
            return error;
        }
    }
    else {
        MCI_SetBusWidth((Mci *)pSdDriver, MCI_SDCBUS_1BIT);
    }
    return 0;
}
Go to the top of the page
 
+Quote Post

Сообщений в этой теме
- AleksBa   Инициализация SD   Dec 4 2008, 10:01
- - AleksBa   Цитата(AleksBa @ Dec 4 2008, 14:01) Вот п...   Dec 4 2008, 11:07
- - Cyber_RAT   Разобрались с инициализацией?   Jan 14 2009, 09:53
|- - Атмег   Цитата(sergeeff @ Jan 14 2009, 20:07) Atm...   Oct 6 2010, 14:52
- - Андрей (Питер)   Может не очень в тему, но не подскажите где можно ...   Feb 7 2009, 17:48
- - Alex11   Есть только simplified версии 2, взять можно на са...   Feb 7 2009, 17:57
|- - Андрей (Питер)   Цитата(Alex11 @ Feb 7 2009, 20:57) Есть т...   Feb 8 2009, 16:43
- - ALEXANDER082   Цитата(AleksBa @ Dec 4 2008, 13:01) Вот п...   Feb 18 2009, 19:26
- - Angelo   Цитатаsergeeff: Atmel в своих последних примерах д...   Jun 29 2009, 17:19
- - roman_av   Та же проблема. Первый раз инициализация проходит ...   Oct 17 2012, 20:31
- - vladimir_orl   А у меня SDH карточка при посылке sendOpCond подви...   Oct 18 2012, 12:45
|- - MiklPolikov   microSD карта 16 Гб на CMD8 c аргументом 0 и аргу...   Nov 26 2013, 16:58
- - GetSmart   Подскажите, плиз, знающие люди, куда копать с иниц...   Feb 5 2014, 16:57
|- - MiklPolikov   Цитата(GetSmart @ Feb 5 2014, 20:57) Подс...   Feb 5 2014, 17:17
|- - GetSmart   Цитата(MiklPolikov @ Feb 5 2014, 23:17) Т...   Feb 5 2014, 18:08
|- - MiklPolikov   Цитата(GetSmart @ Feb 5 2014, 22:08) Спас...   Feb 5 2014, 18:26
|- - GetSmart   Цитата(MiklPolikov @ Feb 6 2014, 00:26) Н...   Feb 14 2014, 16:08
|- - MiklPolikov   Интересно, SD от microSD вообще ни чем не отличает...   Mar 1 2014, 22:18
||- - aaarrr   Цитата(MiklPolikov @ Mar 2 2014, 02:18) Н...   Mar 1 2014, 22:29
||- - octobus   Цитата(MiklPolikov @ Mar 2 2014, 02:18) И...   Mar 2 2014, 02:56
|- - GetSmart   Цитата(GetSmart @ Feb 14 2014, 20:08) И п...   Feb 23 2015, 15:49
- - uvreg   2MiklPolikov, у Вас в коде массив определен как un...   Apr 7 2014, 08:42
|- - MiklPolikov   uvreg, спасибо !   Apr 7 2014, 09:30
- - mekashikuta   Всем добрый день! Начали работать с SD картой(...   Aug 19 2014, 12:17
- - mekashikuta   Всем доброго дня! Вопрос по SD Host: Пытаемся ...   Jan 30 2015, 15:16
|- - MiklPolikov   Цитата(mekashikuta @ Jan 30 2015, 18:16) ...   Jan 30 2015, 15:23
|- - mekashikuta   Цитата(MiklPolikov @ Jan 30 2015, 18:23) ...   Feb 2 2015, 06:08
- - mekashikuta   Всем спасибо за помощь, извините за потраченное вр...   Feb 2 2015, 10:44
- - DeC_NN   Добрый день! Разобрался с инициализацией SD ка...   Jul 8 2015, 11:24


Reply to this topicStart new topic
1 чел. читают эту тему (гостей: 1, скрытых пользователей: 0)
Пользователей: 0

 


RSS Текстовая версия Сейчас: 27th June 2025 - 02:40
Рейтинг@Mail.ru


Страница сгенерированна за 0.01385 секунд с 7
ELECTRONIX ©2004-2016