I've been working on some code to talk to an SD card with the MSP430. I can't get the card to enter into idle mode, and I'm actually pretty stumped as to why. I've looked at the microcontroller output with a logic analyzer and everything looks as it should. I've tried a few different cards and SD card adapters with the same results so it seems like a code issue. I'm initializing the SD card with this code:
void MMC_initSPI(void){
//SOMI: 3.1
//SIMO: 3.0
//CLK: 3.2
//CS: 1.4
//chip select
SD_CSn_PxDIR|=SD_CSn_PIN;
SD_CSn_PxOUT|=SD_CSn_PIN;
UCB0CTL1 = UCSSEL_2 | UCSWRST; // source USCI clock from SMCLK, put USCI in reset mode
UCB0CTL0 |= SPI_MODE_0; // SPI MODE 0 - CPOL=0 CPHA=0
// note: UCCKPH is inverted from CPHA
//do I need to do this??
UCB0BR0 = LOBYTE(SPI_400kHz); // set initial speed
UCB0BR1 = HIBYTE(SPI_400kHz);
P3SEL |= BIT0 + BIT1 + BIT2; // configure for USCI
UCB0CTL1 &= ~UCSWRST; // release for operation
}
and then sending 0xFF
within a for loop 11 times (well within the 71 clock pulses needed to awaken the card to new data) before using the mmc_GoIdle()
function, which is as follows:
char mmc_GoIdle(){
char response=0x01;
CS_LOW();
//Send Command 0 to put MMC in SPI mode
mmcSendCmd(MMC_GO_IDLE_STATE, 0, 0x95);
//Now wait for READY RESPONSE
if(mmcGetResponse()!=0x01)
return MMC_INIT_ERROR;
while(response==0x01)
{
CS_HIGH();
spiSendByte(0xff);
CS_LOW();
mmcSendCmd(MMC_SEND_OP_COND,0x00,0xff);
response=mmcGetResponse();
}
CS_HIGH();
spiSendByte(0xff);
return (MMC_SUCCESS);
}
but it always returns
MMC_INIT_ERROR
. Can anyone spot anything obviously wrong? The logic analyzer tells me it's returning 0x00
and not 0x01
as it should. Any ideas?
Best Answer
Try with SPI_MODE_1 it will work.