This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

LPC2368 SD read problem

i'm using the example program for LPC236X for testing the SD card by writing to it and verifying i'm reading back the same value.
the writing goes fluently without any problems.
the reading is stacked.
i realized that i don't get any data from the SD in the read process and the processor is waiting in the:

while ( !(MCI_STATUS & MCI_RX_DATA_AVAIL) );

i'm using an old 16MB SD card.
even when i'm trying to read from the card the SD_Status by using ACMD13 the card doesn't send any data.

when i insert the card to my digital camera i get the message "unable to use the card", but when i connect the camera to my laptop i can read and write to the card as it is detected by the laptop as removable storage.
any idea regarding the possible problem i have?

Parents
  • Hi again, pls find below the write fifo function where i don't get errors.
    look inside for the part of MCI_TX_Active. this part of the program goes without any problems.
    BTW, in the part of MCI_RX_Active, in the point where the program stuck in the value of blocksize in the LCD is 4, which indicates that there is available data in the fifo and yet the condition of RX_DATD_AVAIL is not set.

    /******************************************************************************
            /* Tx active, and Rx active  */
            if ( MCI_STATUS & MCI_TX_ACTIVE )
            {
                    DataTxActiveCount++;
    #if MCI_DMA_ENABLED
                    while ( !(GPDMA_RAW_INT_TCSTAT & 0x01) );
                    GPDMA_INT_TCCLR |= 0x01;
    #else
                    while ( TXBlockCounter < BLOCK_LENGTH )
                    {
                            blockSize = 0;
                            if ( MCI_STATUS & MCI_TX_FIFO_EMPTY )
                            {
                                    blockSize = FIFO_SIZE * 4;
                            }
                            else if ( MCI_STATUS & MCI_TX_HALF_EMPTY )
                            {
                                    blockSize = (FIFO_SIZE/2) * 4;
                            }
                            else if ( !(MCI_STATUS & MCI_TX_FIFO_FULL) )
                            {
                                    blockSize = 1 * 4;
                            }
    
                            for ( i = 0; i < blockSize; i += 4 )
                            {
                                    DataWord = (unsigned long)(WriteBlock[TXBlockCounter]) | (unsigned long)(WriteBlock[TXBlockCounter+1] << 8)
                                            | (unsigned long)(WriteBlock[TXBlockCounter+2] << 16) | (unsigned long)(WriteBlock[TXBlockCounter+3] << 24);
                                    MCI_FIFO = DataWord;
                                    TXBlockCounter += 4;
                            }
                    }
    #endif
                    /* Data has been written, but has not been programmed into the card yet. */
                    /* Even it's a dead while loop inside the ISR, but, during the
                    flash writing, there is not much else you should do. If it's not in the
                    TRAN state, per MMC/SD state diagram, send STOP to bail out. */
                    if ( MCI_CheckStatus() != TRUE )
                    {
                            MCI_Send_Stop();
                    }
                    MCI_DATA_CTRL = 0;
            }
    
            if ( MCI_STATUS & MCI_RX_ACTIVE )
            {
                    DataRxActiveCount++;
    #if MCI_DMA_ENABLED
                    while ( !(GPDMA_RAW_INT_TCSTAT & 0x02) );
                    GPDMA_INT_TCCLR |= 0x02;
    #else
                    while ( RXBlockCounter < BLOCK_LENGTH )
                    {
    //                      if ( !(MCI_STATUS & MCI_RX_FIFO_FULL) )
                            if ( MCI_STATUS & MCI_RX_FIFO_FULL)
                            {
                                    blockSize = FIFO_SIZE * 4;
                            }
                            else if ( MCI_STATUS & MCI_RX_HALF_FULL )
                            {
                                    blockSize = (FIFO_SIZE/2) * 4;
                            }
    //                      else if ( MCI_STATUS & MCI_RX_FIFO_EMPTY )
                            else if (!( MCI_STATUS & MCI_RX_FIFO_EMPTY ))
                            {
                                    blockSize = 1 * 4;
                            }
                            else
                            {
                                    blockSize = 0;
                            }
    
                            for ( i = 0; i < blockSize; i += 4 )
                            {
                            sprintf (lcd_buf,"blockSize = %3u ",blockSize);
                            goto_cursor(1,0);
                            lcd_print(lcd_buf);
                                    while ( !(MCI_STATUS & MCI_RX_DATA_AVAIL) );
    //                              while ( !(MCI_STATUS & MCI_RX_HALF_FULL) );
                            sprintf (lcd_buf,"Got here2 RX_Active");
                            goto_cursor(1,0);
                            lcd_print(lcd_buf);
                                    DataWord = MCI_FIFO;
                                    ReadBlock[RXBlockCounter] = DataWord & 0xFF;
                                    ReadBlock[RXBlockCounter+1] = (DataWord >> 8) & 0xFF;
                                    ReadBlock[RXBlockCounter+2] = (DataWord >> 16) & 0xFF;
                                    ReadBlock[RXBlockCounter+3] = (DataWord >> 24) & 0xFF;
                                    RXBlockCounter += 4;
                            }
                    }
    #endif
                    if ( MCI_CheckStatus() != TRUE )
                    {
                            MCI_Send_Stop();
                            sprintf (lcd_buf,"CMD13,status check");
                            goto_cursor(0,0);
                            lcd_print(lcd_buf);
                            sprintf (lcd_buf,"Failed RX_Active");
                            goto_cursor(1,0);
                            lcd_print(lcd_buf);
                            delay (10000000);
                    }
                    else
                    {
                            sprintf (lcd_buf,"CMD13 OK Status Check");
                            goto_cursor(0,0);
                            lcd_print(lcd_buf);
                            sprintf (lcd_buf,"Pass RX_Active");
                            goto_cursor(1,0);
                            lcd_print(lcd_buf);
                            delay (10000000);
                    }
    
                    MCI_DATA_CTRL = 0;
            }
            VICIntEnable |= MCI_Int;                                /*enable MCI interrupts */
            return;
    }
    

Reply
  • Hi again, pls find below the write fifo function where i don't get errors.
    look inside for the part of MCI_TX_Active. this part of the program goes without any problems.
    BTW, in the part of MCI_RX_Active, in the point where the program stuck in the value of blocksize in the LCD is 4, which indicates that there is available data in the fifo and yet the condition of RX_DATD_AVAIL is not set.

    /******************************************************************************
            /* Tx active, and Rx active  */
            if ( MCI_STATUS & MCI_TX_ACTIVE )
            {
                    DataTxActiveCount++;
    #if MCI_DMA_ENABLED
                    while ( !(GPDMA_RAW_INT_TCSTAT & 0x01) );
                    GPDMA_INT_TCCLR |= 0x01;
    #else
                    while ( TXBlockCounter < BLOCK_LENGTH )
                    {
                            blockSize = 0;
                            if ( MCI_STATUS & MCI_TX_FIFO_EMPTY )
                            {
                                    blockSize = FIFO_SIZE * 4;
                            }
                            else if ( MCI_STATUS & MCI_TX_HALF_EMPTY )
                            {
                                    blockSize = (FIFO_SIZE/2) * 4;
                            }
                            else if ( !(MCI_STATUS & MCI_TX_FIFO_FULL) )
                            {
                                    blockSize = 1 * 4;
                            }
    
                            for ( i = 0; i < blockSize; i += 4 )
                            {
                                    DataWord = (unsigned long)(WriteBlock[TXBlockCounter]) | (unsigned long)(WriteBlock[TXBlockCounter+1] << 8)
                                            | (unsigned long)(WriteBlock[TXBlockCounter+2] << 16) | (unsigned long)(WriteBlock[TXBlockCounter+3] << 24);
                                    MCI_FIFO = DataWord;
                                    TXBlockCounter += 4;
                            }
                    }
    #endif
                    /* Data has been written, but has not been programmed into the card yet. */
                    /* Even it's a dead while loop inside the ISR, but, during the
                    flash writing, there is not much else you should do. If it's not in the
                    TRAN state, per MMC/SD state diagram, send STOP to bail out. */
                    if ( MCI_CheckStatus() != TRUE )
                    {
                            MCI_Send_Stop();
                    }
                    MCI_DATA_CTRL = 0;
            }
    
            if ( MCI_STATUS & MCI_RX_ACTIVE )
            {
                    DataRxActiveCount++;
    #if MCI_DMA_ENABLED
                    while ( !(GPDMA_RAW_INT_TCSTAT & 0x02) );
                    GPDMA_INT_TCCLR |= 0x02;
    #else
                    while ( RXBlockCounter < BLOCK_LENGTH )
                    {
    //                      if ( !(MCI_STATUS & MCI_RX_FIFO_FULL) )
                            if ( MCI_STATUS & MCI_RX_FIFO_FULL)
                            {
                                    blockSize = FIFO_SIZE * 4;
                            }
                            else if ( MCI_STATUS & MCI_RX_HALF_FULL )
                            {
                                    blockSize = (FIFO_SIZE/2) * 4;
                            }
    //                      else if ( MCI_STATUS & MCI_RX_FIFO_EMPTY )
                            else if (!( MCI_STATUS & MCI_RX_FIFO_EMPTY ))
                            {
                                    blockSize = 1 * 4;
                            }
                            else
                            {
                                    blockSize = 0;
                            }
    
                            for ( i = 0; i < blockSize; i += 4 )
                            {
                            sprintf (lcd_buf,"blockSize = %3u ",blockSize);
                            goto_cursor(1,0);
                            lcd_print(lcd_buf);
                                    while ( !(MCI_STATUS & MCI_RX_DATA_AVAIL) );
    //                              while ( !(MCI_STATUS & MCI_RX_HALF_FULL) );
                            sprintf (lcd_buf,"Got here2 RX_Active");
                            goto_cursor(1,0);
                            lcd_print(lcd_buf);
                                    DataWord = MCI_FIFO;
                                    ReadBlock[RXBlockCounter] = DataWord & 0xFF;
                                    ReadBlock[RXBlockCounter+1] = (DataWord >> 8) & 0xFF;
                                    ReadBlock[RXBlockCounter+2] = (DataWord >> 16) & 0xFF;
                                    ReadBlock[RXBlockCounter+3] = (DataWord >> 24) & 0xFF;
                                    RXBlockCounter += 4;
                            }
                    }
    #endif
                    if ( MCI_CheckStatus() != TRUE )
                    {
                            MCI_Send_Stop();
                            sprintf (lcd_buf,"CMD13,status check");
                            goto_cursor(0,0);
                            lcd_print(lcd_buf);
                            sprintf (lcd_buf,"Failed RX_Active");
                            goto_cursor(1,0);
                            lcd_print(lcd_buf);
                            delay (10000000);
                    }
                    else
                    {
                            sprintf (lcd_buf,"CMD13 OK Status Check");
                            goto_cursor(0,0);
                            lcd_print(lcd_buf);
                            sprintf (lcd_buf,"Pass RX_Active");
                            goto_cursor(1,0);
                            lcd_print(lcd_buf);
                            delay (10000000);
                    }
    
                    MCI_DATA_CTRL = 0;
            }
            VICIntEnable |= MCI_Int;                                /*enable MCI interrupts */
            return;
    }
    

Children