This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

MSP430 SD Card High Speed Communication

Other Parts Discussed in Thread: MSP430F2618

Hello all!

I am currently working at a logger. I am using MSP430F2618 MCU to communicate with a SDHC and everything is fine at low speed. If I raise the speed, all commands return 0x01.

Here are some code snippets:

Clock initialization:

 BCSCTL1 &= ~XT2OFF; // Activate XT2 high freq xtal
BCSCTL3 |= XT2S_2; // 3 - 16MHz crystal or resonator
 BCSCTL1 = CALBC1_16MHZ;
DCOCTL = CALDCO_16MHZ;
// Wait for xtal to stabilize
do
{
IFG1 &= ~OFIFG; // Clear OSCFault flag
for (idx = 0xFF; idx > 0; idx--); // Time for flag to set
}while ((IFG1 & OFIFG)); // OSCFault flag still set?

BCSCTL2 |= SELM_2 | SELS; // MCLK = XT2 HF XTAL (safe), SMCLK = XT2

Then I initialize SPI communication. I set first the USCIB_0 registers:

 UCB0CTL1 |= UCSWRST;
UCB0CTL0 |= UCMST+UCSYNC+UCCKPL+UCMSB; //3-pin, 8-bit SPI master
UCB0CTL1 |= UCSSEL_2; // SMCLK
UCB0BR0 = 0x28;                // /40 => around 400Khz with 16Mhz oscillator
UCB0BR1 = 0; //
UCB0CTL1 &= ~UCSWRST; // **Initialize USCI state machine**
P3SEL |= 0x0E; // P3.3,2,1 option select
P3DIR |= 0x0B;

I am following the steps described in SD Card specifications to initialize the card. Everything goes well and then I am trying to raise the speed by setting UCB0BR0:

 UCB0BR0 = 0x02;             // Divide SMCLK with 2

Next step is to read first sector of the card. But here comes the problem. The response of CMD17 is 0x01.

BUT if I don't change UCB0BR0 value, everything goes well and I am successfully reading/writing on SD card.

Can anyoane help me? 

Thanks!

  • It should work. I had it working with the 1611 on 4MHz without problems. And with 16MHz (!) on a 5438 (but not thoroughly tested).

    Maybe you have too much parasitic capacitance on teh wiring, or the supply voltage is too low for the high speed.

    Try a few intermediate steps. Does it work with 1MHz? 2?

    How do you change UCB0BR0? ou need to set UCSWRST before and clear it after the change.

  • Thanks for your reply Jens!

    So... after the initialization is done, I just set UCB0BR0.

    I have tried to raise the speed as you said. Everything goes well until 4Mhz. The response for commands is 0x0.

    But after 4Mhz I have to send the commands into a loop in order to get 0x0 response. It usually get the response after 10-15 times.

    Plus... at 16Mhz, when I try to read a block, after 20-30 times of sending CMD17 I get the response 0x0, but the actual data is wrong. I receive only 0xFF.

    Something is very, very strange. Do you have any idea? :-s

  • Ionut Ungureanu said:
    So... after the initialization is done, I just set UCB0BR0.

    To change UCB0BR0, you must first set UCSWRST, then change UCB0BR0, then clear UCSWRST. THi swill also clear any IE bits, clear the RXIFG bit and set the TXIFG bit.

    If oyu just change UCBR0, the already running internal state machine may or may not update properly. Perhaps on frequencies <4MHz (or on BR0>4) this i snot a problem, but maybe the device needs to init differently if BR <4. And by omitting the SWRST, this different init isn't done and transfers don't happen properly.

  • Thanks for the suggestion Jens! I will try this and come back with an answer.

**Attention** This is a public forum