Startbiterr on sd card operation with LPC1788

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Startbiterr on sd card operation with LPC1788

685 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by kingjing on Fri Dec 19 02:35:30 MST 2014

hello all, when I use LPC1788 for sd card read, I get a error startbiterr, but when I do write operation, it is ok, I need your help for my following work.

The codes I used are here.

/******************************************************************************
**   Main Function  main()
******************************************************************************/
void c_entry (void)
{
uint32_t i, j;
int32_t retVal = 0;
uint8_t error = 0;

st_Mci_CardId cidval;
en_Mci_CardType cardType;
uint32_t rcAddress;
uint32_t csdVal[4];
uint32_t errorState;

// Initialize buffers for testing later

for(i = 0; i < WRITE_LENGTH; i++)
{
wrBuf = i / (4*WRITE_BLOCK_NUM);
rdBuf = 0;
}

debug_frmwrk_init();

_DBG_("");_DBG(mciRdWrMenu);_DBG_("");

#if MCI_DMA_ENABLED
/* on DMA channel 0, source is memory, destination is MCI FIFO. */
/* On DMA channel 1, source is MCI FIFO, destination is memory. */
GPDMA_Init();
#endif

/* For the SD card I tested, the minimum required block length is 512 */
/* For MMC, the restriction is loose, due to the variety of SD and MMC
card support, ideally, the driver should read CSD register to find the
right speed and block length for the card, and set them accordingly.
In this driver example, it will support both MMC and SD cards, and it
does read the information by send SEND_CSD to poll the card status,
however, to simplify the example, it doesn't configure them accordingly
based on the CSD register value. This is not intended to support all
the SD and MMC cards. */
    
_DBG_("Init Card");
    
if(MCI_Init(BRD_MCI_POWERED_ACTIVE_LEVEL) != MCI_FUNC_OK)
{
_DBG_("MCI_Init FAILED");

while( 1 );/* fatal error */
}

cardType = MCI_GetCardType();

switch (cardType)
{
case MCI_SDHC_SDXC_CARD:
_DBG_("Currently the SDXC/SDHC CARD ver2.0 is being used");
break;
case MCI_SDSC_V2_CARD:
_DBG_("Currently the SD CARD ver2.0 is being used");
break;
case MCI_SDSC_V1_CARD:
_DBG_("Currently the SD CARD ver1.0 is being used");
break;

case MCI_MMC_CARD:
_DBG_("Currently the MMC CARD is being used");
break;

case MCI_CARD_UNKNOWN:
_DBG_("No CARD is being plugged, Please check!!!");
error = 1;
break;
}
if(error)
while(1);
if (MCI_GetCID(&cidval) != MCI_FUNC_OK)
{
_DBG_("Get CID Failed");

while ( 1 );/* fatal error */
}
else
{
_DBG("\t- Product Serial Number: ");_DBH32(cidval.PSN);_DBG_("");
}

/*---- Card is 'ident' state ----*/
retVal = MCI_SetCardAddress();
if(retVal != MCI_FUNC_OK)
{
_DBG("Set Card Address FAILED, retVal = "); _DBH32(retVal);
while(1);
}
else
{
rcAddress = MCI_GetCardAddress();
_DBG("Set CARD ADDRESS OK with address "); _DBH32(rcAddress);
}

_DBG_("");

retVal = MCI_GetCSD(csdVal);
if(retVal != MCI_FUNC_OK)
{
_DBG("Get CSD FAILED, retVal = "); _DBH32(retVal);
while(1);
}
else
{
_DBG_("Get Card Specific Data (CSD) Ok:");
_DBG("\t[0] = "); _DBH32(csdVal[0]);_DBG_("");
_DBG("\t[1] = "); _DBH32(csdVal[1]);_DBG_("");
_DBG("\t[2] = "); _DBH32(csdVal[2]);_DBG_("");
_DBG("\t[3] = "); _DBH32(csdVal[3]);_DBG_("");
}

retVal = MCI_Cmd_SelectCard();

if(retVal != MCI_FUNC_OK)
{
_DBG("Card Selection FAILED, retVal = "); _DBH32(retVal);
while(1);
}
else
{
_DBG("Card has been selected successfully!!!\n\r");
}

MCI_Set_MCIClock( MCI_NORMAL_RATE );

if(cardType == MCI_SDSC_V1_CARD||
cardType == MCI_SDSC_V2_CARD||
cardType == MCI_SDHC_SDXC_CARD)
{
        retVal = MCI_SetBusWidth( SD_4_BIT );
if (retVal != MCI_FUNC_OK )
{
_DBG("Set BandWidth FAILED, retVal = "); _DBH32(retVal);
while (1);/* fatal error */
}
else
{
_DBG("SET Bandwidth!!!\n\r");
}
}

retVal = MCI_SetBlockLen(BLOCK_LENGTH);
if(retVal != MCI_FUNC_OK)
{
_DBG("Set Block Length FAILED, retVal = "); _DBH32(retVal);
while(1);
}
else
{
_DBG("Block Length is SET successfully!!!\n\r");
}

retVal = MCI_WriteBlock(wrBuf, 0, WRITE_BLOCK_NUM);
if(retVal != MCI_FUNC_OK)
{
_DBG("Write Block FAILED, retVal = "); _DBH32(retVal);
while(1);
}
else
{
//while(MCI_GetBlockXferEndState() != 0);
while(MCI_GetDataXferEndState() != 0);
errorState = MCI_GetXferErrState();
#if (WRITE_BLOCK_NUM == 1)        
if(errorState)
#endif
{
retVal = MCI_Cmd_StopTransmission();
if(retVal != MCI_FUNC_OK)
{
    _DBG("Stop transmission FAILED, retVal = "); _DBH32(retVal);
    while(1);
}
}

        if(errorState)
        {
            _DBG("Write ");_DBD(WRITE_BLOCK_NUM);_DBG(" Block(s) FAILED (");_DBH32(errorState);_DBG_(")");
            while(1);
        }
        else
        {
            _DBG("Write ");_DBD(WRITE_BLOCK_NUM);_DBG(" Block(s) successfully!!!\n\r");
        }
}

retVal = MCI_ReadBlock(rdBuf, 0, WRITE_BLOCK_NUM);
if(retVal != MCI_FUNC_OK)
{
_DBG("Read Block FAILED, retVal = "); _DBH32(retVal);
while(1);
}
else
{
//while(MCI_GetBlockXferEndState() != 0);
while(MCI_GetDataXferEndState() != 0);
errorState = MCI_GetXferErrState();
#if (WRITE_BLOCK_NUM == 1)        
if(errorState)
#endif        
{
retVal = MCI_Cmd_StopTransmission();
if(retVal != MCI_FUNC_OK)
{
    _DBG("Stop transmission FAILED, retVal = "); _DBH32(retVal);
    while(1);
}
}

        if(errorState)
        {
            _DBG("Read ");_DBD(WRITE_BLOCK_NUM);_DBG(" Block(s) FAILED (");_DBH32(errorState);_DBG_(")");
            while(1);
        }
        else
        {
            _DBG("Read ");_DBD(WRITE_BLOCK_NUM);_DBG(" Block(s) successfully!!!\n\r");
        }
}

retVal = MCI_FUNC_OK;

for (j = 0; j < WRITE_LENGTH; j++)
{
if(rdBuf[j] != wrBuf[j])
{
_DBG("ERROR on Read and Write at position: "); _DBH32(j);
retVal = MCI_FUNC_FAILED;
while(1);
}
}

if(retVal == MCI_FUNC_OK)
{
_DBG("CHECKING is done! Read and Write correct!!!\n\r");
}

_DBG("\n\r>>> EXAMPLES is ENDED ");

while(1);

}
int main(void)
{
   c_entry();
   return 0;
}


Thanks very much.
Labels (1)
0 Kudos
Reply
1 Reply

563 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by xianghuiwang on Fri Jan 09 15:59:49 MST 2015
you can compare operation and settings with sample projects:
periph_admmc
app_sdmmc_meas

from below sample project package: http://www.lpcware.com/content/nxpfile/lpcopen-software-development-platform-lpc17xx-packages

regards,
0 Kudos
Reply