AnsweredAssumed Answered

Talk to an SD card via SPI?

Question asked by Ronan O'Driscoll on Apr 12, 2018
Latest reply on May 23, 2018 by Ronan O'Driscoll

I am trying to communicate with an SD card using an LPC5411 dev board based on developing my own SD card custom driver. I m basing the development on the following tutorial Porting FatFs file system to KL26 SPI SD card code  . I have the SD card connected externally to the development board. I m having a problem initialising the SD card. I have made sure of the following. I send 80 pulses of a clock signal with Chip Select high and MOSI high. After this i m setting the CS low and sending the byte values 0x40, 0x00, 0x00, 0x00, 0x00, 0x95 for CMD0. I m not receiving any byte values back on the MISO line. I was checking the scope and it appears that the CS, MOSI and CLK are working but the MISO isnt. Is there a timing issue. I have attached the screen grab of the the SPI lines. 

 

 

The code I m using the generate these pulses is as follows

 

uint8_t MMCInit(){
spi_master_config_t userConfig = {0};
spi_master_config_t masterConfig = {0};

uint8_t i = 0,k = 0,tmp = 0;
uint16_t cnt=0;
uint8_t buff[512];

SPI_MasterGetDefaultConfig(&userConfig);
srcFreq = EXAMPLE_SPI_MASTER_CLK_FREQ_LOW;//EXAMPLE_SPI_MASTER_CLK_FREQ;
masterConfig.sselNum = (spi_ssel_t)EXAMPLE_SPI_SSEL;
SPI_MasterInit(EXAMPLE_SPI_MASTER, &userConfig, srcFreq);

spi_transfer_t xfer = {0};
status_t xferStatus = kStatus_Success;

uint8_t ucTemp;
for (i = 0U; i < BUFFER_SIZE; i++)
{
srcBuff[i] = 0xFF;
}

xfer.txData = srcBuff;
xfer.rxData = destBuff;
xfer.dataSize = sizeof(destBuff);

// SPI_CS_Low();
xferStatus = SPI_MasterTransferBlocking(EXAMPLE_SPI_MASTER, &xfer);


//40 00 00 00 00 95 for CMD0
//48 00 00 01 AA 0F for CMD8
//7A 00 00 00 00 75

startCMD[0] = 0x40;
startCMD[1] = 0x00;
startCMD[2] = 0x00;
startCMD[3] = 0x00;
startCMD[4] = 0x00;
startCMD[5] = 0x95;
// xfer.configFlags = kSPI_FrameAssert;

xfer.txData = startCMD;
xfer.rxData = endBuff;
xfer.dataSize = 7;//sizeof(endBuff); 6 bytes and one more
SPI_CS_Low();
xferStatus = SPI_MasterTransferBlocking(EXAMPLE_SPI_MASTER, &xfer);
SPI_CS_High();

}

 

 

uint8_t MMCInit(){ spi_master_config_t userConfig = {0}; spi_master_config_t masterConfig = {0}; uint8_t i = 0,k = 0,tmp = 0; uint16_t cnt=0; uint8_t buff[512]; SPI_MasterGetDefaultConfig(&userConfig); srcFreq = EXAMPLE_SPI_MASTER_CLK_FREQ_LOW;//EXAMPLE_SPI_MASTER_CLK_FREQ; masterConfig.sselNum = (spi_ssel_t)EXAMPLE_SPI_SSEL; SPI_MasterInit(EXAMPLE_SPI_MASTER, &userConfig, srcFreq); spi_transfer_t xfer = {0}; status_t xferStatus = kStatus_Success; uint8_t ucTemp; for (i = 0U; i < BUFFER_SIZE; i++) { srcBuff[i] = 0xFF; } xfer.txData = srcBuff; xfer.rxData = destBuff; xfer.dataSize = sizeof(destBuff); // SPI_CS_Low(); xferStatus = SPI_MasterTransferBlocking(EXAMPLE_SPI_MASTER, &xfer); //40 00 00 00 00 95 for CMD0 //48 00 00 01 AA 0F for CMD8 //7A 00 00 00 00 75 startCMD[0] = 0x40; startCMD[1] = 0x00; startCMD[2] = 0x00; startCMD[3] = 0x00; startCMD[4] = 0x00; startCMD[5] = 0x95; // xfer.configFlags = kSPI_FrameAssert; xfer.txData = startCMD; xfer.rxData = endBuff; xfer.dataSize = 7;//sizeof(endBuff); 6 bytes and one more SPI_CS_Low(); xferStatus = SPI_MasterTransferBlocking(EXAMPLE_SPI_MASTER, &xfer); SPI_CS_High(); }

Outcomes